Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions example.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,26 @@
</head>

<body>
<div class="new-cal"></div>
<div class="new-cal2"></div>
<div class="new-cal">Example 1</div>
<div class="new-cal2">Example 2</div>
<script>
Date.prototype.addDays = function (days) {
let date = new Date(this.valueOf());
date.setDate(date.getDate() + days);
return date;
}
let rightNow = new Date();

var myCalendar = createCalendar({
options: {
class: 'my-class',
id: 'my-id' // You need to pass an ID. If you don't, one will be generated for you.
},
data: {
title: 'Get on the front page of HN', // Event title
start: new Date('June 15, 2013 19:00'), // Event start date
start: new Date('June 15, 2022 19:00'), // Event start date
duration: 120, // Event duration (IN MINUTES)
end: new Date('June 15, 2013 23:00'), // You can also choose to set an end time.
//end: new Date('June 15, 2022 23:00'), // You can also choose to set an end time.
// If an end time is set, this will take precedence over duration
address: 'The internet',
description: 'Get on the front page of HN, then prepare for world domination.'
Expand All @@ -31,8 +38,9 @@
},
data: {
title: 'Go to the gym',
start: new Date('June 15, 2013 17:00'),
duration: 60,
start: rightNow,
end: rightNow.addDays(2),
allDay: true, //Make it an 'All Day' event. A 1 day event ends on the following day. A 2-day event ends 2 days after it starts (ie. start + 2 days), etc.
address: 'Tough Boys Gym',
description: 'Work them biceps out.'
}
Expand Down
41 changes: 13 additions & 28 deletions ouical.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
;(function(exports) {
var MS_IN_MINUTES = 60 * 1000;

var formatTime = function(date) {
return date.toISOString().replace(/-|:|\.\d+/g, '');
var formatTime = function(date, allDay = false) {
return allDay ? date.toISOString().replace(/-|:|\.\d+/g, '').substr(0,8) : date.toISOString().replace(/-|:|\.\d+/g, '');
};

var calculateEndTime = function(event) {
return event.end ?
formatTime(event.end) :
formatTime(new Date(event.start.getTime() + (event.duration * MS_IN_MINUTES)));
return event.end ? event.end : new Date(event.start.getTime() + (event.duration * MS_IN_MINUTES));
};

var calendarGenerators = {
google: function(event) {
var startTime = formatTime(event.start);
var endTime = calculateEndTime(event);
var startTime = formatTime(event.start, event.allDay);
var endTime = formatTime(calculateEndTime(event), event.allDay);

var href = encodeURI([
'https://www.google.com/calendar/render',
Expand All @@ -31,30 +29,17 @@
},

yahoo: function(event) {
var eventDuration = event.end ?
((event.end.getTime() - event.start.getTime())/ MS_IN_MINUTES) :
event.duration;

// Yahoo dates are crazy, we need to convert the duration from minutes to hh:mm
var yahooHourDuration = eventDuration < 600 ?
'0' + Math.floor((eventDuration / 60)) :
Math.floor((eventDuration / 60)) + '';

var yahooMinuteDuration = eventDuration % 60 < 10 ?
'0' + eventDuration % 60 :
eventDuration % 60 + '';

var yahooEventDuration = yahooHourDuration + yahooMinuteDuration;

// Remove timezone from event time
var st = formatTime(new Date(event.start - (event.start.getTimezoneOffset() *
MS_IN_MINUTES))) || '';
// Remove timezone from event time(s)
var st = formatTime(new Date(event.start - (event.start.getTimezoneOffset() * MS_IN_MINUTES))) || '';
var et = calculateEndTime(event);
et = formatTime(new Date(et - (et.getTimezoneOffset() * MS_IN_MINUTES))) || '';

var href = encodeURI([
'http://calendar.yahoo.com/?v=60&view=d&type=20',
'&title=' + (event.title || ''),
'&st=' + st,
'&dur=' + (yahooEventDuration || ''),
'&et=' + et,
'&dur=' + ((event.allDay ? 'allday' : '') || ''),
'&desc=' + (event.description || ''),
'&in_loc=' + (event.address || '')
].join(''));
Expand All @@ -64,8 +49,8 @@
},

ics: function(event, eClass, calendarName) {
var startTime = formatTime(event.start);
var endTime = calculateEndTime(event);
var startTime = formatTime(event.start, event.allDay);
var endTime = formatTime(calculateEndTime(event), event.allDay);

var href = encodeURI(
'data:text/calendar;charset=utf8,' + [
Expand Down
Loading