* fraction -> subsecond
for consistency with method name
* The sentence,
"A non-portable feature allows the offset to be negative on some systems.",
is removed.
Time before 1970 should work portably now.
If localtime() doesn't work before 1970,
Ruby should extrapolate it.
* Time::new -> Time.new
"::" for method call is not common notation now.
* Time#to_i truncates subsecond
* Time#to_f approximates a value in Time object
* Time#to_r
The sentence,
"You can use this method to convert _time_ to another Epoch.",
is removed.
It is not clear because no actual example of "another Epoch" is given.
* Time#usec truncates fraction of microseconds.
* Time#nsec truncates fraction of nanoseconds.
* describe Time#inspect shows subsecond since Ruby 2.7.0.
Not every compilers understand that rb_raise does not return. When a
function does not end with a return statement, such compilers can issue
warnings. We would better tell them about reachabilities.
Saves comitters' daily life by avoid #include-ing everything from
internal.h to make each file do so instead. This would significantly
speed up incremental builds.
We take the following inclusion order in this changeset:
1. "ruby/config.h", where _GNU_SOURCE is defined (must be the very
first thing among everything).
2. RUBY_EXTCONF_H if any.
3. Standard C headers, sorted alphabetically.
4. Other system headers, maybe guarded by #ifdef
5. Everything else, sorted alphabetically.
Exceptions are those win32-related headers, which tend not be self-
containing (headers have inclusion order dependencies).
`find_time_t` did not work correctly for year older than the Epoch
because it used C's integer division (which rounds negative to zero).
For example, `TIme.new(1933)` returned a wrong time whose year is 1922
in Asia/Kuala_Lumpur because there is no 00:00:00 1st Jan. 1933 in the
time zone.
```
$ TZ=Asia/Kuala_Lumpur ruby -e 'p Time.new(1933)'
1932-12-31 00:00:00 +0700
```
This change fixes the issue by using `DIV` macro instead of `/`.
Now `Time.new(1933)` returns a time in 1933.
```
$ TZ=Asia/Kuala_Lumpur ruby -e 'p Time.new(1933)'
1933-01-01 00:20:00 +0720
```
[Bug #16159]
Akatsuki reported ENV['TZ'] = 'UTC' improved 7x-8x faster on following code.
t = Time.now; 100000.times { Time.new(2019) }; Time.now - t
https://hackerslab.aktsk.jp/2019/12/01/141551
commit 4bc1669127(reduce tzset) dramatically improved this situation. But still,
TZ=UTC is faster than default.
This patch removs unnecessary tzset() call completely.
Performance check
----------------------
test program: t = Time.now; 100000.times { Time.new(2019) }; Time.now - t
before: 0.387sec
before(w/ TZ): 0.197sec
after: 0.162sec
after(w/ TZ): 0.165sec
OK. Now, Time creation 2x faster *and* TZ=UTC doesn't improve anything.
We can forget this hack completely. :)
Side note:
This patch slightly changes Time.new(t) behavior implicitly. Before this patch, it might changes
default timezone implicitly. But after this patch, it doesn't. You need to reset TZ
(I mean ENV['TZ'] = nil) explicitly.
But I don't think this is big impact. Don't try to change /etc/localtime on runtime.
Side note2: following test might be useful for testing "ENV['TZ'] = nil".
-----------------------------------------
% cat <<'End' | sudo sh -s
rm -f /etc/localtime-; cp -a /etc/localtime /etc/localtime-
rm /etc/localtime; ln -s /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
./ruby -e '
p Time.new(2000).zone # JST
File.unlink("/etc/localtime"); File.symlink("/usr/share/zoneinfo/America/Los_Angeles", "/etc/localtime")
p Time.new(2000).zone # JST (ruby does not follow /etc/localtime modification automatically)
ENV["TZ"] = nil
p Time.new(2000).zone # PST (ruby detect /etc/localtime modification)
'
rm /etc/localtime; cp -a /etc/localtime- /etc/localtime; rm /etc/localtime-
End
This removes the related tests, and puts the related specs behind
version guards. This affects all code in lib, including some
libraries that may want to support older versions of Ruby.
WIDEVALUE differs from VALUE in 32bit platform, but some codes assume
that they are the same.
There is `#define STRUCT_WIDEVAL` mode to check the consistency.
This change allows to build with STRUCT_WIDEVAL.
Addrinfo.getaddrinfo and .foreach now accepts :timeout in seconds as
a keyword argument. If getaddrinfo_a(3) is available, the timeout will be
applied for name resolution. Otherwise, it will be ignored.
Socket.tcp accepts :resolv_timeout to use this feature.
This commit is retry of 6382f5cc91.
Test was failed on Solaris machines which don't have "http" in
/etc/services. In this commit, use "ssh" instead.
Addrinfo.getaddrinfo and .foreach now accepts :timeout in seconds as
a keyword argument. If getaddrinfo_a(3) is available, the timeout will be
applied for name resolution. Otherwise, it will be ignored.
Socket.tcp accepts :resolv_timeout to use this feature.
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct. This commit deletes ANYARGS from
rb_rescue / rb_rescue2, which revealed many arity / type mismatches.
Build dumped string from base packed data and extended year at
once. Although currently ruby_marshal_write_long() never writes
more than 5 bytes per its format specification, allocate
`sizeof(long)+1` for the sanitation.
* time.c (time_s_now): added in: option to Time.now as well as
Time.at.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67613 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* time.c (vtm_add_offset): separate sign argument to get rid of
repeated negations.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66804 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* time.c (vtm_add_offset): just add offset to other components
only. removed subtraction of utc_offset as it is overwritten
always immediately in callers.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66803 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* time.c (time_set_utc_offset): reset zone when setting to fixoff
mode. while previously TZMODE_SET_FIXOFF has reset it always,
the zone is kept for loaded zone since r65025.
[ruby-core:90627] [Bug #15439]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66520 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* time.c (time_timespec): range check is only for time interval
value if time_t is signed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* time.c (time_timespec): Time interval value can be zero, not
only positive. [ruby-dev:50709] [Bug #15420]
From: shuujii (Shuji KOBAYASHI) <shuujii@gmail.com>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66418 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* time.c: [DOC] fix typos, drop unnecessary `p' from code examples,
add missing `#' for return values, other small improvements.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66389 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Especially over checking argc then calling rb_scan_args just to
raise an ArgumentError.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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/trunk@65974 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* 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
* 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
* 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
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
* 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
* 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
* 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
* 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
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
* 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
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
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
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
* 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
* 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
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
* time.c (divv): add suffix to get rid of the name in C standard
library, and others together.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58312 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Time#to_i will be faster around 80% (on 64-bit platforms).
* Before
user system total real
2.840000 0.000000 2.840000 ( 2.847238)
* After
user system total real
1.600000 0.000000 1.600000 ( 1.598911)
* Test code
require 'benchmark'
Benchmark.bmbm do |x|
x.report do
t = Time.now
20000000.times do
t.to_i
end
end
end
* time.c (_div): new function avoid rb_funcall
(div): replace with new _div function
[ruby-core:80636] [Bug #13418]
Thanks to Watson <watson1978@gmail.com> for the patch.
From: Watson <watson1978@gmail.com>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58308 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
strftime format strings which are dynamically-generated will benefit
from avoiding garbage, here.
* time.c (time_strftime): use rb_str_tmp_frozen_{acquire,release}
* test/ruby/test_time.rb (test_strftime_no_hidden_garbage): new test
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57476 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* time.c (usec2subsecx): fix return type, which is a numeric
object but not a long int. [ruby-dev:49912] [Bug #13066]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57172 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* time.c (time_arg): dump sec and subsec arguments if subsecx is
insane.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57157 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* time.c (num_exact): show the original argument when conversion
failed, instead of intermediate nil.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57140 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* time.c (time_timespec): use RB_TYPE_P instead of switching by
TYPE.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57139 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* time.c (validate_vtm): separate validation failure messages for
each members.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57115 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* time.c (vtm_add_offset): Fix yday on last day of year.
[ruby-core:72878] [Bug #11994] Fixed by Andrew White.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56599 b2dd03c8-39d4-4d8f-98ff-823fe69b080e