Commit graph

673 commits

Author SHA1 Message Date
nagachika
4ca521e913 merge revision(s) 06919949a6, 51bc992822, 42daa6c2a2: [Backport #21141]
[Bug #21141] [DOC] Clarify what time is in UTC

	[Bug #21141] [DOC] Refine description of `Time#utc?`

	[Bug #21141] [DOC] Fix indentation
2025-04-09 17:27:37 +09:00
nagachika
d213eb7f45 merge revision(s) 3f07bc76ff, 34098b669c: [Backport #21144]
[Bug #21144] Win32: Use Windows time zone ID if TZ is not set

	If the TZ environment variable is not set, the time zone names
	retrieved from the system are localized for UI display and may vary
	across editions and language packs for the same time zone.
	Use the time zone IDs that are invariant across environments instead.

	[Bug #21144] Win32: Convert the time zone name to the current locale

	The Windows time zone IDs provided by Microsoft as of 24H1 are ASCII
	only all, but the API itself is not impossible to set non-ASCII key
	name.  Prefer the current locale encoding for now until we move to
	UTF-8 including environment variables and command line arguments.
2025-03-16 18:46:29 +09:00
Takashi Kokubun
b13cf49036 merge revision(s) 055613fd868a8c94e43893f8c58a00cdd2a81f6d,127d7a35df10ee2bc99f44b888972b2c5361d84f,e2a9b87126d59e4766479a7aa12cf7a648f46506: [Backport #20447]
Fix pointer incompatiblity

	Since the subsecond part is discarded, WIDEVAL to VALUE conversion is
	needed.

	Some functions are not used when `THREAD_MODEL=none`

	`rb_thread_sched_destroy` is not used now at all
2024-05-30 11:13:15 -07:00
NARUSE, Yui
821719a505
merge revision(s) d3279a0c11: [Backport #20327] (#10313)
[Bug #20327] Do not count subsecond to calculate UTC offset

	Assume that there will never be any time zones with UTC offsets that
	are subseconds.  Historically, UTC offset has only been used down to
	the second.
2024-03-21 02:18:06 +00:00
Nobuyoshi Nakada
092a17e7bd
[DOC] Markup class name Time as code 2023-12-02 21:48:00 +09:00
Nobuyoshi Nakada
ae3e9f114c
[DOC] Include timezones document in timev.rb
So that it can be referred as a part of the document of `Time`.
2023-12-02 21:46:52 +09:00
Jean Boussier
b4f551686b Get rid of useless dsize functions
If we always return 0, we might as well not define
the function at all.
2023-11-21 15:15:03 +01:00
Peter Zhu
aa6642de63 Use embedded TypedData for Time objects
This drops the total size of a Time object from 86 bytes to 80 bytes.

Running the benchmark benchmark/time_now.yml, this commit improves
performance of Time.now by about 30%:

```
  Time.now
Branch:  13159405.4 i/s
Master:  10036908.7 i/s - 1.31x  slower

  Time.now(in: "+09:00")
Branch:   2712172.6 i/s
Master:   2138637.9 i/s - 1.27x  slower
```

It also decreases memory usage by about 20%:

```
ary = 10_000_000.times.map { Time.now }

puts `ps -o rss= -p #{$$}`
```

Branch: 961792
Master: 1196544

Co-Authored-By: Jean Boussier <byroot@ruby-lang.org>
2023-11-07 15:48:06 -05:00
haseponpon
089227e948
[DOC] Specify the unit of return value for Time#- 2023-08-16 22:51:17 +09:00
Burdette Lamar
8c5b9ebf71
[DOC] Improve doc guide compliance (#8221) 2023-08-15 14:43:58 -04:00
Jeremy Evans
5d4fff8456 Tighten Time.new(string) parsing
Disallow:

* Only year-month
* Only year-month-day
* Preceding whitespace
* Trailing whitespace

Fixes [Bug #19293]
2023-07-13 16:49:39 -07:00
Nobuyoshi Nakada
b934976024
Prefer 0 over NULL as function pointers
SunC warns use of `NULL`, pointer to data as function pointers.
2023-06-23 03:15:55 +09:00
Peter Zhu
a84c99468f Fix crash in Time on 32-bit systems
[Bug #19575]

struct vtm is packed causing it to have a size that is not aligned on
32-bit systems. When allocating it on the stack, it will have unaligned
addresses which means that the fields won't be marked by the GC when
scanning the stack (since the GC only marks aligned addresses). This can
cause crashes when the fields are heap allocated objects like Bignums.

This commit moves the flags in struct time_object into struct vtm for
space efficiency and removes the need for packing.

This is an example of a crash:

    ruby(rb_print_backtrace+0xd) [0x56848945] ../src/vm_dump.c:785
    ruby(rb_vm_bugreport) ../src/vm_dump.c:1101
    ruby(rb_assert_failure+0x7a) [0x56671857] ../src/error.c:878
    ruby(vm_search_cc+0x0) [0x56666e47] ../src/vm_method.c:1366
    ruby(rb_vm_search_method_slowpath) ../src/vm_insnhelper.c:2090
    ruby(callable_method_entry+0x5) [0x568232d3] ../src/vm_method.c:1406
    ruby(rb_callable_method_entry) ../src/vm_method.c:1413
    ruby(gccct_method_search_slowpath) ../src/vm_eval.c:427
    ruby(gccct_method_search+0x20f) [0x568237ef] ../src/vm_eval.c:476
    ruby(opt_equality_by_mid_slowpath+0x2c) [0x5682388c] ../src/vm_insnhelper.c:2338
    ruby(rb_equal+0x37) [0x566fe577] ../src/object.c:133
    ruby(rb_big_eq+0x34) [0x56876ee4] ../src/bignum.c:5554
    ruby(rb_int_equal+0x14) [0x566f3ed4] ../src/numeric.c:4640
    ruby(rb_int_equal) ../src/numeric.c:4634
    ruby(vm_call0_cfunc_with_frame+0x6d) [0x568303c2] ../src/vm_eval.c:148
    ruby(vm_call0_cfunc) ../src/vm_eval.c:162
    ruby(vm_call0_body) ../src/vm_eval.c:208
    ruby(rb_funcallv_scope+0xd1) [0x56833971] ../src/vm_eval.c:85
    ruby(RB_TEST+0x0) [0x567e8488] ../src/time.c:78
    ruby(eq) ../src/time.c:78
    ruby(small_vtm_sub) ../src/time.c:1523
    ruby(timelocalw+0x23b) [0x567f3e9b] ../src/time.c:1593
    ruby(time_s_alloc+0x0) [0x567f536b] ../src/time.c:3698
    ruby(time_new_timew) ../src/time.c:2694
    ruby(time_s_mktime) ../src/time.c:3698
2023-04-04 11:12:07 -04:00
BurdetteLamar
3b239d2480 Remove (newly unneeded) remarks about aliases 2023-02-19 14:26:34 -08:00
Nobuyoshi Nakada
a56d959ed5
Replace PACKED_STRUCT and PACKED_STRUCT_UNALIGNED 2023-02-08 12:35:27 +09:00
git
23052e005e * remove trailing spaces. [ci skip] 2023-02-07 21:03:20 +00:00
Peter Zhu
1c0127ed5e Make Time objects WB protected
Co-Authored-By: Jean Boussier <byroot@ruby-lang.org>
2023-02-07 16:03:08 -05:00
Peter Zhu
e9090eb64d Remove unused code in time.c
Co-Authored-By: Jean Boussier <byroot@ruby-lang.org>
2023-02-07 16:03:08 -05:00
Nobuyoshi Nakada
5be0d42d2c
[Bug #19296] Precheck bits of time components 2023-01-02 23:29:19 +09:00
Nobuyoshi Nakada
542e984d82
[Bug #19292] Re-initialize tm when wday or yday is not set 2023-01-01 16:39:00 +09:00
Kazuki Tsujimoto
b7bb14b96e
Update documentation about Time#deconstruct_keys 2022-12-22 13:05:09 +09:00
Nobuyoshi Nakada
2b96119fc0 [DOC] fix unintentional verbatim 2022-12-21 09:48:42 +09:00
Nobuyoshi Nakada
d64e10228d
Fix guess_diff type
`unsigned_time_t` has the same size as `time_t`, but it doesn't mean
these types are same except for signedness.  For instance, while
`long` and `long long` has the same size and `time_t` is defined as
the latter on 64bit OpenBSD, `unsigned_time_t` has been defined as
`long`.
2022-12-19 13:14:46 +09:00
Nobuyoshi Nakada
3e49d62bc1 [Feature #18033] Parse more strictly conformant with ISO-8601
* 4-digits or more is required as year
* Minutes and seconds parts are not ommittable
2022-12-16 22:52:59 +09:00
Nobuyoshi Nakada
635fc5f7fc [Feature #18033] Make more conformant with C standard 2022-12-16 22:52:59 +09:00
Nobuyoshi Nakada
9515179d74 [Feature #18033] Add precision: option
Which limits the precision of subsecond. Defaulted to 9, that
means nanosecond.
2022-12-16 22:52:59 +09:00
Nobuyoshi Nakada
67c589afa0 [Feature #18033] More strict checks 2022-12-16 22:52:59 +09:00
Nobuyoshi Nakada
0a2f300a8a [Feature #18033] Name a magic number 2022-12-16 22:52:59 +09:00
Nobuyoshi Nakada
8c272f4481 [Feature #18033] Make Time.new parse time strings
`Time.new` now parses strings such as the result of `Time#inspect`
and restricted ISO-8601 formats.
2022-12-16 22:52:59 +09:00
zverok
eaf2b6c439 Add Time#deconstruct_keys 2022-11-22 23:10:46 +02:00
S-H-GAMELINKS
1f4f6c9832 Using UNDEF_P macro 2022-11-16 18:58:33 +09:00
Nobuyoshi Nakada
5c3dba83fa
Re-order checks for colons in UTC offset 2022-11-15 09:01:29 +09:00
Nobuyoshi Nakada
011d4c57d2
[Bug #19106] Normalize time at 24:00:00 with a timezone object 2022-11-07 15:56:12 +09:00
Nobuyoshi Nakada
1a66d42fca
[DOC] use the local rdoc reference than the external URI 2022-10-11 16:25:09 +09:00
Nobuyoshi Nakada
baf050100d
[DOC] Remove extra page-dir prefix to fix broken link 2022-09-03 23:26:07 +09:00
Burdette Lamar
fe865c5262
[DOC] Enhanced RDoc for Time (#6320)
Treats:
    #yday
    #dst?
    #zone
    #to_a
    #strftime
2022-09-03 08:36:44 -05:00
Burdette Lamar
c8c90e459e
Enhanced RDoc for Tim[DOC] (#6319) 2022-09-02 14:11:53 -05:00
Burdette Lamar
d41be1ac37
[DOC] Enhanced RDoc for Time (#6308)
More on timezones.
2022-08-31 16:36:22 -05:00
Burdette Lamar
aecc3b1252
[DOC] Enhanced RDoc for Time (#6294) 2022-08-28 16:49:51 -05:00
Burdette Lamar
8706b74b90
[DOC] Enhanced RDoc for Time (#6277)
Deletes the :include: files in doc/time, which became no longer workable when @nobu pointed out that some (but not all) creator methods accept string values as well as integer-like values.
Changes to methods:

    Time.utc
    Time.local
    Time.at
    Time.new
2022-08-25 13:02:18 -05:00
Nobuyoshi Nakada
c069f50401
[DOC] Tell RDoc aliases of singleton class
Since RDoc C parser cannot capture aliases which are using an
expression other than a single variable as the class, use an
intermediate variable for the singleton class.
2022-08-26 00:07:19 +09:00
Nobuyoshi Nakada
6465a5331a
[DOC] Remove extra page-dir prefix 2022-08-23 09:04:57 +09:00
Burdette Lamar
b8d142e733
[DOC] Enhanced RDoc for Time (#6267)
Treats:
    #utc
    #getlocal
    #getutc
    #ctime
    #to_s
    #inspect
2022-08-22 11:21:36 -05:00
Nobuyoshi Nakada
f99904341e
[DOC] Remove extra page-dir prefix 2022-08-22 23:15:30 +09:00
Burdette Lamar
936327a519
[DOC] Enhanced RDoc for Time (#6255)
Treats:
    #utc
    #hash
    #localtime
2022-08-21 11:36:36 -05:00
Takashi Kokubun
5b21e94beb Expand tabs [ci skip]
[Misc #18891]
2022-07-21 09:42:04 -07:00
Nobuyoshi Nakada
68903df6f6
[Bug #18922] Normalize time at 24:00:00 UTC 2022-07-18 00:59:27 +09:00
Burdette Lamar
8309b1366c
[DOC] Enhanced RDoc for Time (#6118)
Treats:
    ::utc
    ::local
    #to_i
    #to_f
    #to_r
    #usec
    #nsec
    #subsec
    #<=>
    #eql?
2022-07-12 13:21:32 -05:00
S-H-GAMELINKS
46cf3bf333 Using TZMODE_SET_LOCALTIME macro 2022-05-26 19:55:05 +09:00
S-H-GAMELINKS
5b467400d2 [DOC]Some link prefix replace 2022-04-09 17:43:46 +09:00