* lib/date.rb, lib/date/format.rb: tuning for performance.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15001 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a615bbf40b
commit
ea78055b08
@ -1,3 +1,7 @@
|
|||||||
|
Sat Jan 12 12:01:49 2008 Tadayoshi Funaba <tadf@dotrb.org>
|
||||||
|
|
||||||
|
* lib/date.rb, lib/date/format.rb: tuning for performance.
|
||||||
|
|
||||||
Sat Jan 12 11:29:45 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sat Jan 12 11:29:45 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* bootstraptest/test_proc.rb: fixed wrong expected result. pointed
|
* bootstraptest/test_proc.rb: fixed wrong expected result. pointed
|
||||||
|
25
lib/date.rb
25
lib/date.rb
@ -6,7 +6,7 @@
|
|||||||
# Documentation: William Webber <william@williamwebber.com>
|
# Documentation: William Webber <william@williamwebber.com>
|
||||||
#
|
#
|
||||||
#--
|
#--
|
||||||
# $Id: date.rb,v 2.35 2008-01-06 08:42:17+09 tadf Exp $
|
# $Id: date.rb,v 2.36 2008-01-12 10:54:29+09 tadf Exp $
|
||||||
#++
|
#++
|
||||||
#
|
#
|
||||||
# == Overview
|
# == Overview
|
||||||
@ -516,9 +516,9 @@ class Date
|
|||||||
# Convert a fractional day +fr+ to [hours, minutes, seconds,
|
# Convert a fractional day +fr+ to [hours, minutes, seconds,
|
||||||
# fraction_of_a_second]
|
# fraction_of_a_second]
|
||||||
def day_fraction_to_time(fr) # :nodoc:
|
def day_fraction_to_time(fr) # :nodoc:
|
||||||
h, fr = fr.divmod(HOURS_IN_DAY)
|
ss, fr = fr.divmod(SECONDS_IN_DAY) # 4p
|
||||||
min, fr = fr.divmod(MINUTES_IN_DAY)
|
h, ss = ss.divmod(3600)
|
||||||
s, fr = fr.divmod(SECONDS_IN_DAY)
|
min, s = ss.divmod(60)
|
||||||
return h, min, s, fr * 86400
|
return h, min, s, fr * 86400
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -527,14 +527,18 @@ class Date
|
|||||||
begin
|
begin
|
||||||
Rational(Rational(1, 2), 2) # a challenge
|
Rational(Rational(1, 2), 2) # a challenge
|
||||||
|
|
||||||
def time_to_day_fraction(h, min, s) # :nodoc:
|
def time_to_day_fraction(h, min, s)
|
||||||
Rational(h, 24) + Rational(min, 1440) + Rational(s, 86400)
|
Rational(h * 3600 + min * 60 + s, 86400) # 4p
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
def time_to_day_fraction(h, min, s) # :nodoc:
|
def time_to_day_fraction(h, min, s)
|
||||||
|
if Integer === h && Integer === min && Integer === s
|
||||||
|
Rational(h * 3600 + min * 60 + s, 86400) # 4p
|
||||||
|
else
|
||||||
h.to_r/24 + min.to_r/1440 + s.to_r/86400
|
h.to_r/24 + min.to_r/1440 + s.to_r/86400
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Convert an Astronomical Modified Julian Day Number to an
|
# Convert an Astronomical Modified Julian Day Number to an
|
||||||
# Astronomical Julian Day Number.
|
# Astronomical Julian Day Number.
|
||||||
@ -1469,7 +1473,7 @@ class Date
|
|||||||
# Return the date as a human-readable string.
|
# Return the date as a human-readable string.
|
||||||
#
|
#
|
||||||
# The format used is YYYY-MM-DD.
|
# The format used is YYYY-MM-DD.
|
||||||
def to_s() strftime end
|
def to_s() format('%.4d-%02d-%02d', year, mon, mday) end # 4p
|
||||||
|
|
||||||
# Dump to Marshal format.
|
# Dump to Marshal format.
|
||||||
def marshal_dump() [@ajd, @of, @sg] end
|
def marshal_dump() [@ajd, @of, @sg] end
|
||||||
@ -1745,6 +1749,11 @@ class DateTime < Date
|
|||||||
public :hour, :min, :sec, :sec_fraction, :zone, :offset, :new_offset,
|
public :hour, :min, :sec, :sec_fraction, :zone, :offset, :new_offset,
|
||||||
:minute, :second, :second_fraction
|
:minute, :second, :second_fraction
|
||||||
|
|
||||||
|
def to_s # 4p
|
||||||
|
format('%.4d-%02d-%02dT%02d:%02d:%02d%s',
|
||||||
|
year, mon, mday, hour, min, sec, zone)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class Time
|
class Time
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# format.rb: Written by Tadayoshi Funaba 1999-2008
|
# format.rb: Written by Tadayoshi Funaba 1999-2008
|
||||||
# $Id: format.rb,v 2.41 2008-01-06 08:42:17+09 tadf Exp $
|
# $Id: format.rb,v 2.42 2008-01-12 10:54:29+09 tadf Exp $
|
||||||
|
|
||||||
require 'rational'
|
require 'rational'
|
||||||
|
|
||||||
@ -297,9 +297,9 @@ class Date
|
|||||||
t = $1.size
|
t = $1.size
|
||||||
sign = if offset < 0 then -1 else +1 end
|
sign = if offset < 0 then -1 else +1 end
|
||||||
fr = offset.abs
|
fr = offset.abs
|
||||||
hh, fr = fr.divmod(HOURS_IN_DAY)
|
ss = fr.div(SECONDS_IN_DAY) # 4p
|
||||||
mm, fr = fr.divmod(MINUTES_IN_DAY)
|
hh, ss = ss.divmod(3600)
|
||||||
ss, fr = fr.divmod(SECONDS_IN_DAY)
|
mm, ss = ss.divmod(60)
|
||||||
if t == 3
|
if t == 3
|
||||||
if ss.nonzero? then t = 2
|
if ss.nonzero? then t = 2
|
||||||
elsif mm.nonzero? then t = 1
|
elsif mm.nonzero? then t = 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user