Closed mountaindude closed 2 years ago
Meh - that was literally less than a minute from posting to realising that this works:
for (let i = 0; i < 5; i++) {
console.log(`${utcDate.toUTCString()} /// ${i + 1} /// ${occurrences[i].toUTCString()}`);
}
Still, from reading the docs I still expect that later.date.UTC()
would give me UTC straight from later...
Oh well - all good I guess :)
you need to call later.date.UTC()
before any other later calls.
@shadowgate15
Ok, but this code gives the same result as above, and I can't really move later.date.UTC()
any higher up..
const later = require('@breejs/later');
later.date.UTC();
const sched = later.parse.text('every 5 minutes');
const s = later.schedule(sched);
const occurrences = s.next(5);
const utcDate = new Date(Date.now());
console.log('-------------------------------------------------------------------------');
for (let i = 0; i < 5; i++) {
console.log(`${utcDate.toUTCString()} /// ${i + 1} /// ${occurrences[i]}`);
}
I figured it out, two things later
will will return a Date object which mean that when it is stringified by default it will be displayed with local time offset.
and later.date.UTC
makes later
parse all dates as UTC. I.e.
later.date.UTC();
// system currently set for CST
const sched = later.parse.text('every Monday at midnight');
const s = later.schedule(sched);
const next = s.next();
// `next` when stringified will be offset by 5 hours from midnight
// but `next` will actually be midnight UTC
Ahhh... nice. Gottit.
Many thanks!
On Thu, 21 Oct 2021 at 21:39, shadowgate15 @.***> wrote:
I figured it out, two things later will will return a Date object which mean that when it is stringified by default it will be displayed with local time offset.
and later.date.UTC makes later parse all dates as UTC. I.e.
later.date.UTC();// system currently set for CSTconst sched = later.parse.text('every Monday at midnight'); const s = later.schedule(sched);const next = s.next();//
next
when stringified will be offset by 5 hours from midnight// butnext
will actually be midnight UTC— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/breejs/later/issues/16#issuecomment-948944788, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAH3JDRBM7P5NN6BFBSY4JTUIBT65ANCNFSM5GO3AAUQ .
Having read the docs, my understanding is that I can call later.date.UTC() to make the occurrences I create to be in UTC. UTC should even be the default.
But no matter what I do I just get local time zone... The code snippet below prints current time as UTC to the left and the occurrences from later to the right. I am basically trying to get later output something without a timezone offset applied.
results in this: