Skip to content

Commit

Permalink
Shoud use nsec in substitution for subsec. Merged with Ruby 1.9.
Browse files Browse the repository at this point in the history
 - Fixed the #926, #927

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4571 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
Watson1978 committed Oct 4, 2010
1 parent 5ecbe73 commit 3a63f4b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/date.rb
Expand Up @@ -1787,7 +1787,7 @@ def to_date
def to_datetime
jd = DateTime.__send__(:civil_to_jd, year, mon, mday, DateTime::ITALY)
fr = DateTime.__send__(:time_to_day_fraction, hour, min, [sec, 59].min) +
Rational(subsec, 86400)
Rational(nsec, 86400_000_000_000)
of = Rational(utc_offset, 86400)
DateTime.new!(DateTime.__send__(:jd_to_ajd, jd, fr, of),
of, DateTime::ITALY)
Expand Down Expand Up @@ -1817,7 +1817,7 @@ def self.now(sg=ITALY)
t = Time.now
jd = civil_to_jd(t.year, t.mon, t.mday, sg)
fr = time_to_day_fraction(t.hour, t.min, [t.sec, 59].min) +
Rational(t.subsec, 86400)
Rational(t.nsec, 86400_000_000_000)
of = Rational(t.utc_offset, 86400)
new!(jd_to_ajd(jd, fr, of), of, sg)
end
Expand Down
8 changes: 5 additions & 3 deletions lib/time.rb
Expand Up @@ -513,12 +513,14 @@ def httpdate
# require 'time'
#
def xmlschema(fraction_digits=0)
sprintf('%0*d-%02d-%02dT%02d:%02d:%02d',
year < 0 ? 5 : 4, year, mon, day, hour, min, sec) +
sprintf('%d-%02d-%02dT%02d:%02d:%02d',
year, mon, day, hour, min, sec) +
if fraction_digits == 0
''
elsif fraction_digits <= 9
'.' + sprintf('%09d', nsec)[0, fraction_digits]
else
'.' + sprintf('%0*d', fraction_digits, (subsec * 10**fraction_digits).floor)
'.' + sprintf('%09d', nsec) + '0' * (fraction_digits - 9)
end +
if utc?
'Z'
Expand Down

0 comments on commit 3a63f4b

Please sign in to comment.