Project

General

Profile

Actions

Feature #6720

closed

Discrepancy between DateTime#strftime('%s') and Time#strftime('%s') before 1582-10-15

Added by phasis68 (Heesob Park) over 12 years ago. Updated about 12 years ago.

Status:
Rejected
Target version:
[ruby-core:46317]

Description

I found some discrepancy between DateTime#strftime('%s') and Time#strftime('%s') on date before 1582-10-15

Consider this

C:>irb
irb(main):001:0> require 'date'
=> true
irb(main):002:0> Time.at(DateTime.new(0).strftime('%s').to_i)
=> -0001-12-30 09:00:00 +0900

irb(main):003:0> Time.at(DateTime.new(1000).strftime('%s').to_i)
=> 1000-01-06 09:00:00 +0900

irb(main):004:0> Time.at(DateTime.new(1500).strftime('%s').to_i)
=> 1500-01-10 09:00:00 +0900

irb(main):005:0> Time.at(DateTime.new(1582).strftime('%s').to_i)
=> 1582-01-11 09:00:00 +0900

irb(main):006:0> Time.at(DateTime.new(1582,10,4).strftime('%s').to_i)
=> 1582-10-14 09:00:00 +0900

irb(main):007:0> Time.at(DateTime.new(1582,10,5).strftime('%s').to_i)
ArgumentError: invalid date
from (irb):44:in new' from (irb):44 from c:/usr/bin/irb.bat:19:in '

irb(main):008:0> Time.at(DateTime.new(1582,10,15).strftime('%s').to_i)
=> 1582-10-15 09:00:00 +0900

irb(main):050:0> Time.at(DateTime.new.strftime('%s').to_i)
=> -4713-11-24 09:00:00 +0900

irb(main):009:0> Time.at(DateTime.new(1583).strftime('%s').to_i)
=> 1583-01-01 09:00:00 +0900

irb(main):051:0> DateTime.new
=> #<DateTime: -4712-01-01T00:00:00+00:00 ((0j,0s,0n),+0s,2299161j)>

I understand the dates between 1582-10-05 and 1582-10-14 are invalid.
But I cannot understand why the discrepancy changes for each year.

Is the discrepancy inevitable and should not use DateTime#strftime('%s') before 1582-10-15?

I think DateTime#strftime('%s') should return same result with Time#strftime('%s') always.

Updated by usa (Usaku NAKAMURA) over 12 years ago

  • Category changed from ext to core
  • Status changed from Open to Assigned
  • Assignee set to akira (akira yamada)

IMO, this is the problem of Time, not DateTime.
I think that this may be a limitation of Time.
Anyway, it is that akr judges.

Updated by akr (Akira Tanaka) over 12 years ago

2012/7/11 phasis68 (Heesob Park) :

I found some discrepancy between DateTime#strftime('%s') and Time#strftime('%s') on date before 1582-10-15

This is not a bug.

The difference is caused because
Time uses Proleptic Gregorian calendar (doc/NEWS-1.9.2) but
DateTime uses Julian/Gregorian calendar at Italy by default.

I guess you can use DateTime with Proleptic Gregorian calendar (doc/NEWS-1.9.3).

Tanaka Akira

Updated by akr (Akira Tanaka) about 12 years ago

  • Status changed from Assigned to Rejected
  • Assignee changed from akira (akira yamada) to akr (Akira Tanaka)
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0