Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { RRule } = require('rrule');
- const rulesWithoutTz = {
- until: new Date(Date.UTC(2021, 2, 23, 23, 0, 0)),
- dtstart: new Date(Date.UTC(2019, 1, 23, 23, 0, 0)),
- byweekday: [RRule.SA, RRule.SU],
- interval: 1,
- freq: 2
- };
- const rulesWithTz = {
- until: new Date(Date.UTC(2021, 2, 24, 0, 0, 0)),
- dtstart: new Date(Date.UTC(2019, 1, 24, 0, 0, 0)),
- byweekday: [RRule.SA, RRule.SU],
- tzid: 'Europe/Paris',
- interval: 1,
- freq: 2
- };
- const rrulesWithoutTz = new RRule(rulesWithoutTz);
- const rrulesWithTz = new RRule(rulesWithTz);
- const dateRangeBeforeDST = {
- from: new Date(Date.UTC(2019, 2, 17, 23, 0, 0)),
- to: new Date(Date.UTC(2019, 2, 24, 23, 0, 0))
- };
- const dateRangeAfterDST = {
- from: new Date(Date.UTC(2019, 2, 31, 22, 0, 0)),
- to: new Date(Date.UTC(2019, 3, 7, 22, 0, 0))
- };
- console.log('rulesWithoutTz', rulesWithoutTz);
- console.log('dateBeforeDST', dateRangeBeforeDST);
- console.log('dateAfterDST', dateRangeAfterDST);
- console.log('Before DST without TZ', rrulesWithoutTz.between(dateRangeBeforeDST.from, dateRangeBeforeDST.to));
- console.log('After DST without TZ', rrulesWithoutTz.between(dateRangeAfterDST.from, dateRangeAfterDST.to));
- console.log('-----------------------------------');
- console.log('before DST with TZ', rrulesWithTz.between(dateRangeBeforeDST.from, dateRangeBeforeDST.to));
- console.log('after DST with TZ', rrulesWithTz.between(dateRangeAfterDST.from, dateRangeAfterDST.to));
- /*
- output :
- rulesWithoutTz { until: 2021-03-23T23:00:00.000Z,
- dtstart: 2019-02-23T23:00:00.000Z,
- byweekday:
- [ Weekday { weekday: 5, n: undefined },
- Weekday { weekday: 6, n: undefined } ],
- interval: 1,
- freq: 2 }
- dateBeforeDST { from: 2019-03-17T23:00:00.000Z, to: 2019-03-24T23:00:00.000Z }
- dateAfterDST { from: 2019-03-31T22:00:00.000Z, to: 2019-04-07T22:00:00.000Z }
- -----------------------------------
- Before DST without TZ [ 2019-03-23T23:00:00.000Z ]
- After DST without TZ [ 2019-03-31T23:00:00.000Z, 2019-04-06T23:00:00.000Z ]
- -----------------------------------
- before DST with TZ [ 2019-03-23T00:00:00.000Z, 2019-03-24T00:00:00.000Z ]
- after DST with TZ [ 2019-04-06T00:00:00.000Z, 2019-04-07T00:00:00.000Z ]
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement