* 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
This commit is contained in:
akr 2014-05-04 09:01:19 +00:00
Родитель d64eef156f
Коммит a18177d5ed
3 изменённых файлов: 26 добавлений и 9 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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)