summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--lib/rss/rss.rb2
-rw-r--r--lib/time.rb23
3 files changed, 26 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 99ce763d23..9c0c112d9a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Sun May 4 17:58:12 2014 Tanaka Akira <akr@fsij.org>
+
+ * 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!.
+
Sun May 4 10:22:59 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* math.c (math_atan2): return values like as expected by C99 if
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)