Граф коммитов

669 Коммитов

Автор SHA1 Сообщение Дата
Koichi Sasada 2a3d5d661c Use `Primitive.mandatory_only?` for `Time.at` 2021-11-15 15:58:56 +09:00
Nobuyoshi Nakada 8bcff5604b
Tentative fix of subsec to `Time.at` [Bug #18293] 2021-11-10 18:14:14 +09:00
Nobuyoshi Nakada 83bdc2f00c
Simplify default values of `Time.at` [Bug #18293] 2021-11-10 17:42:18 +09:00
Nobuyoshi Nakada 1d666ed50f Fix leap day with UTC offset [Bug #18274]
`struct vtm::year` is a Ruby integer instance, but not a C integer
type.
2021-10-28 14:45:19 +09:00
Nobuyoshi Nakada e057b9eea9
Prefer the reentrant versions of gmtime and localtime 2021-10-14 23:44:15 +09:00
Nobuyoshi Nakada ec4ecb6d6d Include the invalid value in invalid_utc_offset error 2021-09-18 18:03:54 +09:00
S.H 68bd5626c3
Remove unneeded ruby_reset_leap_second_info function declaration (#4824) 2021-09-16 13:21:06 +09:00
S-H-GAMELINKS 032534dbdf Using RB_BIGNUM_TYPE_P macro 2021-09-11 09:13:24 +09:00
卜部昌平 a88bd246ca include/ruby/internal/intern/time.h: add doxygen
Must not be a bad idea to improve documents. [ci skip]
2021-09-10 20:00:06 +09:00
S-H-GAMELINKS bdd6d8746f Replace RBOOL macro 2021-09-05 23:01:27 +09:00
S.H 378e8cdad6
Using RBOOL macro 2021-08-02 12:06:44 +09:00
Nobuyoshi Nakada bf789af28a
Added macros for days in month 2021-06-27 08:37:45 +09:00
Nobuyoshi Nakada 1fd8b6f2b9
Shrink monthly tables 2021-06-27 08:37:42 +09:00
Anton Rieder bce0021f75 [Documentation] Fix typo, formatting in `time.c`
Backticks do not result in code formatting.
2021-06-22 20:51:57 +09:00
Nobuyoshi Nakada bdeaa60e7b
Make frozen Time Ractor-shareable 2021-06-18 11:58:15 +09:00
Yusuke Endoh 688b217706 time.c: Check if defined(RUBY_MSVCRT_VERSION) to build on Solaris
Fixes [Bug #17947]
2021-06-14 10:40:41 +09:00
Nobuyoshi Nakada c741ea0be7
timev.rb: moved class rdoc from time.c 2021-06-07 20:44:05 +09:00
Burdette Lamar 6ee55455a8 Update Time documentation 2021-04-29 19:58:15 -07:00
Nobuyoshi Nakada a5567350f7
Refactored sub-seconds normalizations
* separated argument to `timespec2timew` from `timespec` to seconds and
  nano-seconds.

* unified nano-seconds and micro-seconds normalizations.
2021-04-01 12:00:10 +09:00
Jeremy Evans b51e5c2370 Remove mentions of Bignum in time.c
Move section on internal details out of the class-level documentation,
since users do not need to know that.  Update it to use
Integer(T_BIGNUM) instead of Bignum.

Fixes [Misc #17580]
2021-02-19 08:30:11 -08:00
Nobuyoshi Nakada 296a2cab07 Parse "-00:00" as UTC for the round-trip [Feature #17544] 2021-02-16 20:34:23 +09:00
Nobuyoshi Nakada aea40f44aa
Fixed time_t conversion modifiers for debug 2021-02-11 23:53:29 +09:00
Nobuyoshi Nakada 4b6347ab39 Compile debugging code for time always 2021-02-10 19:45:14 +09:00
Nobuyoshi Nakada ef59a781d7 Fixed the signature of find_time_numguess_getter 2021-02-10 19:45:14 +09:00
Nobuyoshi Nakada 4b15caee8f
Added `in:` timezone option to `Time.new` [Feature #17485] 2021-01-13 18:15:50 +09:00
Nobuyoshi Nakada 9441f3f970 Allow UTC offset without colons per ISO-8601 [Bug #17504] 2021-01-13 16:37:59 +09:00
Nobuyoshi Nakada 1eb8eb55c2
Convert time component strings to integers more strictly
https://bugs.ruby-lang.org/issues/17485#change-89871
2021-01-12 17:24:43 +09:00
Nobuyoshi Nakada b017848f8a
Show seconds of utc_offset if not zero 2021-01-12 17:00:14 +09:00
Nobuyoshi Nakada 18ea81fd2c
get_tmopt is no longer used 2020-12-31 17:25:07 +09:00
Nobuyoshi Nakada 77e7082e82
Moved Time.at to builtin 2020-12-31 17:25:07 +09:00
Nobuyoshi Nakada 9101597d05
Moved Time.now to builtin 2020-12-31 17:25:07 +09:00
Nobuyoshi Nakada 93735f8fc0
Moved time.rb to timev.rb 2020-12-31 17:23:37 +09:00
Nobuyoshi Nakada d5fb51d2d3
Add time.rb as builtin 2020-12-31 15:19:06 +09:00
Nobuyoshi Nakada 7817a438eb Removed deprecated Time#succ 2020-12-07 18:38:59 +09:00
Nobuyoshi Nakada 95bef7b69a Subsecond of Time::tm should be 0 2020-11-28 15:41:41 +09:00
Nobuyoshi Nakada 5a77e90fe8
Use rb_intern_const instead of rb_intern in Init functions
```
find . -name \*.o -exec nm {} + |&
sed '/Init_.*\.rbimpl_id/!d;s/^.* b //;s/\.[1-9][0-9]*$//;s/\.rbimpl_id$//' |
uniq
```
should be empty.
2020-10-21 12:46:53 +09:00
Stefan Stüben 8c2e5bbf58 Don't redefine #rb_intern over and over again 2020-10-21 12:45:18 +09:00
Jeremy Evans 520a734ad9 Fix Time#ceil when result should be the same as the receiver
Fixes [Bug #17025]
2020-07-28 12:53:37 -07:00
Kazuhiro NISHIYAMA 946cd6c534
Use https instead of http 2020-07-28 19:51:54 +09:00
S.H 2735da2039
Fix Time#to_a behavior with timezone [Bug #17046] 2020-07-24 20:17:31 +09:00
Nobuyoshi Nakada caf565f7bf
Ensure time object meets a given condition [Bug #17042] 2020-07-23 11:52:33 +09:00
S.H afacf85e44
Merge pull request #3352 from S-H-GAMELINKS/bug/17042-strftime
Fix Time#strftime with timezone [Bug #17042]
2020-07-23 11:35:20 +09:00
Tanaka Akira 48eb1ad2c3 [DOC] time.c document updated.
* 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.
2020-07-21 20:28:36 +09:00
Nobuyoshi Nakada 99a9c3fe2e
Fixed yday and wday with timezone [Bug #17024] 2020-07-12 21:58:13 +09:00
卜部昌平 da8af471fb find_time_t: reset status before goto 2020-06-29 11:05:41 +09:00
卜部昌平 de3e931df7 add UNREACHABLE_RETURN
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.
2020-06-29 11:05:41 +09:00
卜部昌平 fd0e935886 time_mload: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平 ed6938ef50 indent [ci skip] 2020-06-29 11:05:41 +09:00
卜部昌平 83f6de8691 find_time_t: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平 ce6be8889f utc_offset_arg: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平 1c0a97bfad vtm_add_offset: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平 0fc569361b num_exact: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
Nobuyoshi Nakada ee35a4dad3
Append subsec part instead of creating new string 2020-06-03 19:13:36 +09:00
卜部昌平 9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平 d7f4d732c1 sed -i s|ruby/3|ruby/impl|g
This shall fix compile errors.
2020-05-11 09:24:08 +09:00
卜部昌平 9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
zverok d019cac08a Clarify Time::at documentation for in: argument 2020-03-09 22:28:33 +09:00
प्रथमेश Sonpatki 9a422fc010
Update docs for Time#at method [ci skip]
Add docs about all possible options for the `in` argument.
2020-02-27 11:08:49 +09:00
Tanaka Akira 2dea81f477 Don't refer Date in the document for Time. 2020-02-10 21:41:15 +09:00
卜部昌平 115fec062c more on NULL versus functions.
Function pointers are not void*.  See also
ce4ea956d2
8427fca49b
2020-02-07 14:24:19 +09:00
Tanaka Akira 29e31e72fb ruby_reset_timezone resets leap_second_info.
[Bug #15177]
2020-01-29 00:01:57 +09:00
Tanaka Akira 338c5b8c1d Extract a function, ruby_reset_timezone().
Initial implementation of ruby_reset_timezone()
assigns ruby_tz_uptodate_p to false.
2020-01-28 23:40:25 +09:00
John Hawthorn 91601dcc6a Simplify obj2ubits checks
If this value is less than zero, then the mask check is guaranteed to
fail as well, so we might as well rely on that.
2020-01-13 13:58:23 -08:00
John Hawthorn 5f3189474c Avoid rb_check_string_type in month_arg
This will usually receive a fixnum so we should check that first instead
of the more expensive rb_check_string_type check.
2020-01-13 13:58:23 -08:00
John Hawthorn c2e45422f7 Store "UTC" and "" fstring as globals in time.c 2020-01-13 13:58:23 -08:00
卜部昌平 5e22f873ed decouple internal.h headers
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).
2019-12-26 20:45:12 +09:00
Marcus Stollsteimer ceba5b7088 [DOC] Fix typo in Time#inspect 2019-12-24 21:50:27 +01:00
zverok 4988843188 Actualize Time#inspect docs 2019-12-22 23:17:39 +09:00
Nobuyoshi Nakada db16629008
Fixed misspellings
Fixed misspellings reported at [Bug #16437], only in ruby and rubyspec.
2019-12-20 09:32:42 +09:00
Nobuyoshi Nakada ebe5b66ca8
Reduce tzset calls
Set up-to-date flag always when calling tzset().
2019-12-17 10:48:17 +09:00
Yusuke Endoh d6a2bce64a time.c (find_time_t): fix round-to-zero bug
`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]
2019-12-17 10:36:20 +09:00
KOSAKI Motohiro 7f2cd2ae6f fix typo 2019-12-03 10:50:16 +00:00
KOSAKI Motohiro 4d7a6d04b2 Avoid unnecessary tzset() call
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
2019-12-01 16:34:26 +00:00
Kazuhiro NISHIYAMA 09e76e9828
Improve consistency of bool/true/false 2019-11-25 15:09:09 +09:00
Kazuhiro NISHIYAMA 5c6235a83c
Set TRUE/FALSE to `bool ruby_tz_uptodate_p` instead of 1/FALSE 2019-11-25 12:10:05 +09:00
Jeremy Evans ffd0820ab3 Deprecate taint/trust and related methods, and make the methods no-ops
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.
2019-11-18 01:00:25 +02:00
Nobuyoshi Nakada e7ea6e078f
Check more likely condition first [Feature #16335] 2019-11-13 16:54:31 +09:00
Yusuke Endoh 2409667aa2 time.c: Fix some bugs about WIDEVALUE
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.
2019-10-06 11:39:01 +09:00
NARUSE, Yui cbf405fec4 Specify encoding explicitly for sprintf 2019-09-19 20:45:24 +09:00
NARUSE, Yui 5208c431be Separate Time#inspect from to_s and show subsec [Feature #15958] 2019-09-19 20:20:15 +09:00
Masaki Matsushita 0e9d56f5e7 Support timeout for Addrinfo
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.
2019-09-10 10:10:59 +09:00
Masaki Matsushita c4efbf663e Revert "Support timeout for Addrinfo"
This reverts commit 6382f5cc91.
test failed on Solaris.
2019-09-09 20:34:51 +09:00
Masaki Matsushita 6382f5cc91 Support timeout for Addrinfo
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.
2019-09-09 14:34:05 +09:00
卜部昌平 5c7c2d9951 rb_rescue / rb_rescue2 now free from ANYARGS
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.
2019-08-27 15:52:26 +09:00
Nobuyoshi Nakada 0ed298f382
Refine time_to_r
* time.c (time_to_r): get rid canonicalize and uncanonicalize
  one-denominator rational, by rb_time_unmagnify_to_rational.
2019-08-06 23:39:14 +09:00
Nobuyoshi Nakada 4ea5c5610a
Predefine some IDs 2019-08-03 10:18:39 +09:00
Jeremy Evans 177731aadf Document that Timezone argument for Time uses dst? if available [ci skip] 2019-07-29 11:06:43 -07:00
Nobuyoshi Nakada 149e414ed5
Initialize DST flag
* time.c (zone_timelocal): initialize DST flag by asking the
  timezone object.  [Bug #15988]
2019-07-27 12:41:33 +09:00
Nobuyoshi Nakada f487e5b7a4
Expanded buf to copy at once
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.
2019-07-17 08:34:19 +09:00
Nobuyoshi Nakada ed2f2b4f98
Named the backward compatible dump size 2019-07-17 07:28:17 +09:00
Yusuke Endoh d37da60128 time.c (time_mdump): use another buffer for year_extend
ruby_marshal_write_long may write 9 bytes, but buf has only 8 bytes.
So the buffer cannot be reused.  This issue was found by Coverity Scan.
2019-07-15 06:44:16 +09:00
Yusuke Endoh 219643c075 Add a /* fall through */ comment 2019-07-14 14:28:01 +09:00
Nobuyoshi Nakada e690df1f1e
Marshal distant past/future
[Feature #15160]
2019-06-19 15:26:53 +09:00
Nobuyoshi Nakada 45ad375acc
[DOC] Use Rational literals than to_r in examples 2019-05-24 16:10:10 +09:00
Nobuyoshi Nakada 1a4080cb0a
Hoisted out ndigits_denominator
* time.c (ndigits_denominator): calculate the denominator for
  digits.
2019-05-24 15:16:19 +09:00
git 0b4d51b055 * expand tabs. 2019-05-23 22:39:54 +09:00
manga_osyo f5415a95ce
Add `Time#ceil`.
Closes: https://github.com/ruby/ruby/pull/2133
2019-05-23 22:30:19 +09:00
Marcus Stollsteimer 60de17258b [DOC] Shorten examples for Time#{round,floor} 2019-05-18 13:06:49 +02:00
Marcus Stollsteimer cc0e460bcc [DOC] Improve documentation for Time#floor
Use numbers that are more illustrative for #floor.
2019-05-18 13:06:10 +02:00
Nobuyoshi Nakada b9e52db283
Add a pathologic check 2019-05-04 22:00:22 +09:00