Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-5774

Javascript Date.getDate() does timezone conversion to server's local timezone

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.1.1
    • Component/s: JavaScript
    • None
    • Environment:
      OS X 64bit server with local timezone anything other than UTC
    • ALL

      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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            dcrosta Daniel Crosta
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: