Skip to content

Commit

Permalink
simplify date/time formating
Browse files Browse the repository at this point in the history
  • Loading branch information
pirxpilot committed Apr 18, 2024
1 parent e5f49b4 commit ffe1c97
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
16 changes: 0 additions & 16 deletions lib/format.js
Original file line number Diff line number Diff line change
@@ -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(';');
}
Expand Down
9 changes: 4 additions & 5 deletions lib/ical.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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');
Expand Down

0 comments on commit ffe1c97

Please sign in to comment.