Time.rb

time.rb e$B$O!"e(BTime
e$B$r7Q>5$7$?:]$K$&$^$/5!G=$7$J$$$h$&$K;W$$$^$9!#e(B

e$B$?$H$($P!"e(B

$ cat t2.rb
require ‘time’
class Time2 < Time; end

e$B$H$7$?>l9g!"F1$8e(B httpdate e$B$G$b!"7A<0$N0c$$$K$h$j!"e(BTime
e$B$K$J$C$?$j!"e(B
Time2 e$B$K$J$C$?$j$7$^$9!#e(B

Time2.httpdate(“Sunday, 06-Nov-94 08:49:37 GMT”).class #=> Time
Time2.httpdate(“Thu, 01 Dec 1994 16:00:00 GMT”).class #=> Time2

time.rb e$B$NDj5AK\BN$G!“e(BTime
e$B$X$ND>@\E*$J;2>H$r95$($k$3$H$K$7$?$$$N$G$9e(B
e$B$,!”$I$&$G$7$g$&!#e(B

Index: lib/time.rb

— lib/time.rb (revision 15003)
+++ lib/time.rb (working copy)
@@ -66,7 +66,7 @@
‘N’ => -1, ‘O’ => -2, ‘P’ => -3, ‘Q’ => -4, ‘R’ => -5, ‘S’ =>
-6,
‘T’ => -7, ‘U’ => -8, ‘V’ => -9, ‘W’ => -10, ‘X’ => -11, ‘Y’ =>
-12,
}

  • def zone_offset(zone, year=Time.now.year)
  • def zone_offset(zone, year=self.now.year)
    off = nil
    zone = zone.upcase
    if /\A([±])(\d\d):?(\d\d)\z/ =~ zone
    @@ -75,9 +75,9 @@
    off = zone.to_i * 3600
    elsif ZoneOffset.include?(zone)
    off = ZoneOffset[zone] * 3600
  •  elsif ((t = Time.local(year, 1, 1)).zone.upcase == zone rescue 
    

false)

  •  elsif ((t = self.local(year, 1, 1)).zone.upcase == zone rescue 
    

false)
off = t.utc_offset

  •  elsif ((t = Time.local(year, 7, 1)).zone.upcase == zone rescue 
    

false)

  •  elsif ((t = self.local(year, 7, 1)).zone.upcase == zone rescue 
    

false)
off = t.utc_offset
end
off
@@ -177,7 +177,7 @@
if off
year, mon, day, hour, min, sec =
apply_offset(year, mon, day, hour, min, sec, off)

  •    t = Time.utc(year, mon, day, hour, min, sec, usec)
    
  •    t = self.utc(year, mon, day, hour, min, sec, usec)
       t.localtime if !zone_utc?(zone)
       t
     else
    

@@ -236,7 +236,7 @@
#
# A failure for Time.parse should be checked, though.
#

  • def parse(date, now=Time.now)
  • def parse(date, now=self.now)
    d = Date._parse(date, false)
    year = d[:year]
    year = yield(year) if year && block_given?
    @@ -250,7 +250,7 @@

    block. For example:

    Time.strptime(…) {|y| y < 100 ? (y >= 69 ? y + 1900 : y +

  1. : y}
  • def strptime(date, format, now=Time.now)
  • def strptime(date, format, now=self.now)
    d = Date._strptime(date, format)
    raise ArgumentError, “invalid strptime format - `#{format}’”
    unless d
    year = d[:year]
    @@ -344,7 +344,7 @@
    else
    year += 1900
    end
  •    Time.utc(year, $2, $1.to_i, $4.to_i, $5.to_i, $6.to_i)
    
  •    self.utc(year, $2, $1.to_i, $4.to_i, $5.to_i, $6.to_i)
     elsif /\A\s*
            (?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\x20
            (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\x20
    

@@ -389,9 +389,9 @@
zone = $8
year, mon, day, hour, min, sec =
apply_offset(year, mon, day, hour, min, sec,
zone_offset(zone))

  •      Time.utc(year, mon, day, hour, min, sec, usec)
    
  •      self.utc(year, mon, day, hour, min, sec, usec)
       else
    
  •      Time.local(year, mon, day, hour, min, sec, usec)
    
  •      self.local(year, mon, day, hour, min, sec, usec)
       end
     else
       raise ArgumentError.new("invalid date: #{date.inspect}")

In article [email protected],
Tadayoshi F. [email protected] writes:

time.rb e$B$NDj5AK\BN$G!“e(BTime e$B$X$ND>@\E*$J;2>H$r95$($k$3$H$K$7$?$$$N$G$9e(B
e$B$,!”$I$&$G$7$g$&!#e(B

e$B$J$k$[$I!#$I$&$>!#e(B

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs