summaryrefslogtreecommitdiff
path: root/time.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-05 11:43:42 (GMT)
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-05 11:43:42 (GMT)
commit6538f67d4dccc32f1613be188a0748f0d4f90a05 (patch)
tree35bbf3b73137f0400b235a421abbd1e12765ef3b /time.c
parent4c777ac94eaa423969678a09ed5305240219c796 (diff)
Re-apply r63848 (Optimize Time.utc)
* Both timegmw and gmtimew ignores leap second if the timezone doesn't have leap seconds on the first call of init_leap_second_info() * Add Bug::Time.reset_leap_second_info for testing git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63857 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r--time.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/time.c b/time.c
index f48f0e2..20a514e 100644
--- a/time.c
+++ b/time.c
@@ -1098,6 +1098,12 @@ init_leap_second_info(void)
}
}
+/* Use this if you want to re-run init_leap_second_info() */
+void reset_leap_second_info(void)
+{
+ this_year = 0;
+}
+
static wideval_t
timegmw(struct vtm *vtm)
{
@@ -1115,7 +1121,14 @@ timegmw(struct vtm *vtm)
timew = timegmw_noleapsecond(vtm);
- if (wlt(rb_time_magnify(TIMET2WV(known_leap_seconds_limit)), timew)) {
+
+ if (number_of_leap_seconds_known == 0) {
+ /* When init_leap_second_info() is executed, the timezone doesn't have
+ * leap second information. Disable leap second for calculating gmtime.
+ */
+ return timew;
+ }
+ else if (wlt(rb_time_magnify(TIMET2WV(known_leap_seconds_limit)), timew)) {
return wadd(timew, rb_time_magnify(WINT2WV(number_of_leap_seconds_known)));
}
@@ -1148,7 +1161,14 @@ gmtimew(wideval_t timew, struct vtm *result)
init_leap_second_info();
- if (wlt(rb_time_magnify(TIMET2WV(known_leap_seconds_limit)), timew)) {
+ if (number_of_leap_seconds_known == 0) {
+ /* When init_leap_second_info() is executed, the timezone doesn't have
+ * leap second information. Disable leap second for calculating gmtime.
+ */
+ gmtimew_noleapsecond(timew, result);
+ return result;
+ }
+ else if (wlt(rb_time_magnify(TIMET2WV(known_leap_seconds_limit)), timew)) {
timew = wsub(timew, rb_time_magnify(WINT2WV(number_of_leap_seconds_known)));
gmtimew_noleapsecond(timew, result);
return result;