summaryrefslogtreecommitdiff
path: root/time.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-06-09 13:13:44 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-06-09 13:13:44 +0000
commit2a1d97cc1fc3699caf2b55943c12c63d5f8e6b6a (patch)
treee9c2ffd0494aee3e948949bf55662943884db36a /time.c
parentb5f7766f72921bfecdd65a2121479943d263f065 (diff)
* time.c (calc_tm_yday): extracted from timegmw_noleapsecond.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28236 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r--time.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/time.c b/time.c
index 63b52a0726..be398eb96c 100644
--- a/time.c
+++ b/time.c
@@ -30,6 +30,7 @@ static ID id_eq, id_ne, id_quo, id_div, id_cmp, id_lshift;
#define NDIV(x,y) (-(-((x)+1)/(y))-1)
#define NMOD(x,y) ((y)-(-((x)+1)%(y))-1)
#define DIV(n,d) ((n)<0 ? NDIV((n),(d)) : (n)/(d))
+#define MOD(n,d) ((n)<0 ? NMOD((n),(d)) : (n)%(d))
static int
eq(VALUE x, VALUE y)
@@ -933,13 +934,29 @@ static const int leap_year_days_in_month[] = {
31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
+static int
+calc_tm_yday(long tm_year, int tm_mon, int tm_mday)
+{
+ int tm_year_mod400;
+ int tm_yday = tm_mday;
+
+ tm_year_mod400 = MOD(tm_year, 400);
+
+ if (leap_year_p(tm_year_mod400 + 1900))
+ tm_yday += leap_year_yday_offset[tm_mon];
+ else
+ tm_yday += common_year_yday_offset[tm_mon];
+
+ return tm_yday;
+}
+
static wideval_t
timegmw_noleapsecond(struct vtm *vtm)
{
VALUE year1900;
VALUE q400, r400;
int year_mod400;
- int yday = vtm->mday;
+ int yday;
long days_in400;
VALUE vdays, ret;
wideval_t wret;
@@ -949,10 +966,7 @@ timegmw_noleapsecond(struct vtm *vtm)
divmodv(year1900, INT2FIX(400), &q400, &r400);
year_mod400 = NUM2INT(r400);
- if (leap_year_p(year_mod400 + 1900))
- yday += leap_year_yday_offset[vtm->mon-1];
- else
- yday += common_year_yday_offset[vtm->mon-1];
+ yday = calc_tm_yday(year_mod400, vtm->mon-1, vtm->mday);
/*
* `Seconds Since the Epoch' in SUSv3: