mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
updated based on date2 4.0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11432 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5ba0254777
commit
7290b6925c
3 changed files with 607 additions and 571 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Sun Dec 31 00:15:13 2006 Tadayoshi Funaba <tadf@dotrb.org>
|
||||||
|
|
||||||
|
* lib/date.rb, lib/date/format.rb: updated based on date2 4.0.
|
||||||
|
|
||||||
Sat Dec 30 04:38:23 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Sat Dec 30 04:38:23 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* enum.c (enum_each_with_index): reuse array for yield parameters.
|
* enum.c (enum_each_with_index): reuse array for yield parameters.
|
||||||
|
|
793
lib/date.rb
793
lib/date.rb
File diff suppressed because it is too large
Load diff
|
@ -1,5 +1,5 @@
|
||||||
# format.rb: Written by Tadayoshi Funaba 1999-2006
|
# format.rb: Written by Tadayoshi Funaba 1999-2006
|
||||||
# $Id: format.rb,v 2.28 2006-10-25 06:45:12+09 tadf Exp $
|
# $Id: format.rb,v 2.29 2006-12-30 21:43:41+09 tadf Exp $
|
||||||
|
|
||||||
require 'rational'
|
require 'rational'
|
||||||
|
|
||||||
|
@ -239,24 +239,24 @@ class Date
|
||||||
when 'j'; emit_n(yday, 3, f)
|
when 'j'; emit_n(yday, 3, f)
|
||||||
when 'k'; emit_a(hour, 2, f)
|
when 'k'; emit_a(hour, 2, f)
|
||||||
when 'L'
|
when 'L'
|
||||||
emit_n((sec_fraction / (1.to_r/86400/(10**3))).round, 3, f)
|
emit_n((sec_fraction / (1.to_r/(10**3))).round, 3, f)
|
||||||
when 'l'; emit_a((hour % 12).nonzero? || 12, 2, f)
|
when 'l'; emit_a((hour % 12).nonzero? || 12, 2, f)
|
||||||
when 'M'; emit_n(min, 2, f)
|
when 'M'; emit_n(min, 2, f)
|
||||||
when 'm'; emit_n(mon, 2, f)
|
when 'm'; emit_n(mon, 2, f)
|
||||||
when 'N'
|
when 'N'
|
||||||
emit_n((sec_fraction / (1.to_r/86400/(10**9))).round, 9, f)
|
emit_n((sec_fraction / (1.to_r/(10**9))).round, 9, f)
|
||||||
when 'n'; "\n"
|
when 'n'; "\n"
|
||||||
when 'P'; emit_ad(strftime('%p').downcase, 0, f)
|
when 'P'; emit_ad(strftime('%p').downcase, 0, f)
|
||||||
when 'p'; emit_au(if hour < 12 then 'AM' else 'PM' end, 0, f)
|
when 'p'; emit_au(if hour < 12 then 'AM' else 'PM' end, 0, f)
|
||||||
when 'Q'
|
when 'Q'
|
||||||
d = ajd - self.class.jd_to_ajd(self.class::UNIXEPOCH, 0)
|
d = ajd - jd_to_ajd(self.class::UNIXEPOCH, 0)
|
||||||
s = (d * 86400*10**3).to_i
|
s = (d * 86400*10**3).to_i
|
||||||
emit_sn(s, 1, f)
|
emit_sn(s, 1, f)
|
||||||
when 'R'; emit_a(strftime('%H:%M'), 0, f)
|
when 'R'; emit_a(strftime('%H:%M'), 0, f)
|
||||||
when 'r'; emit_a(strftime('%I:%M:%S %p'), 0, f)
|
when 'r'; emit_a(strftime('%I:%M:%S %p'), 0, f)
|
||||||
when 'S'; emit_n(sec, 2, f)
|
when 'S'; emit_n(sec, 2, f)
|
||||||
when 's'
|
when 's'
|
||||||
d = ajd - self.class.jd_to_ajd(self.class::UNIXEPOCH, 0)
|
d = ajd - jd_to_ajd(self.class::UNIXEPOCH, 0)
|
||||||
s = (d * 86400).to_i
|
s = (d * 86400).to_i
|
||||||
emit_sn(s, 1, f)
|
emit_sn(s, 1, f)
|
||||||
when 'T'
|
when 'T'
|
||||||
|
@ -310,21 +310,6 @@ class Date
|
||||||
([emit_z(sign * hh, 2, f)] + tail).join(sep)
|
([emit_z(sign * hh, 2, f)] + tail).join(sep)
|
||||||
when '%'; emit_a('%', 0, f)
|
when '%'; emit_a('%', 0, f)
|
||||||
when '+'; emit_a(strftime('%a %b %e %H:%M:%S %Z %Y'), 0, f)
|
when '+'; emit_a(strftime('%a %b %e %H:%M:%S %Z %Y'), 0, f)
|
||||||
when '1'
|
|
||||||
if $VERBOSE
|
|
||||||
warn("warning: strftime: %1 is deprecated; forget this")
|
|
||||||
end
|
|
||||||
emit_n(jd, 1, f)
|
|
||||||
when '2'
|
|
||||||
if $VERBOSE
|
|
||||||
warn("warning: strftime: %2 is deprecated; use '%Y-%j'")
|
|
||||||
end
|
|
||||||
emit_a(strftime('%Y-%j'), 0, f)
|
|
||||||
when '3'
|
|
||||||
if $VERBOSE
|
|
||||||
warn("warning: strftime: %3 is deprecated; use '%F'")
|
|
||||||
end
|
|
||||||
emit_a(strftime('%F'), 0, f)
|
|
||||||
else
|
else
|
||||||
c
|
c
|
||||||
end
|
end
|
||||||
|
@ -337,7 +322,6 @@ class Date
|
||||||
|
|
||||||
alias_method :ctime, :asctime
|
alias_method :ctime, :asctime
|
||||||
|
|
||||||
=begin
|
|
||||||
def iso8601() strftime('%F') end
|
def iso8601() strftime('%F') end
|
||||||
|
|
||||||
def rfc3339() iso8601 end
|
def rfc3339() iso8601 end
|
||||||
|
@ -364,6 +348,7 @@ class Date
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
=begin
|
||||||
def beat(n=0)
|
def beat(n=0)
|
||||||
i, f = (new_offset(1.to_r/24).day_fraction * 1000).divmod(1)
|
i, f = (new_offset(1.to_r/24).day_fraction * 1000).divmod(1)
|
||||||
('@%03d' % i) +
|
('@%03d' % i) +
|
||||||
|
@ -545,23 +530,6 @@ class Date
|
||||||
return unless str.sub!(/\A%/, '')
|
return unless str.sub!(/\A%/, '')
|
||||||
when '+'
|
when '+'
|
||||||
return unless _strptime_i(str, '%a %b %e %H:%M:%S %Z %Y', e)
|
return unless _strptime_i(str, '%a %b %e %H:%M:%S %Z %Y', e)
|
||||||
when '1'
|
|
||||||
if $VERBOSE
|
|
||||||
warn("warning: strptime: %1 is deprecated; forget this")
|
|
||||||
end
|
|
||||||
return unless str.sub!(/\A(\d+)/, '')
|
|
||||||
val = $1.to_i
|
|
||||||
e.jd = val
|
|
||||||
when '2'
|
|
||||||
if $VERBOSE
|
|
||||||
warn("warning: strptime: %2 is deprecated; use '%Y-%j'")
|
|
||||||
end
|
|
||||||
return unless _strptime_i(str, '%Y-%j', e)
|
|
||||||
when '3'
|
|
||||||
if $VERBOSE
|
|
||||||
warn("warning: strptime: %3 is deprecated; use '%F'")
|
|
||||||
end
|
|
||||||
return unless _strptime_i(str, '%F', e)
|
|
||||||
else
|
else
|
||||||
return unless str.sub!(Regexp.new('\\A' + Regexp.quote(s)), '')
|
return unless str.sub!(Regexp.new('\\A' + Regexp.quote(s)), '')
|
||||||
end
|
end
|
||||||
|
@ -1015,7 +983,11 @@ class Date
|
||||||
e.to_hash
|
e.to_hash
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.zone_to_diff(zone) # :nodoc:
|
t = Module.new do
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def zone_to_diff(zone) # :nodoc:
|
||||||
zone = zone.downcase
|
zone = zone.downcase
|
||||||
if zone.sub!(/\s+(standard|daylight)\s+time\z/, '')
|
if zone.sub!(/\s+(standard|daylight)\s+time\z/, '')
|
||||||
dst = $1 == 'daylight'
|
dst = $1 == 'daylight'
|
||||||
|
@ -1051,6 +1023,11 @@ class Date
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
extend t
|
||||||
|
include t
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
class DateTime < Date
|
class DateTime < Date
|
||||||
|
|
||||||
def strftime(fmt='%FT%T%:z')
|
def strftime(fmt='%FT%T%:z')
|
||||||
|
@ -1061,13 +1038,12 @@ class DateTime < Date
|
||||||
super(str, fmt)
|
super(str, fmt)
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
|
||||||
def iso8601_timediv(n) # :nodoc:
|
def iso8601_timediv(n) # :nodoc:
|
||||||
strftime('T%T' +
|
strftime('T%T' +
|
||||||
if n < 1
|
if n < 1
|
||||||
''
|
''
|
||||||
else
|
else
|
||||||
'.%0*d' % [n, (sec_fraction / (1.to_r/86400/(10**n))).round]
|
'.%0*d' % [n, (sec_fraction / (1.to_r/(10**n))).round]
|
||||||
end +
|
end +
|
||||||
'%:z')
|
'%:z')
|
||||||
end
|
end
|
||||||
|
@ -1081,6 +1057,5 @@ class DateTime < Date
|
||||||
def jisx0301(n=0)
|
def jisx0301(n=0)
|
||||||
super() + iso8601_timediv(n)
|
super() + iso8601_timediv(n)
|
||||||
end
|
end
|
||||||
=end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue