Project

General

Profile

Actions

Bug #12259

closed

DateTime.parse does not take into account the system timezone

Added by sonots (Naotoshi Seo) almost 8 years ago. Updated over 4 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin13]
[ruby-core:74845]

Description

DateTime.parse does not take into account the system timezone although Time.parse does take into account the system timezone.

irb(main):002:0> DateTime.parse('2011-10-10 10:00:00')
=> #<DateTime: 2011-10-10T10:00:00+00:00 ((2455845j,36000s,0n),+0s,2299161j)>
irb(main):005:0> Time.parse('2011-10-10 10:00:00')
=> 2011-10-10 10:00:00 +0900

Are there any reasons that DateTime.parse behaves like this?
Can this behavior be changed, or do we have to keep this behavior for lower version compatibility?

Updated by sonots (Naotoshi Seo) almost 8 years ago

  • Subject changed from DateTime.parse does not take into account system time to DateTime.parse does not take into account the system timezone

Updated by jeremyevans0 (Jeremy Evans) almost 5 years ago

I do not think this is a bug. DateTime has always defaulted to UTC, not just in DateTime.parse:

DateTime.new.zone
# => "+00:00"

DateTime.strptime('2009', '%Y').zone
# => "+00:00"

DateTime.jd(2458000)
# => "+00:00"

To switch to defaulting to local time for compatibility with Time would be a huge break to backwards compatibility, and I don't think such a change is worthwhile. I think DateTime mostly exists for backwards compatibility, since starting in Ruby 2.6, Time can handle timezones (timezone handling was the last major advantage of DateTime over Time).

Actions #3

Updated by jeremyevans0 (Jeremy Evans) over 4 years ago

  • Status changed from Open to Rejected
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0