lib/et-orbi.rb in et-orbi-1.1.2 vs lib/et-orbi.rb in et-orbi-1.1.3
- old
+ new
@@ -7,11 +7,11 @@
require 'et-orbi/zone_aliases'
module EtOrbi
- VERSION = '1.1.2'
+ VERSION = '1.1.3'
#
# module methods
class << self
@@ -313,11 +313,12 @@
"\nTry setting `ENV['TZ'] = 'Continent/City'` in your script " +
"(see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)" +
(defined?(TZInfo::Data) ? '' : "\nand adding gem 'tzinfo-data'")
) unless @zone
- @time = nil # cache for #to_time result
+ @time = nil
+ # cache for #to_time result
end
def seconds=(f)
@time = nil
@@ -328,10 +329,27 @@
@time = nil
@zone = self.class.get_tzone(zone || :current)
end
+ # Returns true if this EoTime instance corresponds to 2 different UTC
+ # times.
+ # It happens when transitioning from DST to winter time.
+ #
+ # https://www.timeanddate.com/time/change/usa/new-york?year=2018
+ #
+ def ambiguous?
+
+ @zone.local_to_utc(@zone.utc_to_local(utc))
+
+ false
+
+ rescue TZInfo::AmbiguousTime => e
+
+ true
+ end
+
# Returns this ::EtOrbi::EoTime as a ::Time instance
# in the current UTC timezone.
#
def utc
@@ -462,10 +480,15 @@
def to_s
strftime('%Y-%m-%d %H:%M:%S %z')
end
+ def to_zs
+
+ strftime('%Y-%m-%d %H:%M:%S %/Z')
+ end
+
def iso8601(fraction_digits=0)
s = (fraction_digits || 0) > 0 ? ".%#{fraction_digits}N" : ''
strftime("%Y-%m-%dT%H:%M:%S#{s}%:z")
end
@@ -525,10 +548,10 @@
# Warning: the timezone of that Time instance will be UTC when used with
# TZInfo < 2.0.0.
#
def to_time
- @time ||= begin; u = utc; @zone.utc_to_local(u); end
+ @time ||= @zone.utc_to_local(utc)
end
def count_weeks(dir)
c = 0