Skip to content
Merged
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
29 changes: 29 additions & 0 deletions site/themes/s2b_hugo_theme/assets/js/cal/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,35 @@
}
};

$.fn.getAddToGoogleLink = function(event) {
const googleCalUrl = new URL('https://www.google.com/calendar/render');

const startDate = dayjs(`${event.date} ${event.time}`).toISOString();
const duration = event.duration ?? 60; // Google requires a duration and defaults to 60 minutes anyway
const endDate = dayjs(startDate).add(dayjs.duration({ 'minute': duration })).toISOString();
/**
* Matches anything that is not a word or whitespace
* @example
* "2025-05-21T16:30:00.000Z".replace(regex, '') // 20250521T163000000Z
*/
const regex = /[^\w\s]/gi;

// Remove colons and periods for Google Calendar URL (2025-05-21T16:30:00.000Z => 20250521T163000000Z)
const calendarDates = `${startDate.replace(regex, '')}/${endDate.replace(regex, '')}`;

googleCalUrl.search = new URLSearchParams({
action: "TEMPLATE",
text: `shift2Bikes: ${event.title}`,
location: event.address,
details: `${event.details}\n\n${event.shareable}`,
dates: calendarDates,
sf: true, // ??
output: 'xml'
});

return googleCalUrl.toString();
};

$.fn.compareTimes = function ( event1, event2 ) {
if ( event1.time < event2.time ) {
return -1;
Expand Down
28 changes: 1 addition & 27 deletions site/themes/s2b_hugo_theme/assets/js/cal/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,7 @@ $(document).ready(function() {
exportURL.searchParams.set('id', value.id);
value.exportlink = exportURL.toString();

/**
* Add To Google Calendar
*/
const googleCalUrl = new URL('https://www.google.com/calendar/render')
const startDate = dayjs(`${value.date} ${value.time}`).toISOString()
const duration = value.duration ?? 60 // Google requires a duration and defaults to 60 minutes anyway
const endDate = dayjs(startDate).add(dayjs.duration({ 'minute': duration })).toISOString()
/**
* Matches anything that is not a word or whitespace
* @example
* "2025-05-21T16:30:00.000Z".replace(regex, '') // 20250521T163000000Z
*/
const regex = /[^\w\s]/gi

// Remove colons and periods for Google Calendar URL (2025-05-21T16:30:00.000Z => 20250521T163000000Z)
const calendarDates = `${startDate.replace(regex, '')}/${endDate.replace(regex, '')}`

googleCalUrl.search = new URLSearchParams({
action: "TEMPLATE",
text: `shift2Bikes: ${value.title}`,
location: value.address,
details: `${value.details}\n\n${value.shareable}`,
dates: calendarDates,
sf: true, // ??
output: 'xml'
})
value.addToGoogleLink = googleCalUrl.toString()
value.addToGoogleLink = container.getAddToGoogleLink(value);

groupedByDate[date].events.push(value);
});
Expand Down