bunkat / later

A javascript library for defining recurring schedules and calculating future (or past) occurrences for them. Includes support for using English phrases and Cron schedules. Works in Node and in the browser.
http://bunkat.github.io/later/
MIT License
2.42k stars 245 forks source link

Time zone? What am I missing? #205

Open zeg-io opened 7 years ago

zeg-io commented 7 years ago

Below is some code I consider pretty simple and straightforward.

The output (below) is I would expect, except that it acts as though I'm wanting it to operate on UTC +0, meaning that it considers 8 to be 3am and 17 to be 12pm!

is there a way other than changing those number to adjust the time zone? I'd rather it take into account daylight savings, etc.

let later = require('later')

    let schedule = later.parse.recur()
                    .every(1).hour().between(8, 17)
                    .on(30).minute()
                    .onWeekday()

    let sched = later.schedule(schedule)

    console.info(`${moment().format('YYYY-MM-DD hh:mm')} <-- now`)
    sched.next(5, new Date()).forEach(s => {
      console.info(moment(s).format('YYYY-MM-DD hh:mm'))
    })
2017-03-27 11:21 <-- now
2017-03-27 11:30
2017-03-27 12:30
2017-03-28 03:30
2017-03-28 04:30
2017-03-28 05:30
zeg-io commented 7 years ago

Ok, right after posting this I finally googled the right thing. Solution is to add: later.date.localTime() before the rest of your later time