Skip to content

DateTime loses timezone offsets on marshal/unmarshal #6385

@pauline2k

Description

@pauline2k

On JRuby 9.2, marshaling and unmarshaling a DateTime object with a nonzero timezone offset outputs an “invalid offset is ignored” warning, and returns a DateTime with the timezone offset set to zero.

I believe the marshal dump and load methods in org.jruby.ext.date.RubyDate may be representing nonzero timezone offsets in an incompatible way.

Environment Information

  • JRuby 9.2.13.0
  • Fresh install with no additional gems
  • No additional flags or JRUBY_OPTS

Expected Behavior

On MRI 2.5.7, marshaling and unmarshaling a DateTime object preserves timezone offset without error. Minimal example in irb:

:001 > require 'date'
 => true 
 :002 > d = DateTime.now
 => #<DateTime: 2020-09-03T10:00:56-07:00 ((2459096j,61256s,323456000n),-25200s,2299161j)> 
 :003 > Marshal.load(Marshal.dump(d))
 => #<DateTime: 2020-09-03T10:00:56-07:00 ((2459096j,61256s,323456000n),-25200s,2299161j)>

Actual Behavior

Minimal irb example in JRuby 9.2.13.0. Note “invalid offset is ignored” warning and loss of timezone offset information after marshaling and unmarshaling.

jruby-9.2.13.0 :001 > require 'date'
 => true 
jruby-9.2.13.0 :002 > d = DateTime.now
 => #<DateTime: 2020-09-03T09:53:30-07:00 ((2459096j,60810s,196000000n),-25200s,2299161j)> 
jruby-9.2.13.0 :003 > Marshal.load(Marshal.dump(d))
invalid offset is ignored
 => #<DateTime: 2020-09-03T16:53:30+00:00 ((2459096j,60810s,196000000n),+0s,2299161j)> 

A DateTime object with zero offset does not trigger the warning.

jruby-9.2.13.0 :001 > require 'date'
 => true 
jruby-9.2.13.0 :002 > d = DateTime.now.new_offset(0)
 => #<DateTime: 2020-09-03T17:19:31+00:00 ((2459096j,62371s,904000000n),+0s,2299161j)> 
jruby-9.2.13.0 :003 > Marshal.load(Marshal.dump(d))
 => #<DateTime: 2020-09-03T17:19:31+00:00 ((2459096j,62371s,904000000n),+0s,2299161j)> 

JRuby 9.1.17.0 does not exhibit the issue.

jruby-9.1.17.0 :001 > require 'date'
 => true 
jruby-9.1.17.0 :002 > d = DateTime.now
 => #<DateTime: 2020-09-03T10:13:04-07:00 ((2459096j,61984s,83000000n),-25200s,2299161j)> 
jruby-9.1.17.0 :003 > Marshal.load(Marshal.dump(d))
 => #<DateTime: 2020-09-03T10:13:04-07:00 ((2459096j,61984s,83000000n),-25200s,2299161j)> 

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions