summaryrefslogtreecommitdiff
path: root/time.c
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-01-16 15:32:54 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-01-16 15:32:54 +0000
commit11a64cea0a4c5e72611c40fc92fe9ac0889cd662 (patch)
treee53ce6a15fc830025869065541765a19edb5a225 /time.c
parent9ab19d792e8fa412900ad671256ba5ee49730f21 (diff)
merge revision(s) 65974: [Backport #15340]
Normalize month-mday before finding epoch Especially over the year 2038, 30 Feb and so on may cause odd behavior on validating found epoch with given year-month-day [Bug #15340] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@66839 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r--time.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/time.c b/time.c
index 2e77bda630..1967c5d689 100644
--- a/time.c
+++ b/time.c
@@ -2610,6 +2610,29 @@ time_arg(int argc, VALUE *argv, struct vtm *vtm)
vtm->mday = obj2ubits(v[2], 5);
}
+ /* normalize month-mday */
+ switch (vtm->mon) {
+ case 2:
+ {
+ /* this drops higher bits but it's not a problem to calc leap year */
+ unsigned int mday2 = leap_year_v_p(vtm->year) ? 29 : 28;
+ if (vtm->mday > mday2) {
+ vtm->mday -= mday2;
+ vtm->mon++;
+ }
+ }
+ break;
+ case 4:
+ case 6:
+ case 9:
+ case 11:
+ if (vtm->mday == 31) {
+ vtm->mon++;
+ vtm->mday = 1;
+ }
+ break;
+ }
+
vtm->hour = NIL_P(v[3])?0:obj2ubits(v[3], 5);
vtm->min = NIL_P(v[4])?0:obj2ubits(v[4], 6);