From 815a507bd454b5f99345276d723e58af1e418ef3 Mon Sep 17 00:00:00 2001 From: Tim Shaker Date: Sat, 2 Apr 2022 17:16:15 -0700 Subject: [PATCH 1/4] apply timezone offset to test dtstart UTC times --- test/optionstostring.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/optionstostring.test.ts b/test/optionstostring.test.ts index 4eb5e94e..c98b5bc8 100644 --- a/test/optionstostring.test.ts +++ b/test/optionstostring.test.ts @@ -7,14 +7,14 @@ describe('optionsToString', () => { it('serializes valid single lines of rrules', function () { const expectations: ([ Partial, string ][]) = [ [{ freq: RRule.WEEKLY, until: new Date(Date.UTC(2010, 0, 1, 0, 0, 0)) }, 'RRULE:FREQ=WEEKLY;UNTIL=20100101T000000Z' ], - [{ dtstart: new Date(Date.UTC(1997, 8, 2, 9, 0, 0)), tzid: 'America/New_York' }, 'DTSTART;TZID=America/New_York:19970902T090000' ], + [{ dtstart: new Date(Date.UTC(1997, 8, 2, 13, 0, 0)), tzid: 'America/New_York' }, 'DTSTART;TZID=America/New_York:19970902T090000' ], [ { dtstart: new Date(Date.UTC(1997, 8, 2, 9, 0, 0)), freq: RRule.WEEKLY }, 'DTSTART:19970902T090000Z\n' + 'RRULE:FREQ=WEEKLY' ], [ - { dtstart: new Date(Date.UTC(1997, 8, 2, 9, 0, 0)), tzid: 'America/New_York', freq: RRule.WEEKLY }, + { dtstart: new Date(Date.UTC(1997, 8, 2, 13, 0, 0)), tzid: 'America/New_York', freq: RRule.WEEKLY }, 'DTSTART;TZID=America/New_York:19970902T090000\n' + 'RRULE:FREQ=WEEKLY' ] From ee7d2693c1cc731619ef1498b0f8ea5bad848b26 Mon Sep 17 00:00:00 2001 From: Tim Shaker Date: Sun, 5 Jun 2022 10:36:49 -0700 Subject: [PATCH 2/4] update gitignore --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0e9e8106..3e2bb632 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ bower_components/ *.log coverage .nyc_output -dist/ \ No newline at end of file +dist/ + +.DS_Store \ No newline at end of file From d8e3e1d4b95019283d4b9717b68edf184844fb9d Mon Sep 17 00:00:00 2001 From: Tim Shaker Date: Sun, 5 Jun 2022 10:37:11 -0700 Subject: [PATCH 3/4] add dayjs --- package.json | 1 + src/lib/dayjs.ts | 5 +++++ yarn.lock | 5 +++++ 3 files changed, 11 insertions(+) create mode 100644 src/lib/dayjs.ts diff --git a/package.json b/package.json index d15cc660..a8d1705d 100644 --- a/package.json +++ b/package.json @@ -85,6 +85,7 @@ }, "peerDependencies": {}, "dependencies": { + "dayjs": "^1.11.0", "tslib": "^1.10.0" } } diff --git a/src/lib/dayjs.ts b/src/lib/dayjs.ts new file mode 100644 index 00000000..fffa5ebf --- /dev/null +++ b/src/lib/dayjs.ts @@ -0,0 +1,5 @@ +export const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') +const timezone = require('dayjs/plugin/timezone') // dependent on utc plugin +dayjs.extend(utc) +dayjs.extend(timezone) diff --git a/yarn.lock b/yarn.lock index b510ef7a..216f4c37 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1091,6 +1091,11 @@ cyclist@^1.0.1: resolved "https://registry.yarnpkg.com/cyclist/-/cyclist-1.0.1.tgz#596e9698fd0c80e12038c2b82d6eb1b35b6224d9" integrity sha1-WW6WmP0MgOEgOMK4LW6xs1tiJNk= +dayjs@^1.11.0: + version "1.11.0" + resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.0.tgz#009bf7ef2e2ea2d5db2e6583d2d39a4b5061e805" + integrity sha512-JLC809s6Y948/FuCZPm5IX8rRhQwOiyMb2TfVVQEixG7P8Lm/gt5S7yoQZmC8x1UehI9Pb7sksEt4xx14m+7Ug== + debug@3.2.6: version "3.2.6" resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b" From a8684fe8588a026559c5eea64044d5ce3926f1c9 Mon Sep 17 00:00:00 2001 From: Tim Shaker Date: Sun, 5 Jun 2022 10:37:30 -0700 Subject: [PATCH 4/4] use dayjs --- src/datewithzone.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/datewithzone.ts b/src/datewithzone.ts index 8ae3ed09..3b757fc9 100644 --- a/src/datewithzone.ts +++ b/src/datewithzone.ts @@ -1,5 +1,5 @@ -import dateutil from './dateutil' import { DateTime } from 'luxon' +import { dayjs } from './lib/dayjs' export class DateWithZone { public date: Date @@ -15,12 +15,11 @@ export class DateWithZone { } public toString () { - const datestr = dateutil.timeToUntilString(this.date.getTime(), this.isUTC) if (!this.isUTC) { - return `;TZID=${this.tzid}:${datestr}` + return `;TZID=${this.tzid}:${dayjs.tz(this.date, this.tzid).format('YYYYMMDDTHHmmss')}` } - return `:${datestr}` + return `:${dayjs(this.date).utc().format('YYYYMMDDTHHmmss')}Z` } public getTime () {