diff --git a/lib/format.js b/lib/format.js index a3958fd..badf53b 100644 --- a/lib/format.js +++ b/lib/format.js @@ -1,24 +1,8 @@ module.exports = { formatArray, - formatDate, formatText }; - -function formatDate(date) { - return [ - date.getFullYear(), - pad(date.getMonth() + 1), - pad(date.getDate()), - 'T', - pad(date.getHours()), - pad(date.getMinutes()), - pad(date.getSeconds()), - ].join(''); - - function pad(n) { return n.toString().padStart(2, 0); } -} - function formatArray(arr) { return arr.join(';'); } diff --git a/lib/ical.js b/lib/ical.js index b4600fe..3a06285 100644 --- a/lib/ical.js +++ b/lib/ical.js @@ -1,5 +1,5 @@ const { v5: uuid } = require('uuid'); -const { formatDate, formatArray } = require("./format"); +const { formatArray } = require("./format"); const property = require("./property"); exports = module.exports = ical; @@ -15,14 +15,13 @@ function id2uuid(id, day) { return uuid(id, NAMESPACE) + '@furkot.com'; } -const offset = new Date().getTimezoneOffset() * 60 * 1000; - function ts2date(ts) { - return formatDate(new Date(ts + offset)); + // remove dashes and colons and strip milliseconds + return new Date(ts).toISOString().replace(/[-:]/g, '').slice(0, -5); } function* ical({ metadata, routes }) { - const dtstamp = formatDate(new Date()); + const dtstamp = ts2date(Date.now()); yield* property('BEGIN', 'VCALENDAR'); yield* property('VERSION', '2.0');