mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/time] Use Time#strftime to format
https://github.com/ruby/time/commit/6b8cc4799e
This commit is contained in:
parent
0d57d59933
commit
5307fab661
1 changed files with 2 additions and 26 deletions
28
lib/time.rb
28
lib/time.rb
|
@ -666,30 +666,10 @@ class Time
|
|||
# You must require 'time' to use this method.
|
||||
#
|
||||
def rfc2822
|
||||
sprintf('%s, %02d %s %0*d %02d:%02d:%02d ',
|
||||
RFC2822_DAY_NAME[wday],
|
||||
day, RFC2822_MONTH_NAME[mon-1], year < 0 ? 5 : 4, year,
|
||||
hour, min, sec) <<
|
||||
if utc?
|
||||
'-0000'
|
||||
else
|
||||
off = utc_offset
|
||||
sign = off < 0 ? '-' : '+'
|
||||
sprintf('%s%02d%02d', sign, *(off.abs / 60).divmod(60))
|
||||
end
|
||||
strftime('%a, %d %b %Y %T ') << (utc? ? '-0000' : strftime('%z'))
|
||||
end
|
||||
alias rfc822 rfc2822
|
||||
|
||||
|
||||
RFC2822_DAY_NAME = [ # :nodoc:
|
||||
'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'
|
||||
]
|
||||
|
||||
RFC2822_MONTH_NAME = [ # :nodoc:
|
||||
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
||||
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
|
||||
]
|
||||
|
||||
#
|
||||
# Returns a string which represents the time as RFC 1123 date of HTTP-date
|
||||
# defined by RFC 2616:
|
||||
|
@ -706,11 +686,7 @@ class Time
|
|||
# You must require 'time' to use this method.
|
||||
#
|
||||
def httpdate
|
||||
t = dup.utc
|
||||
sprintf('%s, %02d %s %0*d %02d:%02d:%02d GMT',
|
||||
RFC2822_DAY_NAME[t.wday],
|
||||
t.day, RFC2822_MONTH_NAME[t.mon-1], t.year < 0 ? 5 : 4, t.year,
|
||||
t.hour, t.min, t.sec)
|
||||
getutc.strftime('%a, %d %b %Y %T GMT')
|
||||
end
|
||||
|
||||
#
|
||||
|
|
Loading…
Reference in a new issue