Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-2158

Return UTC times when parsing extended json

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • bson-4.8.2
    • Affects Version/s: None
    • Component/s: BSON
    • None
    • Minor Change

      When a Time is encoded to bson and decoded the result is a UTC time:

      irb(main):008:0> Time.now
      => 2020-03-04 14:40:18.04943667 -0500
      irb(main):009:0> Time.now.to_bson
      => #<BSON::ByteBuffer:0x0000557ab847d370>
      irb(main):010:0> Time.from_bson(Time.now.to_bson)
      => 2020-03-04 19:40:26.553 UTC
      

      When a Time is encoded to extended json and decoded the result is a local time:

      irb(main):003:0> Time.now.as_extended_json
      => {"$date"=>{"$numberLong"=>"1583350627753"}}
      irb(main):005:0> BSON::ExtJSON.parse_obj(Time.now.as_extended_json)
      => 2020-03-04 14:37:25.927 -0500
      

      For consistency between the two serializations we should be returning the time in UTC when performing extended json parsing.

      Note that plain to_json does not round-trip times:

      irb(main):006:0> Time.now.to_json         
      => "\"2020-03-04 14:38:24 -0500\""
      irb(main):007:0> JSON.parse(Time.now.to_json)
      => "2020-03-04 14:38:40 -0500"
      

      When the times are returned in UTC, the workaround added in https://github.com/mongodb/mongo-ruby-driver/pull/1756 for this issue should be removed.

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: