summaryrefslogtreecommitdiff
path: root/time.c
AgeCommit message (Collapse)Author
2018-11-04Hide Time::TM as Time::tmnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65526 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-29time.c: [DOC] fix method names to refer class methods [ci skip]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65428 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-28time.c: added Time::TM#+ and Time::TM#-nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-28time.c: ignore 7th argnobu
* time.c (tm_initialize): allow 7th argument as well as Time#initialize, but just ignore. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65420 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-28time.c: [DOC] add description and fix markups [ci skip]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65419 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-28time.c: [DOC] fix rdoc-ref [ci skip]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65413 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-28time.c: [DOC] about timezone arguemnt [ci skip]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65406 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-25time.c: benchmark recoverynobu
* time.c (time_localtime): check if `vtm.zone` is a simple zone name string before trying to call the conversion method. since r64952, `Time.getlocal` on UTC time has lost the performance about 45%, due to this call. the performance is about 90% of r64951 by avoiding it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65360 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-23Let Time::TM share the implementation with Timenobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65321 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-22No longer subsec and isdst membersnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65307 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-22Revert TM_IS_TIME to 1nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65306 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-22Return fixed values at subsec, utc_offset, and isdstnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65305 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-22time.c: optional arguments of Time::TM#initializenobu
* time.c (tm_initialize): arguments other than year are optional now as Time.new. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65296 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-13Prefer `rb_fstring_lit` over `rb_fstring_cstr`nobu
The former states explicitly that the argument must be a literal, and can optimize away `strlen` on all compilers. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-12Fix overwritten zone stringnobu
* time.c (zone_str): while rb_fstring_usascii and the family require that the argument string is never modified, tzname may point areas which will be discarded by calling tzset(). make a String then call rb_fstring to copy the zone name. when an ID equals TZ environment variable, its name string also has modified by changing tzname. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65035 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-12Initialize zonenobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65026 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-12Load as FIXOFF mode if zone is presentnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-12Just copy tzmodenobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-08Timezone at Time#+ and Time#-nobu
* time.c (time_add): support for Timezone. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64958 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-08* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64953 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-08Timezone support by Time [Feature #14850]nobu
* strftime.c (rb_strftime): support timezone object by `%z`. * time.c (time_init_1, time_new_timew, time_getlocaltime): accept timezone object as `off`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-27Fix messages for too small yearnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64866 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-12time.c split time_utc_or_localnobu
* time.c (time_utc_or_local): split into time_s_mkutc and time_s_mktime without utc flag. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-21rename an argument of calc_wday.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64494 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-15gmtimew_noleapsecond uses tables for mon and mday.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64380 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-12timegm_noleapsecond uses calc_tm_yday.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64327 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-08rename several internal macros in time.cakr
TIME_UTC_P -> TZMODE_UTC_P TIME_SET_UTC -> TZMODE_SET_UTC TIME_LOCALTIME_P -> TZMODE_LOCALTIME_P TIME_SET_LOCALTIME -> TZMODE_SET_LOCALTIME TIME_FIXOFF_P -> TZMODE_FIXOFF_P TIME_SET_FIXOFF -> TZMODE_SET_FIXOFF TIME_COPY_GMT -> TZMODE_COPY git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64230 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-08Update comment of tzmode [ci skip]kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64229 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-08Rename gmt field to tzmode in struct time_object.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64228 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-08Store String as zone in struct vtm.akr
This removes zone_table and use fstring instead. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64227 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-19renamed ruby_tz_update as ruby_tz_uptodate_pnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-18reduce tzsetnobu
* time.c (rb_localtime_r): call tzset() only after TZ environment variable is changed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-06Prefixed reset_leap_second_infonobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63864 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-05Re-apply r63848 (Optimize Time.utc)naruse
* 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
2018-07-04Revert "Optimize Time.utc"naruse
This reverts commit r63848. It breaks tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63849 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-04Optimize Time.utcnaruse
Time.utc uses timegmw() and it uses leap second information. If the given time is larger than known_leap_seconds_limit, it calls find_time_t, which uses localtime(3) and calls stat(2) in it. This patch avoid it by setting known_leap_seconds_limit to 0 if the timezone doesn't have leapsecond information (if no leap second is found "now", I assume the timezone doesn't have leapsecond information). Before: % time ./miniruby --disable-gem -e'time = Time.now; year = time.year; month = time.month; day = time.day; hour = time.hour; min = time.min; sec = time.sec + time.subsec; i = 0; while i < 100000; ::Time.utc(year, month, day, hour, min, sec); i += 1; end' ./miniruby --disable-gem 0.35s user 0.19s system 99% cpu 0.542 total After: % time ./miniruby --disable-gem -e'time = Time.now; year = time.year; month = time.month; day = time.day; hour = time.hour; min = time.min; sec = time.sec + time.subsec; i = 0; while i < 100000; ::Time.utc(year, month, day, hour, min, sec); i += 1; end' ./miniruby --disable-gem 0.23s user 0.00s system 99% cpu 0.233 total git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63848 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-02time.c: [DOC] Time#localtimenobu
* time.c: state that Time#localtime does nothing when nothing changes. [ruby-core:87675] [Bug #14880] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63823 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-22time.c (num_exact): use predefined IDsnormal
No need to waste space on "to_r" and "to_int" which are predefined in defs/id.def git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62006 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-22time.c: constify compat_* tablesnormal
compat_common_month_table and compat_leap_month_table should not be writable. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62005 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-17time.c: use "unsigned int" for bitfieldsnormal
Followup to r61870 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61881 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09internal.h: remove dependecy on ruby/encoding.hnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-02bit-fields other than int is a C99ismshyouhei
To be precise C90 says "A bit-field may have type int, unsigned int, or signed int". It is clear that char or enum are NG. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61554 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-11extern rb_time_utc_offset to get utc offsetnaruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61116 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-25Time#at receives 3rd argument which specifies the unit of 2nd argument ↵naruse
[Feature #13919] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-14time.c (Time#-): Fix documentation.eregon
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59908 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-04time.c: preserve marshalled timezonenobu
* time.c (time_add): preserve timezone name restored by Marshal. [ruby-core:81892] [Bug #13710] * time.c (time_mload): reset localtime if having timezone. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59258 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-27Improve performance of some Time methodswatson1978
internal.h : add rb_numeric_quo() as internal API. rational.c : rename numeric_quo() to rb_numeric_quo() as internal API. time.c (quov): optimize by invoking rb_numeric_quo() to retrieve a value of Numeric#quo instead of method dispatching via rb_funcall(). Time#subsec -> 7 % up Time#- -> 26 % up Time#to_f -> 30 % up Time#to_r -> 7 % up [ruby-core:80915] [Bug #13519] [Fix GH-1601] ### Before Time#subsec 2.024M (± 8.7%) i/s - 10.062M in 5.009762s Time#- 5.049M (± 4.7%) i/s - 25.186M in 5.002379s Time#to_f 5.625M (± 4.2%) i/s - 28.066M in 5.000749s Time#to_r 1.880M (± 9.7%) i/s - 9.361M in 5.027527s ### After Time#subsec 2.155M (± 9.7%) i/s - 10.724M in 5.022579s Time#- 6.362M (± 2.0%) i/s - 31.824M in 5.004625s Time#to_f 7.287M (± 4.8%) i/s - 36.402M in 5.010983s Time#to_r 2.020M (± 9.4%) i/s - 10.059M in 5.021852s ### Test code require 'benchmark/ips' Benchmark.ips do |x| x.report "Time#subsec" do |t| time = Time.now t.times { time.subsec } end x.report "Time#-" do |t| time1 = Time.now time2 = Time.now t.times { time1 - time2 } end x.report "Time#to_f" do |t| time = Time.now t.times { time.to_f } end x.report "Time#to_r" do |t| time = Time.now t.times { time.to_r } end end git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58921 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-21Improve Time#+ & Time#- performancewatson1978
* time.c (wadd): use internal addv() function to calculate internal value in Time object. On 64-bit machine, Time object might have Fixnum object internally by default and addv() can calculate Fixnum objects directly. * time.c (wsub): use internal subv() function due the same reason in above. Time#+ & Time#- will be faster around 15%. [ruby-dev:50036] [Bug #13357] [Fix GH-1547] ### Before user system total real Time#+ 0.820000 0.000000 0.820000 ( 0.818081) Time#- 0.810000 0.000000 0.810000 ( 0.813835) ### After user system total real Time#+ 0.710000 0.000000 0.710000 ( 0.710241) Time#- 0.710000 0.010000 0.720000 ( 0.714151) ### Test code require 'benchmark' Benchmark.bmbm do |x| x.report "Time#+" do t = Time.now 2000000.times do t + 1 end end x.report "Time#-" do t = Time.now 2000000.times do t - 1 end end end git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58829 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-21Improve Time#<=> performancewatson1978
* time.c (wcmp): use internal cmp() function for comparing internal Fixnum value in Time objects. On 64-bit machine, Time object might have Fixnum object internally by default and cmp() can compare the Fixnum objects directly. Time#<=> will be faster around 60% on 64-bit machine. * time.c (cmp): add optimized path for comparing internal Bignum value by using rb_big_cmp() API. On 32-bit machine, Time object might have Bignum object internally by default. Time#<=> will be faster around 50% on 32-bit machine. [ruby-dev:50034] [Bug #13354] [Fix GH-1546] ### Before user system total real Fixnum 1.410000 0.000000 1.410000 ( 1.407848) Bignum 1.550000 0.000000 1.550000 ( 1.549145) ### After user system total real Fixnum 0.880000 0.000000 0.880000 ( 0.886662) Bignum 1.050000 0.000000 1.050000 ( 1.047994) ### Test code require 'benchmark' Benchmark.bmbm do |x| x.report "Fixnum" do t1 = Time.now t2 = Time.now 10000000.times do t1 <=> t2 end end x.report "Bignum" do t1 = Time.at(2 ** 64) t2 = Time.at(2 ** 64 + 1) 10000000.times do t1 <=> t2 end end end git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58828 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-04time.c: avoid taking a pointer to a member of packed structmame
clang 4.0.0 emitted a warning: "taking address of packed member 'subsecx' of class or structure 'vtm' may result in an unaligned pointer value [-Waddress-of-packed-member]". git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e