summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-04 09:01:19 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-04 09:01:19 +0000
commita18177d5ed270ba7007c12011b9693ec226b1ad6 (patch)
tree587f2aa211257018675b6cfd15ee5481f0789ec4 /lib
parentd64eef156f4a95797b31deee1c64a4090bc40bb5 (diff)
* lib/time.rb (Time.force_zone!): New private method.
(Time.make_time): Use Time.force_zone!. (Time.strptime): Ditto. (Time.rfc2822): Ditto. (Time.xmlschema): Ditto. * lib/rss/rss.rb (Time.w3cdtf): Use Time.force_zone!. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45807 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/rss/rss.rb2
-rw-r--r--lib/time.rb23
2 files changed, 16 insertions, 9 deletions
diff --git a/lib/rss/rss.rb b/lib/rss/rss.rb
index fc4f9328ac..4f6732b4d2 100644
--- a/lib/rss/rss.rb
+++ b/lib/rss/rss.rb
@@ -28,7 +28,7 @@ class Time
datetime = apply_offset(*(datetime + [off]))
datetime << usec
time = Time.utc(*datetime)
- time.localtime(off) unless zone_utc?(zone)
+ force_zone!(time, zone, off)
time
else
datetime << usec
diff --git a/lib/time.rb b/lib/time.rb
index 3b928a205f..e394078a03 100644
--- a/lib/time.rb
+++ b/lib/time.rb
@@ -174,6 +174,17 @@ class Time
end
private :zone_utc?
+ def force_zone!(t, zone, offset=nil)
+ if zone_utc?(zone)
+ t.utc
+ elsif offset ||= zone_offset(zone)
+ t.localtime(offset)
+ else
+ t.localtime
+ end
+ end
+ private :force_zone!
+
LeapYearMonthDays = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] # :nodoc:
CommonYearMonthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] # :nodoc:
def month_days(y, m)
@@ -258,7 +269,7 @@ class Time
year, mon, day, hour, min, sec =
apply_offset(year, mon, day, hour, min, sec, off)
t = self.utc(year, mon, day, hour, min, sec, usec)
- t.localtime(off) if !zone_utc?(zone)
+ force_zone!(t, zone, off)
t
else
self.local(year, mon, day, hour, min, sec, usec)
@@ -395,11 +406,7 @@ class Time
if seconds = d[:seconds]
t = Time.at(seconds)
if zone = d[:zone]
- if zone_utc?(zone)
- t.utc
- elsif offset = zone_offset(zone)
- t.localtime(offset)
- end
+ force_zone!(t, zone)
end
else
year = d[:year]
@@ -460,7 +467,7 @@ class Time
year, mon, day, hour, min, sec =
apply_offset(year, mon, day, hour, min, sec, off)
t = self.utc(year, mon, day, hour, min, sec)
- t.localtime(off) if !zone_utc?(zone)
+ force_zone!(t, zone, off)
t
else
raise ArgumentError.new("not RFC 2822 compliant date: #{date.inspect}")
@@ -552,7 +559,7 @@ class Time
year, mon, day, hour, min, sec =
apply_offset(year, mon, day, hour, min, sec, off)
t = self.utc(year, mon, day, hour, min, sec, usec)
- t.localtime(off) if !zone_utc?(zone)
+ force_zone!(t, zone, off)
t
else
self.local(year, mon, day, hour, min, sec, usec)