harrisiirak/cron-parser

Time zone formatting not working as expected

faithfulojebiyi opened this issue · 1 comments

    const interval2 = parser.parseExpression(
      '0 * * * * *',
      {
        currentDate: DateTime.now().toJSDate(),
        tz: 'America/New_York',
      },
    );
    console.log(interval2);
    console.log('Date: ', interval2.next().toString());
    console.log('Date: ', interval2.next().toString());
    console.log('Date: ', interval2.next().toString());

Here's the code
and heres the result

Date:  Wed Mar 22 2023 21:44:00 GMT+0100 (West Africa Standard Time)
Date:  Wed Mar 22 2023 21:45:00 GMT+0100 (West Africa Standard Time)
Date:  Wed Mar 22 2023 21:46:00 GMT+0100 (West Africa Standard Time)
CronExpression {
  _options: { currentDate: 2023-03-22T20:43:05.540Z, tz: 'America/New_York' },
  _utc: false,
  _tz: 'America/New_York',
  _currentDate: CronDate {
    _date: DateTime {
      ts: 1679517785540,
      _zone: [IANAZone],
      loc: [Locale],
      invalid: null,
      weekData: null,
      c: [Object],
      o: -240,
      isLuxonDateTime: true
    }
  },
  _startDate: null,
  _endDate: null,
  _isIterator: false,
  _hasIterated: false,
  _nthDayOfWeek: 0,
  fields: {
    second: [ 0 ],
    minute: [
       0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,
      12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
      24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
      36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
      48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59
    ],
    hour: [
       0,  1,  2,  3,  4,  5,  6,  7,
       8,  9, 10, 11, 12, 13, 14, 15,
      16, 17, 18, 19, 20, 21, 22, 23
    ],
    dayOfMonth: [
       1,  2,  3,  4,  5,  6,  7,  8,  9,
      10, 11, 12, 13, 14, 15, 16, 17, 18,
      19, 20, 21, 22, 23, 24, 25, 26, 27,
      28, 29, 30, 31
    ],
    month: [
       1,  2, 3, 4,  5,
       6,  7, 8, 9, 10,
      11, 12
    ],
    dayOfWeek: [
      0, 1, 2, 3,
      4, 5, 6, 7
    ]
  }
}

Found out you on get the difference once you get to the daily context of cron jobs