lib/rufus/scheduler/zotime.rb in rufus-scheduler-3.3.1 vs lib/rufus/scheduler/zotime.rb in rufus-scheduler-3.3.2
- old
+ new
@@ -1,7 +1,7 @@
#--
-# Copyright (c) 2006-2016, John Mettraux, jmettraux@gmail.com
+# Copyright (c) 2006-2017, John Mettraux, jmettraux@gmail.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@@ -283,11 +283,11 @@
return nil if str == '*'
# ok, it's a timezone then
ostr = str
- str = Time.now.zone if str == :current || str == :local
+ str = ENV['TZ'] || Time.now.zone if str == :current || str == :local
# utc_offset
if str.is_a?(Numeric)
i = str.to_i
@@ -306,16 +306,30 @@
# time zone abbreviations
if str.match(/\A[A-Z0-9-]{3,6}\z/)
- twin = Time.utc(Time.now.year, 1, 1)
- tsum = Time.utc(Time.now.year, 7, 1)
+ toff = Time.now.utc_offset
+ toff = nil if str != Time.now.zone
+ twin = Time.utc(Time.now.year, 1, 1) # winter
+ tsum = Time.utc(Time.now.year, 7, 1) # summer
+
z =
::TZInfo::Timezone.all.find do |tz|
- tz.period_for_utc(twin).abbreviation.to_s == str ||
- tz.period_for_utc(tsum).abbreviation.to_s == str
+
+ pwin = tz.period_for_utc(twin)
+ psum = tz.period_for_utc(tsum)
+
+ if toff
+ (pwin.abbreviation.to_s == str && pwin.utc_offset == toff) ||
+ (psum.abbreviation.to_s == str && psum.utc_offset == toff)
+ else
+ # returns the first tz with the given abbreviation, almost useless
+ # favour fully named zones...
+ pwin.abbreviation.to_s == str ||
+ psum.abbreviation.to_s == str
+ end
end
return z if z
end
# some time zone aliases