Project

General

Profile

Feature #9549 ยป 540.patch

sferik (Erik Michaels-Ober), 02/21/2014 09:05 PM

View differences:

lib/time.rb
# %Z :: Time zone name
# %% :: Literal "%" character
def strptime(date, format, now=self.now)
def strptime(date='-4712-01-01', format='%F', now=self.now)
d = Date._strptime(date, format)
raise ArgumentError, "invalid strptime format - `#{format}'" unless d
if seconds = d[:seconds]
test/test_time.rb
assert_equal(Time.at(1).localtime, Time.strptime("1", "%s"))
assert_equal(false, Time.strptime('0', '%s').utc?)
assert_equal(3600, Time.strptime('0 +0100', '%s %z').utc_offset)
assert_equal(Date.strptime.to_time, Time.strptime)
end
def test_nsec
-
lib/time.rb
# %Z :: Time zone name
# %% :: Literal "%" character
def strptime(date='-4712-01-01', format='%F', now=self.now)
d = Date._strptime(date, format)
raise ArgumentError, "invalid strptime format - `#{format}'" unless d
if seconds = d[:seconds]
if offset = d[:offset]
def strptime(time='-4712-01-01', format='%F', now=self.now)
date = Date.strptime(time, format) # will raise an ArgumentError if the time is invalid
hash = Date._strptime(time, format)
raise ArgumentError, "invalid strptime format - `#{format}'" unless hash
if seconds = hash[:seconds]
if offset = hash[:offset]
Time.at(seconds).localtime(offset)
else
Time.at(seconds)
end
else
year = d[:year]
year = date.year
year = yield(year) if year && block_given?
make_time(year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
make_time(year, date.mon, date.mday, hash[:hour], hash[:min], hash[:sec], hash[:sec_fraction], hash[:zone], now)
end
end
test/test_time.rb
assert_equal(false, Time.strptime('0', '%s').utc?)
assert_equal(3600, Time.strptime('0 +0100', '%s %z').utc_offset)
assert_equal(Date.strptime.to_time, Time.strptime)
assert_raise(ArgumentError) {
Time.strptime('31/2/2014', '%d/%m/%Y')
}
end
def test_nsec
-
lib/time.rb
#
# You must require 'time' to use this method.
#
def parse(date, now=self.now)
def parse(time, now=self.now)
comp = !block_given?
d = Date._parse(date, comp)
if !d[:year] && !d[:mon] && !d[:mday] && !d[:hour] && !d[:min] && !d[:sec] && !d[:sec_fraction]
hash = Date._parse(time, comp)
if !hash[:year] && !hash[:mon] && !hash[:mday] && !hash[:hour] && !hash[:min] && !hash[:sec] && !hash[:sec_fraction]
raise ArgumentError, "no time information in #{date.inspect}"
end
year = d[:year]
year = hash[:year]
year = yield(year) if year && !comp
make_time(year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
make_time(year, hash[:mon], hash[:mday], hash[:hour], hash[:min], hash[:sec], hash[:sec_fraction], hash[:zone], now)
end
#
    (1-1/1)