Unverified Commit f8ab3c1e authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #3932 from ken-mu/timegm

mruby-time: Fix mruby specific timegm() cannot return minus
parents e5fb21b6 d398cd47
...@@ -138,8 +138,14 @@ timegm(struct tm *tm) ...@@ -138,8 +138,14 @@ timegm(struct tm *tm)
int i; int i;
unsigned int *nday = (unsigned int*) ndays[is_leapyear(tm->tm_year+1900)]; unsigned int *nday = (unsigned int*) ndays[is_leapyear(tm->tm_year+1900)];
for (i = 70; i < tm->tm_year; ++i) static const int epoch_year = 70;
if(tm->tm_year >= epoch_year) {
for (i = epoch_year; i < tm->tm_year; ++i)
r += is_leapyear(i+1900) ? 366*24*60*60 : 365*24*60*60; r += is_leapyear(i+1900) ? 366*24*60*60 : 365*24*60*60;
} else {
for (i = tm->tm_year; i < epoch_year; ++i)
r -= is_leapyear(i+1900) ? 366*24*60*60 : 365*24*60*60;
}
for (i = 0; i < tm->tm_mon; ++i) for (i = 0; i < tm->tm_mon; ++i)
r += nday[i] * 24 * 60 * 60; r += nday[i] * 24 * 60 * 60;
r += (tm->tm_mday - 1) * 24 * 60 * 60; r += (tm->tm_mday - 1) * 24 * 60 * 60;
......
...@@ -226,3 +226,11 @@ assert('2000 times 500us make a second') do ...@@ -226,3 +226,11 @@ assert('2000 times 500us make a second') do
end end
t.usec == 0 t.usec == 0
end end
assert('Time.new with Dec 31 23:59:59 1969 raise ArgumentError') do
assert_raise(ArgumentError) {Time.new(1969, 12, 31, 23, 59, 59)}
end
assert('Time.gm with Dec 31 23:59:59 1969 raise ArgumentError') do
assert_raise(ArgumentError) {Time.gm(1969, 12, 31, 23, 59, 59)}
end
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment