lib/et-orbi.rb in et-orbi-1.1.3 vs lib/et-orbi.rb in et-orbi-1.1.4
- old
+ new
@@ -7,11 +7,11 @@
require 'et-orbi/zone_aliases'
module EtOrbi
- VERSION = '1.1.3'
+ VERSION = '1.1.4'
#
# module methods
class << self
@@ -341,11 +341,11 @@
@zone.local_to_utc(@zone.utc_to_local(utc))
false
- rescue TZInfo::AmbiguousTime => e
+ rescue TZInfo::AmbiguousTime
true
end
# Returns this ::EtOrbi::EoTime as a ::Time instance
@@ -539,10 +539,42 @@
def wday_in_month
[ count_weeks(-1), - count_weeks(1) ]
end
+ def reach(points)
+
+ t = EoTime.new(self.to_f, @zone)
+ step = 1
+
+ s = points[:second] || points[:sec] || points[:s]
+ m = points[:minute] || points[:min] || points[:m]
+ h = points[:hour] || points[:hou] || points[:h]
+
+ fail ArgumentError.new("missing :second, :minute, and :hour") \
+ unless s || m || h
+
+ if !s && !m
+ step = 60 * 60
+ t -= t.sec
+ t -= t.min * 60
+ elsif !s
+ step = 60
+ t -= t.sec
+ end
+
+ loop do
+ t += step
+ next if s && t.sec != s
+ next if m && t.min != m
+ next if h && t.hour != h
+ break
+ end
+
+ t
+ end
+
protected
# Returns a Ruby Time instance.
#
# Warning: the timezone of that Time instance will be UTC when used with
@@ -670,11 +702,12 @@
attr_accessor :_os_zone # test tool
def os_tz
- return (@_os_zone == '' ? nil : @_os_zone) if @_os_zone
+ return (@_os_zone == '' ? nil : @_os_zone) \
+ if defined?(@_os_zone) && @_os_zone
@os_tz ||= (debian_tz || centos_tz || osx_tz)
end
def to_windows_tz(zone_name, time=Time.now)
@@ -705,10 +738,13 @@
def to_offset(n)
i = n.to_i
sn = i < 0 ? '-' : '+'; i = i.abs
hr = i / 3600; mn = i % 3600; sc = i % 60
- (sc > 0 ? "%s%02d:%02d:%02d" : "%s%02d:%02d") % [ sn, hr, mn, sc ]
+
+ sc > 0 ?
+ '%s%02d:%02d:%02d' % [ sn, hr, mn, sc ] :
+ '%s%02d:%02d' % [ sn, hr, mn ]
end
def get_offset_tzone(str)
# custom timezones, no DST, just an offset, like "+08:00" or "-01:30"