[SERVER-5774] Javascript Date.getDate() does timezone conversion to server's local timezone Created: 07/May/12  Updated: 15/Aug/12  Resolved: 07/May/12

Status: Closed
Project: Core Server
Component/s: JavaScript
Affects Version/s: 2.1.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Daniel Crosta Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

OS X 64bit server with local timezone anything other than UTC


Operating System: ALL
Participants:

 Description   

If you use the Date.getDate() function (returns day of month, 1-indexed) in server-side javascript, it seems that timezone conversion into the server's timezone is taking place (here with server in US/Eastern timezone):

> db.eval("function(){ return new ISODate('2012-05-07T00:00:00Z').getDate(); }")
6
> db.eval("function(){ return new ISODate('2012-05-07T12:00:00Z').getDate(); }")
7
> db.eval("function(){ return new ISODate('2012-05-07T23:00:00Z').getDate(); }")
7

Note that the local shell has the same behavior:

> new ISODate('2012-05-07T00:00:00Z').getDate()
6
> new ISODate('2012-05-07T12:00:00Z').getDate()
7
> new ISODate('2012-05-07T23:00:00Z').getDate()
7

I can't tell whether I think the shell ought to do this conversion or not. The server certainly shouldn't.



 Comments   
Comment by Scott Hernandez (Inactive) [ 07/May/12 ]

You want getUTCDate(), not getDate() (which runs in the local TZ):

> new ISODate('2012-05-07T00:00:00Z').getUTCDate()
7

Generated at Thu Feb 08 03:09:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.