diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-06-09 13:13:44 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-06-09 13:13:44 +0000 |
commit | 2a1d97cc1fc3699caf2b55943c12c63d5f8e6b6a (patch) | |
tree | e9c2ffd0494aee3e948949bf55662943884db36a | |
parent | b5f7766f72921bfecdd65a2121479943d263f065 (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
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | time.c | 24 |
2 files changed, 23 insertions, 5 deletions
@@ -1,3 +1,7 @@ +Wed Jun 9 22:13:08 2010 Tanaka Akira <akr@fsij.org> + + * time.c (calc_tm_yday): extracted from timegmw_noleapsecond. + Tue Jun 8 06:27:09 2010 Nobuyoshi Nakada <nobu@ruby-lang.org> * gem_prelude.rb: load full rubygems at LoadError for activation @@ -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: |