Feature #6720

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

Added by Heesob Park over 3 years ago. Updated about 3 years ago.

Assignee:Akira Tanaka


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

Consider this

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
=> #

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.


#1 Updated by Usaku NAKAMURA over 3 years ago

  • Category changed from ext to core
  • Status changed from Open to Assigned
  • Assignee set to 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.

#2 Updated by Akira Tanaka over 3 years ago

2012/7/11 phasis68 (Heesob Park) phasis@gmail.com:

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

#3 Updated by Akira Tanaka about 3 years ago

  • Status changed from Assigned to Rejected
  • Assignee changed from akira yamada to Akira Tanaka

Also available in: Atom PDF