Skip to content

Time#to_datetime incorrect for times before the date of calendar reform #4822

@jeremyevans

Description

@jeremyevans

Environment

jruby 9.1.13.0 (2.3.3) 2017-09-06 8e1c115 OpenJDK 64-Bit Server VM 25.144-b01 on 1.8.0_144-b01 +jit [OpenBSD-x86_64]
OpenBSD systemname.local 6.2 GENERIC.MP#140 amd64

Also tested on:

jruby 9.1.12.0 (2.3.3) 2017-06-15 33c6439 Java HotSpot(TM) 64-Bit Server VM 25.131-b11 on 1.8.0_131-b11 +jit [mswin32-x86_64]
Windows 10 Professional

Expected Behavior

Same Results as CRuby for the following code:

require 'date'
# after date of calendar reform in 1582: correct
p Time.at(-12000000000).utc
p Time.at(-12000000000).utc.to_datetime 
# before date of calendar reform in 1582: incorrect
p Time.at(-12500000000).utc
p Time.at(-12500000000).utc.to_datetime 

CRuby Results:

1589-09-26 02:40:00 UTC
#<DateTime: 1589-09-26T02:40:00+00:00 ((2301699j,9600s,0n),+0s,2299161j)>
1573-11-22 01:46:40 UTC
#<DateTime: 1573-11-22T01:46:40+00:00 ((2295922j,6400s,0n),+0s,2299161j)>

Actual Behavior

JRuby Results:

1589-09-26 02:40:00 UTC
#<DateTime: 1589-09-26T02:40:00+00:00 ((2301699j,9600s,0n),+0s,2299161j)>
1573-11-22 01:46:40 UTC
#<DateTime: 1573-11-12T01:46:40+00:00 ((2295912j,6400s,0n),+0s,2299161j)>

Note the change from 1573-11-22 to 1573-11-12 in last line of output.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions