Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. const { RRule } = require('rrule');
  2.  
  3. const rulesWithoutTz = {
  4. until: new Date(Date.UTC(2021, 2, 23, 23, 0, 0)),
  5. dtstart: new Date(Date.UTC(2019, 1, 23, 23, 0, 0)),
  6. byweekday: [RRule.SA, RRule.SU],
  7. interval: 1,
  8. freq: 2
  9. };
  10.  
  11. const rulesWithTz = {
  12. until: new Date(Date.UTC(2021, 2, 24, 0, 0, 0)),
  13. dtstart: new Date(Date.UTC(2019, 1, 24, 0, 0, 0)),
  14. byweekday: [RRule.SA, RRule.SU],
  15. tzid: 'Europe/Paris',
  16. interval: 1,
  17. freq: 2
  18. };
  19.  
  20. const rrulesWithoutTz = new RRule(rulesWithoutTz);
  21. const rrulesWithTz = new RRule(rulesWithTz);
  22.  
  23. const dateRangeBeforeDST = {
  24. from: new Date(Date.UTC(2019, 2, 17, 23, 0, 0)),
  25. to: new Date(Date.UTC(2019, 2, 24, 23, 0, 0))
  26. };
  27.  
  28. const dateRangeAfterDST = {
  29. from: new Date(Date.UTC(2019, 2, 31, 22, 0, 0)),
  30. to: new Date(Date.UTC(2019, 3, 7, 22, 0, 0))
  31. };
  32.  
  33. console.log('rulesWithoutTz', rulesWithoutTz);
  34. console.log('dateBeforeDST', dateRangeBeforeDST);
  35. console.log('dateAfterDST', dateRangeAfterDST);
  36. console.log('Before DST without TZ', rrulesWithoutTz.between(dateRangeBeforeDST.from, dateRangeBeforeDST.to));
  37. console.log('After DST without TZ', rrulesWithoutTz.between(dateRangeAfterDST.from, dateRangeAfterDST.to));
  38. console.log('-----------------------------------');
  39. console.log('before DST with TZ', rrulesWithTz.between(dateRangeBeforeDST.from, dateRangeBeforeDST.to));
  40. console.log('after DST with TZ', rrulesWithTz.between(dateRangeAfterDST.from, dateRangeAfterDST.to));
  41.  
  42. /*
  43. output :
  44.  
  45. rulesWithoutTz { until: 2021-03-23T23:00:00.000Z,
  46. dtstart: 2019-02-23T23:00:00.000Z,
  47. byweekday:
  48. [ Weekday { weekday: 5, n: undefined },
  49. Weekday { weekday: 6, n: undefined } ],
  50. interval: 1,
  51. freq: 2 }
  52. dateBeforeDST { from: 2019-03-17T23:00:00.000Z, to: 2019-03-24T23:00:00.000Z }
  53. dateAfterDST { from: 2019-03-31T22:00:00.000Z, to: 2019-04-07T22:00:00.000Z }
  54. -----------------------------------
  55. Before DST without TZ [ 2019-03-23T23:00:00.000Z ]
  56. After DST without TZ [ 2019-03-31T23:00:00.000Z, 2019-04-06T23:00:00.000Z ]
  57. -----------------------------------
  58. before DST with TZ [ 2019-03-23T00:00:00.000Z, 2019-03-24T00:00:00.000Z ]
  59. after DST with TZ [ 2019-04-06T00:00:00.000Z, 2019-04-07T00:00:00.000Z ]
  60.  
  61. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement