diff options
author | tadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 14:47:33 +0000 |
---|---|---|
committer | tadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 14:47:33 +0000 |
commit | 98c886aeb2ba211cfe6b3ec114eb53a1e1f73c34 (patch) | |
tree | c673f117dd1563161d6ac666d970bd7b0a112496 /lib | |
parent | fd3d59b8c145bb5ef0a29bd98ebf1e9bffee35d9 (diff) | |
download | ruby-98c886aeb2ba211cfe6b3ec114eb53a1e1f73c34.tar.gz ruby-98c886aeb2ba211cfe6b3ec114eb53a1e1f73c34.tar.xz ruby-98c886aeb2ba211cfe6b3ec114eb53a1e1f73c34.zip |
* lib/date/format.rb(strftime): can print with given arbitrary
precision.
* lib/date/format.rb(strftime): optional flags and filed width
should also affect %[nt].
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@18841 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/date/format.rb | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/date/format.rb b/lib/date/format.rb index 46d2147b8..baba8dcbf 100644 --- a/lib/date/format.rb +++ b/lib/date/format.rb @@ -257,13 +257,17 @@ class Date when 'j'; emit_n(yday, 3, f) when 'k'; emit_a(hour, 2, f) when 'L' - emit_n((sec_fraction / MILLISECONDS_IN_SECOND).floor, 3, f) + w = f[:w] || 3 + u = 10**w + emit_n((sec_fraction * u).floor, w, f) when 'l'; emit_a((hour % 12).nonzero? || 12, 2, f) when 'M', 'OM'; emit_n(min, 2, f) when 'm', 'Om'; emit_n(mon, 2, f) when 'N' - emit_n((sec_fraction / NANOSECONDS_IN_SECOND).floor, 9, f) - when 'n'; "\n" + w = f[:w] || 9 + u = 10**w + emit_n((sec_fraction * u).floor, w, f) + when 'n'; emit_a("\n", 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 'Q' @@ -281,7 +285,7 @@ class Date else emit_a(strftime('%H:%M:%S'), 0, f) end - when 't'; "\t" + when 't'; emit_a("\t", 0, f) when 'U', 'W', 'OU', 'OW' emit_n(if c[-1,1] == 'U' then wnum0 else wnum1 end, 2, f) when 'u', 'Ou'; emit_n(cwday, 1, f) |