Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time.Date() incorrect for Jan 31, 2010 19:00 GMT #28

Closed
danpres14 opened this issue Nov 30, 2012 · 10 comments
Closed

time.Date() incorrect for Jan 31, 2010 19:00 GMT #28

danpres14 opened this issue Nov 30, 2012 · 10 comments

Comments

@danpres14
Copy link

The following line seems to be returning "Sun Jan 03 2010 19:00:00 GMT+0000 (UTC)"

var newTime = new time.Date(2010, 0, 31, 19, 0, 0, 0, 'UTC');
var newTimeString = newTime.toString();

I think this should be returning "Sun Jan 31..." instead. I really appreciate the help with this - if I'm missing something, I'm sure not seeing it.

Thanks,
-Dan

The code I need looks a little more like this but I can't seem to get the hard-coded values to work so that seems like the place to start.

var newTime = new time.Date(startTime.getUTCFullYear(), startTime.getUTCMonth(), startTime.getUTCDate(), startTime.getUTCHours(), startTime.getUTCMinutes(), 0, 0);//, 'UTC');
newTime.setTimezone('UTC');
newTime.setTimezone(timezone);
@haozhun
Copy link

haozhun commented Dec 1, 2012

I can reproduce this bug with local timezone set to "America/Los_Angeles".

@danpres14
Copy link
Author

Looks like this particular bug may have something to do with dates on the 31st of the month - this one also incorrectly gives March 1st...

newTime = new time.Date(2010, 2, 31, 19, 0, 0, 0, 'UTC');

@danpres14
Copy link
Author

I found a workaround that seems to work for my needs so far. If I create a standard JavaScript Date object with the correct year, month, day, hour, and minute, then create a new time.Date from the standard JavaScript Date, all of the timezone manipulations seem to work as expected. I will obviously need to do more testing but it's looking promising at the moment.

var jsUTC = Date.UTC(2010, 0, 31, 19, 0, 0, 0);
var jsTime = new Date(jsUTC);
var newTime = new time.Date(jsTime);
newTime.setTimezone('UTC', false);
newTime.setTimezone(timezone);

@mdedetrich
Copy link

I am getting this issue as well
http://stackoverflow.com/questions/14618254/issue-in-node-js-timezone

Unfortunately I can't find a work around for my issue using this library. I am going from Australia/Sydney (or any other generic timezone) to UTC, and not vice versa. This means I cant use the Date.UTC (or normal Date functions) as they will be in the incorrect timezone (UTC) and it defeats the purpose of using this library

@zenoamaro
Copy link

Hi. I think I've fixed the problem you are having.

This patch should produce correct results even on the last days of a month, and also when going back to UTC with setTimezone, both forwards and backwards.

Tests are included, but please try this on your code too.

TooTallNate added a commit that referenced this issue Jan 31, 2013
Fixes #28: Incorrect timezone calculation on edge of months.
@TooTallNate
Copy link
Owner

Fixed in the v0.8.4 release.

@TooTallNate
Copy link
Owner

Sorry about the wait guys!

@blax
Copy link
Contributor

blax commented Mar 19, 2013

Actually this fix created inverse problem:

> new time.Date(2013,02,01,00,00,"US/Eastern")
{ Fri, 01 Mar 2013 05:00:00 GMT

@zenoamaro
Copy link

@blax: strange, I thought I did test that too.

I guess operating differently according to the day of month is too hacky, but it could work as a quick fix.

@blax
Copy link
Contributor

blax commented Mar 19, 2013

I've noticed it strongly depends on your local system TimeZone and tests seem to not take it into consideration at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants