Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply timezone offset to test dtstart UTC times #502

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ bower_components/
*.log
coverage
.nyc_output
dist/
dist/

.DS_Store
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
},
"peerDependencies": {},
"dependencies": {
"dayjs": "^1.11.0",
"tslib": "^1.10.0"
}
}
7 changes: 3 additions & 4 deletions src/datewithzone.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dateutil from './dateutil'
import { DateTime } from 'luxon'
import { dayjs } from './lib/dayjs'

export class DateWithZone {
public date: Date
Expand All @@ -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 () {
Expand Down
5 changes: 5 additions & 0 deletions src/lib/dayjs.ts
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions test/optionstostring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ describe('optionsToString', () => {
it('serializes valid single lines of rrules', function () {
const expectations: ([ Partial<Options>, 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'
]
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==

[email protected]:
version "3.2.6"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b"
Expand Down