{"id":21820325,"url":"https://github.com/trademe/add2calendar","last_synced_at":"2026-05-21T07:06:15.412Z","repository":{"id":148327993,"uuid":"96731580","full_name":"TradeMe/add2Calendar","owner":"TradeMe","description":"A small lib to provide integration with online and desktop calendars","archived":false,"fork":false,"pushed_at":"2017-08-08T02:21:08.000Z","size":109,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-26T07:24:08.854Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TradeMe.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-10T03:19:53.000Z","updated_at":"2019-04-29T13:56:08.000Z","dependencies_parsed_at":"2023-05-19T19:45:19.579Z","dependency_job_id":null,"html_url":"https://github.com/TradeMe/add2Calendar","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TradeMe%2Fadd2Calendar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TradeMe%2Fadd2Calendar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TradeMe%2Fadd2Calendar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TradeMe%2Fadd2Calendar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TradeMe","download_url":"https://codeload.github.com/TradeMe/add2Calendar/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244782632,"owners_count":20509856,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-27T16:31:28.268Z","updated_at":"2026-05-21T07:06:10.393Z","avatar_url":"https://github.com/TradeMe.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Add2Calendar\n\nA simple JS library that enables you to \"add to calendar\" your upcoming events.\n\n## Inspiration\n\nThis project was inspired by [OuiCal](https://github.com/carlsednaoui/add-to-calendar-buttons) add to calendar library.\n\n## How to use it?\n\nCall ```Add2CalendarService.getHrefFor``` with your event info, and it returns the url for it.\n\nThe only fields that are mandatory are:\n\n  - Event title\n  - Start time\n  - Event duration, in minutes\n\n## Example\n```javascript\n    var url = Add2CalendarService.getHrefFor(\n    \tCalendarTypeEnum.google, \n        {\n\t\t\t// Event title\n          \ttitle: 'Get on the front page of HN',\n\n            // Event start date\n            start: new Date('June 15, 2013 19:00'),\n\n            // Event duration (IN MINUTES)\n            duration: 120,\n\n            // You can also choose to set an end time\n            // If an end time is set, this will take precedence over duration\n            end: new Date('June 15, 2013 23:00'),     \n\n            // Event Address\n            address: 'The internet',\n\n            // Event Description\n            description: 'Get on the front page of HN, then prepare for world domination.'      \n    \t});\n        \n   \tdocument.querySelector('#some-link').appendChild(myCalendar).href = url;\n```\n\n\n## You can deploy it in three different flavours\n\n*  CommonJS, suitable for Node and Browserify/Webpack\n \t* ```npm run build```\n* A self-executing function, suitable for inclusion as a \\\u003cscript\u003e tag. (If you want to create a bundle for your application, you probably want to use this, because it leads to smaller file sizes.)\n\t* ```npm run build:iife```\n* Universal Module Definition, works as amd, cjs and iife all in one\n\t*  ```npm run build:umd```\n\n## Want to try it out on your console?\n\nCopy this on your console:\n\n\n``` javascript\nvar add2Calendar=function(t){\"use strict\";function e(t,e){function n(){this.constructor=t}for(var o in e)e.hasOwnProperty(o)\u0026\u0026(t[o]=e[o]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var n=/-|:|\\.\\d+/g,o=function(){function t(t){this.event=t,this.startTime=this.formatTime(t.start),this.endTime=this.calculateEndTime(t)}return Object.defineProperty(t.prototype,\"href\",{get:function(){},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,\"uid\",{get:function(){return(this.s4()+this.s4()+\"-\"+this.s4()+\"-4\"+this.s4().substr(0,3)+\"-\"+this.s4()+\"-\"+this.s4()+this.s4()+this.s4()).toLowerCase()},enumerable:!0,configurable:!0}),t.prototype.formatTime=function(t){return t.toISOString().replace(n,\"\")},t.prototype.calculateEndTime=function(t){if(t.end)return this.formatTime(t.end);if(!t.duration)throw new Error(\"You have to provide either the duration or end\");return this.formatTime(new Date(t.start.getTime()+6e4*t.duration))},t.prototype.s4=function(){return(65536*(1+Math.random())|0).toString(16).substring(1)},t}(),r=function(t){function n(e){t.call(this,e),this.event=e}return e(n,t),Object.defineProperty(n.prototype,\"href\",{get:function(){return encodeURI(\"https://www.google.com/calendar/render?action=TEMPLATE\u0026dates=\"+(this.startTime||\"\")+\"/\"+(this.endTime||\"\")+\"\u0026location=\"+(this.event.address||\"\")+\"\u0026sprop=\"+(this.event.url||\"\"))+\"\u0026text=\"+encodeURIComponent(this.event.title||\"\")+\"\u0026details=\"+encodeURIComponent(this.event.description||\"\")},enumerable:!0,configurable:!0}),n}(o),i=function(t){function n(e){t.call(this,e),this.event=e}return e(n,t),Object.defineProperty(n.prototype,\"href\",{get:function(){return encodeURI(\"data:text/calendar;charset=utf8,\"+[\"BEGIN:VCALENDAR\",\"PRODID:-//Destination Search//ical4j 1.0//EN\",\"VERSION:2.0\",\"CALSCALE:GREGORIAN\",\"X-MS-OLK-FORCEINSPECTOROPEN:true\",\"METHOD:PUBLISH\",\"BEGIN:VEVENT\",\"URL:\"+(this.event.url||\"\"),\"DTSTART:\"+(this.startTime||\"\"),\"DTEND:\"+(this.endTime||\"\"),\"SUMMARY:\"+(this.event.title||\"\"),\"DESCRIPTION:\"+(this.event.description||\"\"),\"LOCATION:\"+(this.event.address||\"\"),\"SEQUENCE:0\",\"DTSTAMP:\"+this.dtStamp,\"UID:\"+this.uid,\"END:VEVENT\",\"END:VCALENDAR\"].join(\"\\n\"))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,\"dtStamp\",{get:function(){return this.formatTime(new Date)},enumerable:!0,configurable:!0}),n}(o),a=function(t){function n(e){t.call(this,e),this.event=e}return e(n,t),Object.defineProperty(n.prototype,\"href\",{get:function(){return encodeURI(\"https://outlook.live.com/owa/?rru=addevent\u0026path=%2fcalendar%2fview%2fMonth\u0026authRedirect=true\u0026realm=live.com\u0026whr=live.com\u0026CBCXT=out\u0026fl=wld\u0026startdt=\"+(this.startTime||\"\")+\"\u0026enddt=\"+(this.endTime||\"\")+\"\u0026uid=\"+this.uid)+\"\u0026subject=\"+encodeURIComponent(this.event.title||\"\")+\"\u0026body=\"+encodeURIComponent(this.event.description||\"\")},enumerable:!0,configurable:!0}),n}(o),s=function(t){function n(e){t.call(this,e),this.event=e}return e(n,t),n.prototype.getYahooEventDuration=function(){var t=this.event.end?(this.event.end.getTime()-this.event.start.getTime())/6e4:this.event.duration;return(t\u003c600?\"0\"+Math.floor(t/60):\"\"+Math.floor(t/60))+(t%60\u003c10?\"0\"+t%60:\"\"+t%60)},Object.defineProperty(n.prototype,\"href\",{get:function(){return encodeURI(\"http://calendar.yahoo.com/?v=60\u0026view=d\u0026type=20\u0026st=\"+this.startTime+\"\u0026dur=\"+(this.getYahooEventDuration()||\"\")+\"\u0026in_loc=\"+(this.event.address||\"\")+\"\u0026url=\"+(this.event.url||\"\"))+\"\u0026title=\"+encodeURIComponent(this.event.title||\"\")+\"\u0026desc=\"+encodeURIComponent(this.event.description||\"\")},enumerable:!0,configurable:!0}),n}(o),u=function(){function t(){}return t.getHrefFor=function(e,n){return new(t.getGeneratorFor(e))(n).href},t.getGeneratorFor=function(e){return t.factory[e]},t.stConstructor=void(t.factory=[r,s,i,i,a]),t}();return function(t){t[t.google=0]=\"google\",t[t.yahoo=1]=\"yahoo\",t[t.iCalendar=2]=\"iCalendar\",t[t.outlook=3]=\"outlook\",t[t.outlookLive=4]=\"outlookLive\"}(t.CalendarTypeEnum||(t.CalendarTypeEnum={})),t.Add2CalendarService=u,t}({});\n```\n\nAnd then copy:\n```javascript\nadd2Calendar.Add2CalendarService.getHrefFor(\n    \tadd2Calendar.CalendarTypeEnum.google,\n        {\n            title: 'Get on the front page of HN',\n            start: new Date('June 15, 2013 19:00'),\n            duration: 120,\n            end: new Date('June 15, 2013 23:00'),\n            address: 'The internet',\n            description: 'Get on the front page of HN, then prepare for world domination.'      \n    \t});\n```\n\n\\#winning!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrademe%2Fadd2calendar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrademe%2Fadd2calendar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrademe%2Fadd2calendar/lists"}