BYU-ODH / hlrdesk

https://hlrdesk.hlrdev.byu.edu/
MIT License
0 stars 2 forks source link

Changes the due times to be at the end of the day and fixes a bug. #349

Closed aldahl closed 8 years ago

aldahl commented 8 years ago

I don't know if this is an issue with the database timezone or what, but when it would take any date submitted and convert it to 00:00 UTC time, which would be 17:00 the previous day due to the time difference. This is a slightly hacky way to fix that.

webnard commented 8 years ago

The TZ environment variable on Dokku is set to America/Denver, so it seems odd to me that times would be set to UTC +-0:00, especially on the server. The Postgres server has SHOW TIME ZONE set to "Navajo", whose territory does not touch BYU's campus, but it uses the MST/MDT time zone as well.

image

Are these issues machine-specific? Like, are they only present in Travis builds, or on the lab attendants' computers?

aldahl commented 8 years ago

Yeah I noticed that it was set to Navajo, but didn't think anything of it. As far as I can tell, it is not machine-specific, as it occurs on the Travis builds, on my local machine, and on the lab attendants' computers.

Does the node.js server have a timezone or anything? I think that the database is storing them as a date without specifying a timezone, but somehow they're getting converted to dates with a timezone.

webnard commented 8 years ago

@alexcdahl It looks like the current code gives me the end of the next day instead of the current day, though—is that intentional?

Node.js v0.12.9 Moment v2.8.4

$ process.env.TZ = 'America/Boise';
$ var moment = require('moment');
$ var g = new Date("2016-02-12 21:00:00 GMT-0700 (MST)");
$ moment(new Date(g.toString()).setHours(24)).hour(21).toDate();
> Sat Feb 13 2016 21:00:00 GMT-0700 (MST)
aldahl commented 8 years ago

So I figured it out. In the database, the due dates are stored as just dates (no timestamp). However, in javascript, the date object always has a timestamp, so when it queried the due dates from the database, it returned them as the dates, plus 00:00:00 UTC+0000, or midnight Greenwich time. Since we're at UTC-0700, it subtracted seven hours from that, making it 17:00 the previous day. I changed the code so it would compensate for the difference between the locale and Greenwhich, as well as set all due dates to just be 00:00:00 on their respective days.