Hi all.
I’m using the same SyncedCron script on Meteor Startup when I develop locally as what’s on the production server (Ubuntu 16.04). I’m in America/New_York TZ and using Moment.js.
I also have the server configured to be in the U.S. Eastern timezone; set via:
$ sudo dpkg-reconfigure tzdata
When the app runs locally, it detects that I have an “event” correctly on server side console output:
I20180527-23:31:20.518(-4)? ===========================
I20180527-23:31:20.520(-4)? Event found for today. Event ID: ghnvLbbKFwSACg9J2
I20180527-23:31:20.555(-4)? Current time: 2018-05-27T23:31:20-04:00
I20180527-23:31:20.557(-4)? Event start: 2018-05-27T23:01:00-04:00
I20180527-23:31:20.558(-4)? Event end: 2018-05-27T23:03:00-04:00
I20180527-23:31:20.559(-4)? Event active? false
I20180527-23:31:20.561(-4)? This event occurs today but it is not active.
I20180527-23:31:20.562(-4)? ===========================
Locally, if an event is not detected for the day:
I20180527-23:33:30.187(-4)? ===========================
I20180527-23:33:30.190(-4)? Current day: Sun May 27 2018 00:00:00 GMT-0400 (EDT)
I20180527-23:33:30.193(-4)? No event scheduled for today.
I20180527-23:33:30.213(-4)? ===========================
On production, at the same time as the app running locally (mup logs --tail -f
):
[66.228.42.205]===========================
[66.228.42.205]Current day: Mon May 28 2018 00:00:00 GMT+0000 (UTC)
[66.228.42.205]No event scheduled for today.
[66.228.42.205]===========================
The current day was still May 27 and not yet May 28, but due to as late as it was in the evening (11:30ish PM EST) in the example above, UTC is in May 28.
So, you can see in the "Current day: " output that the server is reading the timestamp as UTC but locally, the server is correctly reading the time as EDT.
Here’s the code used:
startup.js
:
SyncedCron.add({
name: 'Event Checker Image Poller',
schedule(parser) {
return parser.text('every 30 seconds');
},
job: function() {
var today = moment().startOf('day'),
today = moment(today).toDate();
var query = {
"eventDate" : today
}
var result = Event.findOne(query);
if (result) {
console.log('===========================');
console.log("Event found for today. Event ID: " + result._id);
var eventId = result._id,
gallery = Gallery.findOne({
galleryToEvent: eventId
}),
localCurrent = moment.tz("America/New_York").format(),
eventStart = moment(result.eventStartTime).format(),
eventEnd = moment(result.eventEndTime).format(),
eventActive = moment(localCurrent).isBetween(eventStart, eventEnd);
console.log("Current time: " + localCurrent);
console.log("Event start: " + eventStart);
console.log("Event end: " + eventEnd);
console.log("Event active? " + eventActive);
////////////////////////////////////
/////////// CHECK B2 ///////////////
////////////////////////////////////
if (eventActive) {
// do my stuff
} else {
console.log("This event occurs today but it is not active.");
console.log('===========================');
}
////////////////////////////////////
///////// END CHECK B2 /////////////
////////////////////////////////////
} else {
console.log('===========================');
console.log("Current day: " + today);
console.log("No event scheduled for today.");
console.log('===========================');
}
}
});
SyncedCron.start();
Any suggestions or thoughts here to get production to read in EDT like it does locally?
Thanks!