Skip to content

Instantly share code, notes, and snippets.

@fj
Created September 28, 2012 14:13
Show Gist options
  • Save fj/3800120 to your computer and use it in GitHub Desktop.
Save fj/3800120 to your computer and use it in GitHub Desktop.
Why time zones suck
# Ψ irb --prompt=simple
require 'tzinfo'
# => true
tz = TZInfo::Timezone.get 'Asia/Shanghai'
# => #<TZInfo::DataTimezone: Asia/Shanghai>
tz.local_to_utc Time.mktime(1927, 12, 31, 23, 54, 5)
# => 1927-12-31 15:48:13 UTC
tz.local_to_utc Time.mktime(1927, 12, 31, 23, 54, 6)
# => 1927-12-31 15:48:14 UTC
tz.local_to_utc Time.mktime(1927, 12, 31, 23, 54, 7)
# => 1927-12-31 15:48:15 UTC
tz.local_to_utc Time.mktime(1927, 12, 31, 23, 54, 8)
# TZInfo::AmbiguousTime: Time: 1927-12-31 23:54:08 UTC is an ambiguous local time.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment