summaryrefslogtreecommitdiff
path: root/lib/date
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-03-20 00:56:08 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-03-20 00:56:08 +0000
commit87f9d9e0c1f780d9cf7808d5b5af2f44234c30db (patch)
treea8ceb224eac27c30f12d0915c822daaaef34a944 /lib/date
parent55a14a81169e22d220ff10cc68c4621b7e956a88 (diff)
synchronized with date2 3.6.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@5981 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/date')
-rw-r--r--lib/date/format.rb38
1 files changed, 30 insertions, 8 deletions
diff --git a/lib/date/format.rb b/lib/date/format.rb
index d3d8d17511..e8e54e7894 100644
--- a/lib/date/format.rb
+++ b/lib/date/format.rb
@@ -1,5 +1,7 @@
# format.rb: Written by Tadayoshi Funaba 1999-2004
-# $Id: format.rb,v 2.12 2004-01-19 05:43:28+09 tadf Exp $
+# $Id: format.rb,v 2.13 2004-03-20 08:05:13+09 tadf Exp $
+
+require 'rational'
class Date
@@ -182,6 +184,12 @@ class Date
return unless str.sub!(/\A%/o, '')
when '%+'
return unless __strptime(str, '%a %b %e %H:%M:%S %Z %Y', elem)
+=begin
+ when '%.'
+ return unless str.sub!(/\A(\d+)/o, '')
+ val = $1.to_i.to_r / (10**$1.size)
+ elem[:sec_fraction] = val
+=end
when '%1'
return unless str.sub!(/\A(\d+)/o, '')
val = $1.to_i
@@ -227,7 +235,7 @@ class Date
def self._parse(str, comp=false)
str = str.dup
- str.gsub!(/[^-+.\/:0-9a-z]+/ino, ' ')
+ str.gsub!(/[^-+,.\/:0-9a-z]+/ino, ' ')
# day
if str.sub!(/(#{PARSE_DAYPAT})\S*/ino, ' ')
@@ -236,7 +244,10 @@ class Date
# time
if str.sub!(
- /(\d+):(\d+)(?::(\d+))?
+ /(\d+):(\d+)
+ (?:
+ :(\d+)(?:[,.](\d*))?
+ )?
(?:
\s*
([ap])(?:m\b|\.m\.)
@@ -254,15 +265,18 @@ class Date
hour = $1.to_i
min = $2.to_i
sec = $3.to_i if $3
-
if $4
+ sec_fraction = $4.to_i.to_r / (10**$4.size)
+ end
+
+ if $5
hour %= 12
- if $4.downcase == 'p'
+ if $5.downcase == 'p'
hour += 12
end
end
- zone = $5
+ zone = $6
end
# eu
@@ -368,7 +382,7 @@ class Date
\s*
T?
\s*
- (\d{2,6})
+ (\d{2,6})(?:[,.](\d*))?
)?
(?:
\s*
@@ -406,7 +420,10 @@ class Date
sec = $3[ 4, 2].to_i if $3.size >= 6
end
end
- zone = $4
+ if $4
+ sec_fraction = $4.to_i.to_r / (10**$4.size)
+ end
+ zone = $5
end
if str.sub!(/\b(bc\b|bce\b|b\.c\.|b\.c\.e\.)/ino, ' ')
@@ -432,6 +449,7 @@ class Date
elem[:hour] = hour if hour
elem[:min] = min if min
elem[:sec] = sec if sec
+ elem[:sec_fraction] = sec_fraction if sec_fraction
elem[:zone] = zone if zone
offset = zone_to_diff(zone) if zone
elem[:offset] = offset if offset
@@ -511,6 +529,10 @@ class Date
o << '%02d' % mm
when '%%'; o << '%'
when '%+'; o << strftime('%a %b %e %H:%M:%S %Z %Y') # TZ
+=begin
+ when '%.'
+ o << '%06d' % (sec_fraction / (1.to_r/86400/(10**6)))
+=end
when '%1'; o << '%d' % jd
when '%2'; o << strftime('%Y-%j')
when '%3'; o << strftime('%Y-%m-%d')