rbs 3.0.0.dev.2 → 3.0.0.dev.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +2 -1
  3. data/.github/workflows/ruby.yml +4 -0
  4. data/Gemfile.lock +11 -11
  5. data/Rakefile +2 -2
  6. data/Steepfile +1 -1
  7. data/core/array.rbs +573 -423
  8. data/core/basic_object.rbs +11 -39
  9. data/core/binding.rbs +1 -1
  10. data/core/builtin.rbs +8 -0
  11. data/core/class.rbs +37 -0
  12. data/core/comparable.rbs +7 -18
  13. data/core/complex.rbs +2 -2
  14. data/core/data.rbs +419 -0
  15. data/core/dir.rbs +52 -104
  16. data/core/encoding.rbs +22 -181
  17. data/core/enumerable.rbs +212 -175
  18. data/core/enumerator/product.rbs +96 -0
  19. data/core/enumerator.rbs +57 -8
  20. data/core/errors.rbs +8 -2
  21. data/core/exception.rbs +41 -0
  22. data/core/fiber.rbs +95 -12
  23. data/core/file.rbs +840 -275
  24. data/core/file_test.rbs +34 -19
  25. data/core/float.rbs +40 -96
  26. data/core/gc.rbs +15 -3
  27. data/core/hash.rbs +113 -175
  28. data/core/integer.rbs +85 -145
  29. data/core/io/buffer.rbs +187 -60
  30. data/core/io/wait.rbs +28 -16
  31. data/core/io.rbs +1859 -1389
  32. data/core/kernel.rbs +525 -961
  33. data/core/match_data.rbs +306 -142
  34. data/core/math.rbs +506 -234
  35. data/core/method.rbs +0 -24
  36. data/core/module.rbs +110 -17
  37. data/core/nil_class.rbs +2 -0
  38. data/core/numeric.rbs +76 -144
  39. data/core/object.rbs +88 -212
  40. data/core/proc.rbs +17 -5
  41. data/core/process.rbs +22 -5
  42. data/core/ractor.rbs +1 -1
  43. data/core/random.rbs +20 -3
  44. data/core/range.rbs +91 -89
  45. data/core/rational.rbs +2 -3
  46. data/core/rbs/unnamed/argf.rbs +177 -120
  47. data/core/rbs/unnamed/env_class.rbs +89 -163
  48. data/core/rbs/unnamed/random.rbs +36 -12
  49. data/core/refinement.rbs +8 -0
  50. data/core/regexp.rbs +462 -272
  51. data/core/ruby_vm.rbs +210 -0
  52. data/{stdlib/set/0 → core}/set.rbs +43 -47
  53. data/core/string.rbs +1403 -1332
  54. data/core/string_io.rbs +191 -107
  55. data/core/struct.rbs +67 -63
  56. data/core/symbol.rbs +187 -201
  57. data/core/thread.rbs +40 -35
  58. data/core/time.rbs +902 -826
  59. data/core/trace_point.rbs +55 -6
  60. data/core/unbound_method.rbs +48 -24
  61. data/docs/collection.md +4 -0
  62. data/docs/syntax.md +55 -0
  63. data/ext/rbs_extension/parser.c +5 -6
  64. data/lib/rbs/cli.rb +6 -1
  65. data/lib/rbs/collection/cleaner.rb +8 -1
  66. data/lib/rbs/collection/config/lockfile.rb +3 -1
  67. data/lib/rbs/collection/config/lockfile_generator.rb +16 -14
  68. data/lib/rbs/collection/config.rb +1 -1
  69. data/lib/rbs/collection/sources/git.rb +9 -2
  70. data/lib/rbs/collection/sources/local.rb +79 -0
  71. data/lib/rbs/collection/sources.rb +8 -1
  72. data/lib/rbs/environment.rb +6 -5
  73. data/lib/rbs/environment_loader.rb +3 -2
  74. data/lib/rbs/errors.rb +18 -0
  75. data/lib/rbs/locator.rb +26 -7
  76. data/lib/rbs/sorter.rb +2 -2
  77. data/lib/rbs/version.rb +1 -1
  78. data/sig/collection/sources.rbs +32 -3
  79. data/sig/environment.rbs +2 -3
  80. data/sig/locator.rbs +14 -2
  81. data/sig/shims/{abstract_syntax_tree.rbs → _abstract_syntax_tree.rbs} +0 -0
  82. data/stdlib/bigdecimal/0/big_decimal.rbs +16 -13
  83. data/stdlib/cgi/0/core.rbs +16 -0
  84. data/stdlib/coverage/0/coverage.rbs +50 -8
  85. data/stdlib/csv/0/csv.rbs +1 -1
  86. data/stdlib/date/0/date.rbs +856 -726
  87. data/stdlib/date/0/date_time.rbs +83 -210
  88. data/stdlib/erb/0/erb.rbs +13 -36
  89. data/stdlib/etc/0/etc.rbs +127 -20
  90. data/stdlib/fileutils/0/fileutils.rbs +1290 -381
  91. data/stdlib/logger/0/logger.rbs +466 -316
  92. data/stdlib/net-http/0/net-http.rbs +2211 -534
  93. data/stdlib/nkf/0/nkf.rbs +5 -5
  94. data/stdlib/objspace/0/objspace.rbs +31 -14
  95. data/stdlib/openssl/0/openssl.rbs +11 -7
  96. data/stdlib/optparse/0/optparse.rbs +20 -17
  97. data/stdlib/pathname/0/pathname.rbs +21 -4
  98. data/stdlib/pstore/0/pstore.rbs +378 -154
  99. data/stdlib/pty/0/pty.rbs +24 -8
  100. data/stdlib/ripper/0/ripper.rbs +1650 -0
  101. data/stdlib/socket/0/addrinfo.rbs +9 -15
  102. data/stdlib/socket/0/socket.rbs +36 -3
  103. data/stdlib/strscan/0/string_scanner.rbs +7 -5
  104. data/stdlib/tempfile/0/tempfile.rbs +104 -44
  105. data/stdlib/time/0/time.rbs +2 -2
  106. data/stdlib/uri/0/file.rbs +5 -0
  107. data/stdlib/uri/0/generic.rbs +2 -2
  108. data/stdlib/yaml/0/yaml.rbs +2 -2
  109. data/stdlib/zlib/0/zlib.rbs +1 -1
  110. metadata +8 -6
  111. data/core/deprecated.rbs +0 -9
  112. data/sig/shims/ripper.rbs +0 -8
@@ -1,144 +1,100 @@
1
1
  # <!-- rdoc-file=ext/date/date_core.c -->
2
- # date and datetime class - Tadayoshi Funaba 1998-2011
2
+ # Class Date provides methods for storing and manipulating calendar dates.
3
3
  #
4
- # 'date' provides two classes: Date and DateTime.
4
+ # Consider using [class Time](rdoc-ref:Time) instead of class Date if:
5
5
  #
6
- # ## Terms and Definitions
6
+ # * You need both dates and times; Date handles only dates.
7
+ # * You need only Gregorian dates (and not Julian dates); see [Julian and
8
+ # Gregorian Calendars](rdoc-ref:calendars.rdoc).
7
9
  #
8
- # Some terms and definitions are based on ISO 8601 and JIS X 0301.
9
10
  #
10
- # ### Calendar Date
11
+ # A Date object, once created, is immutable, and cannot be modified.
11
12
  #
12
- # The calendar date is a particular day of a calendar year, identified by its
13
- # ordinal number within a calendar month within that year.
13
+ # ## Creating a Date
14
14
  #
15
- # In those classes, this is so-called "civil".
15
+ # You can create a date for the current date, using Date.today:
16
16
  #
17
- # ### Ordinal Date
17
+ # Date.today # => #<Date: 1999-12-31>
18
18
  #
19
- # The ordinal date is a particular day of a calendar year identified by its
20
- # ordinal number within the year.
19
+ # You can create a specific date from various combinations of arguments:
21
20
  #
22
- # In those classes, this is so-called "ordinal".
21
+ # * Date.new takes integer year, month, and day-of-month:
23
22
  #
24
- # ### Week Date
23
+ # Date.new(1999, 12, 31) # => #<Date: 1999-12-31>
25
24
  #
26
- # The week date is a date identified by calendar week and day numbers.
25
+ # * Date.ordinal takes integer year and day-of-year:
27
26
  #
28
- # The calendar week is a seven day period within a calendar year, starting on a
29
- # Monday and identified by its ordinal number within the year; the first
30
- # calendar week of the year is the one that includes the first Thursday of that
31
- # year. In the Gregorian calendar, this is equivalent to the week which includes
32
- # January 4.
27
+ # Date.ordinal(1999, 365) # => #<Date: 1999-12-31>
33
28
  #
34
- # In those classes, this is so-called "commercial".
29
+ # * Date.jd takes integer Julian day:
35
30
  #
36
- # ### Julian Day Number
31
+ # Date.jd(2451544) # => #<Date: 1999-12-31>
37
32
  #
38
- # The Julian day number is in elapsed days since noon (Greenwich Mean Time) on
39
- # January 1, 4713 BCE (in the Julian calendar).
33
+ # * Date.commercial takes integer commercial data (year, week, day-of-week):
40
34
  #
41
- # In this document, the astronomical Julian day number is the same as the
42
- # original Julian day number. And the chronological Julian day number is a
43
- # variation of the Julian day number. Its days begin at midnight on local time.
35
+ # Date.commercial(1999, 52, 5) # => #<Date: 1999-12-31>
44
36
  #
45
- # In this document, when the term "Julian day number" simply appears, it just
46
- # refers to "chronological Julian day number", not the original.
37
+ # * Date.parse takes a string, which it parses heuristically:
47
38
  #
48
- # In those classes, those are so-called "ajd" and "jd".
39
+ # Date.parse('1999-12-31') # => #<Date: 1999-12-31>
40
+ # Date.parse('31-12-1999') # => #<Date: 1999-12-31>
41
+ # Date.parse('1999-365') # => #<Date: 1999-12-31>
42
+ # Date.parse('1999-W52-5') # => #<Date: 1999-12-31>
49
43
  #
50
- # ### Modified Julian Day Number
44
+ # * Date.strptime takes a date string and a format string, then parses the
45
+ # date string according to the format string:
51
46
  #
52
- # The modified Julian day number is in elapsed days since midnight (Coordinated
53
- # Universal Time) on November 17, 1858 CE (in the Gregorian calendar).
47
+ # Date.strptime('1999-12-31', '%Y-%m-%d') # => #<Date: 1999-12-31>
48
+ # Date.strptime('31-12-1999', '%d-%m-%Y') # => #<Date: 1999-12-31>
49
+ # Date.strptime('1999-365', '%Y-%j') # => #<Date: 1999-12-31>
50
+ # Date.strptime('1999-W52-5', '%G-W%V-%u') # => #<Date: 1999-12-31>
51
+ # Date.strptime('1999 52 5', '%Y %U %w') # => #<Date: 1999-12-31>
52
+ # Date.strptime('1999 52 5', '%Y %W %u') # => #<Date: 1999-12-31>
53
+ # Date.strptime('fri31dec99', '%a%d%b%y') # => #<Date: 1999-12-31>
54
54
  #
55
- # In this document, the astronomical modified Julian day number is the same as
56
- # the original modified Julian day number. And the chronological modified Julian
57
- # day number is a variation of the modified Julian day number. Its days begin at
58
- # midnight on local time.
59
55
  #
60
- # In this document, when the term "modified Julian day number" simply appears,
61
- # it just refers to "chronological modified Julian day number", not the
62
- # original.
56
+ # See also the specialized methods in ["Specialized Format Strings" in Formats
57
+ # for Dates and
58
+ # Times](rdoc-ref:strftime_formatting.rdoc@Specialized+Format+Strings)
63
59
  #
64
- # In those classes, those are so-called "amjd" and "mjd".
60
+ # ## Argument `limit`
65
61
  #
66
- # ## Date
62
+ # Certain singleton methods in Date that parse string arguments also take
63
+ # optional keyword argument `limit`, which can limit the length of the string
64
+ # argument.
67
65
  #
68
- # A subclass of Object that includes the Comparable module and easily handles
69
- # date.
66
+ # When `limit` is:
70
67
  #
71
- # A Date object is created with Date::new, Date::jd, Date::ordinal,
72
- # Date::commercial, Date::parse, Date::strptime, Date::today, Time#to_date, etc.
73
- #
74
- # require 'date'
75
- #
76
- # Date.new(2001,2,3)
77
- # #=> #<Date: 2001-02-03 ...>
78
- # Date.jd(2451944)
79
- # #=> #<Date: 2001-02-03 ...>
80
- # Date.ordinal(2001,34)
81
- # #=> #<Date: 2001-02-03 ...>
82
- # Date.commercial(2001,5,6)
83
- # #=> #<Date: 2001-02-03 ...>
84
- # Date.parse('2001-02-03')
85
- # #=> #<Date: 2001-02-03 ...>
86
- # Date.strptime('03-02-2001', '%d-%m-%Y')
87
- # #=> #<Date: 2001-02-03 ...>
88
- # Time.new(2001,2,3).to_date
89
- # #=> #<Date: 2001-02-03 ...>
90
- #
91
- # All date objects are immutable; hence cannot modify themselves.
92
- #
93
- # The concept of a date object can be represented as a tuple of the day count,
94
- # the offset and the day of calendar reform.
95
- #
96
- # The day count denotes the absolute position of a temporal dimension. The
97
- # offset is relative adjustment, which determines decoded local time with the
98
- # day count. The day of calendar reform denotes the start day of the new style.
99
- # The old style of the West is the Julian calendar which was adopted by Caesar.
100
- # The new style is the Gregorian calendar, which is the current civil calendar
101
- # of many countries.
102
- #
103
- # The day count is virtually the astronomical Julian day number. The offset in
104
- # this class is usually zero, and cannot be specified directly.
105
- #
106
- # A Date object can be created with an optional argument, the day of calendar
107
- # reform as a Julian day number, which should be 2298874 to 2426355 or
108
- # negative/positive infinity. The default value is `Date::ITALY`
109
- # (2299161=1582-10-15). See also sample/cal.rb.
110
- #
111
- # $ ruby sample/cal.rb -c it 10 1582
112
- # October 1582
113
- # S M Tu W Th F S
114
- # 1 2 3 4 15 16
115
- # 17 18 19 20 21 22 23
116
- # 24 25 26 27 28 29 30
117
- # 31
118
- #
119
- # $ ruby sample/cal.rb -c gb 9 1752
120
- # September 1752
121
- # S M Tu W Th F S
122
- # 1 2 14 15 16
123
- # 17 18 19 20 21 22 23
124
- # 24 25 26 27 28 29 30
125
- #
126
- # A Date object has various methods. See each reference.
127
- #
128
- # d = Date.parse('3rd Feb 2001')
129
- # #=> #<Date: 2001-02-03 ...>
130
- # d.year #=> 2001
131
- # d.mon #=> 2
132
- # d.mday #=> 3
133
- # d.wday #=> 6
134
- # d += 1 #=> #<Date: 2001-02-04 ...>
135
- # d.strftime('%a %d %b %Y') #=> "Sun 04 Feb 2001"
68
+ # * Non-negative: raises ArgumentError if the string length is greater than
69
+ # *limit*.
70
+ # * Other numeric or `nil`: ignores `limit`.
71
+ # * Other non-numeric: raises TypeError.
136
72
  #
137
73
  class Date
138
74
  # <!--
139
75
  # rdoc-file=ext/date/date_core.c
140
- # - new(p1 = v1, p2 = v2, p3 = v3, p4 = v4)
76
+ # - Date.new(year = -4712, month = 1, mday = 1, start = Date::ITALY) -> date
141
77
  # -->
78
+ # Returns a new Date object constructed from the given arguments:
79
+ #
80
+ # Date.new(2022).to_s # => "2022-01-01"
81
+ # Date.new(2022, 2).to_s # => "2022-02-01"
82
+ # Date.new(2022, 2, 4).to_s # => "2022-02-04"
83
+ #
84
+ # Argument `month` should be in range (1..12) or range (-12..-1); when the
85
+ # argument is negative, counts backward from the end of the year:
86
+ #
87
+ # Date.new(2022, -11, 4).to_s # => "2022-02-04"
88
+ #
89
+ # Argument `mday` should be in range (1..n) or range (-n..-1) where `n` is the
90
+ # number of days in the month; when the argument is negative, counts backward
91
+ # from the end of the month.
92
+ #
93
+ # See argument [start](rdoc-ref:calendars.rdoc@Argument+start).
94
+ #
95
+ # Date.civil is an alias for Date.new.
96
+ #
97
+ # Related: Date.jd.
142
98
  #
143
99
  def initialize: (?Integer year, ?Integer month, ?Integer mday, ?Integer start) -> void
144
100
 
@@ -146,480 +102,652 @@ class Date
146
102
 
147
103
  # <!--
148
104
  # rdoc-file=ext/date/date_core.c
149
- # - Date._httpdate(string, limit: 128) -> hash
105
+ # - Date._httpdate(string, limit: 128) -> hash
150
106
  # -->
151
- # Returns a hash of parsed elements.
107
+ # Returns a hash of values parsed from `string`, which should be a valid [HTTP
108
+ # date format](rdoc-ref:strftime_formatting.rdoc@HTTP+Format):
152
109
  #
153
- # Raise an ArgumentError when the string length is longer than *limit*. You can
154
- # stop this check by passing `limit: nil`, but note that it may take a long time
155
- # to parse.
110
+ # d = Date.new(2001, 2, 3)
111
+ # s = d.httpdate # => "Sat, 03 Feb 2001 00:00:00 GMT"
112
+ # Date._httpdate(s)
113
+ # # => {:wday=>6, :mday=>3, :mon=>2, :year=>2001, :hour=>0, :min=>0, :sec=>0, :zone=>"GMT", :offset=>0}
114
+ #
115
+ # Related: Date.httpdate (returns a Date object).
156
116
  #
157
117
  def self._httpdate: (String str) -> Hash[Symbol, Integer]
158
118
 
159
119
  # <!--
160
120
  # rdoc-file=ext/date/date_core.c
161
- # - Date._iso8601(string, limit: 128) -> hash
121
+ # - Date._iso8601(string, limit: 128) -> hash
162
122
  # -->
163
- # Returns a hash of parsed elements.
123
+ # Returns a hash of values parsed from `string`, which should contain an [ISO
124
+ # 8601 formatted
125
+ # date](rdoc-ref:strftime_formatting.rdoc@ISO+8601+Format+Specifications):
126
+ #
127
+ # d = Date.new(2001, 2, 3)
128
+ # s = d.iso8601 # => "2001-02-03"
129
+ # Date._iso8601(s) # => {:mday=>3, :year=>2001, :mon=>2}
130
+ #
131
+ # See argument [limit](rdoc-ref:Date@Argument+limit).
164
132
  #
165
- # Raise an ArgumentError when the string length is longer than *limit*. You can
166
- # stop this check by passing `limit: nil`, but note that it may take a long time
167
- # to parse.
133
+ # Related: Date.iso8601 (returns a Date object).
168
134
  #
169
135
  def self._iso8601: (String str) -> Hash[Symbol, Integer]
170
136
 
171
137
  # <!--
172
138
  # rdoc-file=ext/date/date_core.c
173
- # - Date._jisx0301(string, limit: 128) -> hash
139
+ # - Date._jisx0301(string, limit: 128) -> hash
174
140
  # -->
175
- # Returns a hash of parsed elements.
141
+ # Returns a hash of values parsed from `string`, which should be a valid [JIS X
142
+ # 0301 date format](rdoc-ref:strftime_formatting.rdoc@JIS+X+0301+Format):
176
143
  #
177
- # Raise an ArgumentError when the string length is longer than *limit*. You can
178
- # stop this check by passing `limit: nil`, but note that it may take a long time
179
- # to parse.
144
+ # d = Date.new(2001, 2, 3)
145
+ # s = d.jisx0301 # => "H13.02.03"
146
+ # Date._jisx0301(s) # => {:year=>2001, :mon=>2, :mday=>3}
147
+ #
148
+ # See argument [limit](rdoc-ref:Date@Argument+limit).
149
+ #
150
+ # Related: Date.jisx0301 (returns a Date object).
180
151
  #
181
152
  def self._jisx0301: (String str) -> Hash[Symbol, Integer]
182
153
 
183
154
  # <!--
184
155
  # rdoc-file=ext/date/date_core.c
185
- # - Date._parse(string[, comp=true], limit: 128) -> hash
156
+ # - Date._parse(string, comp = true, limit: 128) -> hash
186
157
  # -->
187
- # Parses the given representation of date and time, and returns a hash of parsed
188
- # elements.
158
+ # **Note**: This method recognizes many forms in `string`, but it is not a
159
+ # validator. For formats, see ["Specialized Format Strings" in Formats for Dates
160
+ # and Times](rdoc-ref:strftime_formatting.rdoc@Specialized+Format+Strings)
161
+ #
162
+ # If `string` does not specify a valid date, the result is unpredictable;
163
+ # consider using Date._strptime instead.
189
164
  #
190
- # This method *does not* function as a validator. If the input string does not
191
- # match valid formats strictly, you may get a cryptic result. Should consider
192
- # to use `Date._strptime` or `DateTime._strptime` instead of this method as
193
- # possible.
165
+ # Returns a hash of values parsed from `string`:
194
166
  #
195
- # If the optional second argument is true and the detected year is in the range
196
- # "00" to "99", considers the year a 2-digit form and makes it full.
167
+ # Date._parse('2001-02-03') # => {:year=>2001, :mon=>2, :mday=>3}
197
168
  #
198
- # Date._parse('2001-02-03') #=> {:year=>2001, :mon=>2, :mday=>3}
169
+ # If `comp` is `true` and the given year is in the range `(0..99)`, the current
170
+ # century is supplied; otherwise, the year is taken as given:
199
171
  #
200
- # Raise an ArgumentError when the string length is longer than *limit*. You can
201
- # stop this check by passing `limit: nil`, but note that it may take a long time
202
- # to parse.
172
+ # Date._parse('01-02-03', true) # => {:year=>2001, :mon=>2, :mday=>3}
173
+ # Date._parse('01-02-03', false) # => {:year=>1, :mon=>2, :mday=>3}
174
+ #
175
+ # See argument [limit](rdoc-ref:Date@Argument+limit).
176
+ #
177
+ # Related: Date.parse(returns a Date object).
203
178
  #
204
179
  def self._parse: (String str, ?boolish complete) -> Hash[Symbol, Integer]
205
180
 
206
181
  # <!--
207
182
  # rdoc-file=ext/date/date_core.c
208
- # - Date._rfc2822(string, limit: 128) -> hash
209
- # - Date._rfc822(string, limit: 128) -> hash
183
+ # - Date._rfc2822(string, limit: 128) -> hash
210
184
  # -->
211
- # Returns a hash of parsed elements.
185
+ # Returns a hash of values parsed from `string`, which should be a valid [RFC
186
+ # 2822 date format](rdoc-ref:strftime_formatting.rdoc@RFC+2822+Format):
187
+ #
188
+ # d = Date.new(2001, 2, 3)
189
+ # s = d.rfc2822 # => "Sat, 3 Feb 2001 00:00:00 +0000"
190
+ # Date._rfc2822(s)
191
+ # # => {:wday=>6, :mday=>3, :mon=>2, :year=>2001, :hour=>0, :min=>0, :sec=>0, :zone=>"+0000", :offset=>0}
212
192
  #
213
- # Raise an ArgumentError when the string length is longer than *limit*. You can
214
- # stop this check by passing `limit: nil`, but note that it may take a long time
215
- # to parse.
193
+ # See argument [limit](rdoc-ref:Date@Argument+limit).
194
+ #
195
+ # Date._rfc822 is an alias for Date._rfc2822.
196
+ #
197
+ # Related: Date.rfc2822 (returns a Date object).
216
198
  #
217
199
  def self._rfc2822: (String str) -> Hash[Symbol, Integer | String]
218
200
 
219
201
  # <!--
220
202
  # rdoc-file=ext/date/date_core.c
221
- # - Date._rfc3339(string, limit: 128) -> hash
203
+ # - Date._rfc3339(string, limit: 128) -> hash
222
204
  # -->
223
- # Returns a hash of parsed elements.
205
+ # Returns a hash of values parsed from `string`, which should be a valid [RFC
206
+ # 3339 format](rdoc-ref:strftime_formatting.rdoc@RFC+3339+Format):
207
+ #
208
+ # d = Date.new(2001, 2, 3)
209
+ # s = d.rfc3339 # => "2001-02-03T00:00:00+00:00"
210
+ # Date._rfc3339(s)
211
+ # # => {:year=>2001, :mon=>2, :mday=>3, :hour=>0, :min=>0, :sec=>0, :zone=>"+00:00", :offset=>0}
224
212
  #
225
- # Raise an ArgumentError when the string length is longer than *limit*. You can
226
- # stop this check by passing `limit: nil`, but note that it may take a long time
227
- # to parse.
213
+ # See argument [limit](rdoc-ref:Date@Argument+limit).
214
+ #
215
+ # Related: Date.rfc3339 (returns a Date object).
228
216
  #
229
217
  def self._rfc3339: (String str) -> Hash[Symbol, Integer | String]
230
218
 
231
219
  # <!--
232
220
  # rdoc-file=ext/date/date_core.c
233
- # - Date._rfc2822(string, limit: 128) -> hash
234
- # - Date._rfc822(string, limit: 128) -> hash
221
+ # - Date._rfc2822(string, limit: 128) -> hash
235
222
  # -->
236
- # Returns a hash of parsed elements.
223
+ # Returns a hash of values parsed from `string`, which should be a valid [RFC
224
+ # 2822 date format](rdoc-ref:strftime_formatting.rdoc@RFC+2822+Format):
225
+ #
226
+ # d = Date.new(2001, 2, 3)
227
+ # s = d.rfc2822 # => "Sat, 3 Feb 2001 00:00:00 +0000"
228
+ # Date._rfc2822(s)
229
+ # # => {:wday=>6, :mday=>3, :mon=>2, :year=>2001, :hour=>0, :min=>0, :sec=>0, :zone=>"+0000", :offset=>0}
230
+ #
231
+ # See argument [limit](rdoc-ref:Date@Argument+limit).
237
232
  #
238
- # Raise an ArgumentError when the string length is longer than *limit*. You can
239
- # stop this check by passing `limit: nil`, but note that it may take a long time
240
- # to parse.
233
+ # Date._rfc822 is an alias for Date._rfc2822.
234
+ #
235
+ # Related: Date.rfc2822 (returns a Date object).
241
236
  #
242
237
  def self._rfc822: (String str) -> Hash[Symbol, Integer | String]
243
238
 
244
239
  # <!--
245
240
  # rdoc-file=ext/date/date_core.c
246
- # - Date._strptime(string[, format='%F']) -> hash
241
+ # - Date._strptime(string, format = '%F') -> hash
247
242
  # -->
248
- # Parses the given representation of date and time with the given template, and
249
- # returns a hash of parsed elements. _strptime does not support specification
250
- # of flags and width unlike strftime.
243
+ # Returns a hash of values parsed from `string` according to the given `format`:
244
+ #
245
+ # Date._strptime('2001-02-03', '%Y-%m-%d') # => {:year=>2001, :mon=>2, :mday=>3}
246
+ #
247
+ # For other formats, see [Formats for Dates and
248
+ # Times](rdoc-ref:strftime_formatting.rdoc). (Unlike Date.strftime, does not
249
+ # support flags and width.)
251
250
  #
252
- # Date._strptime('2001-02-03', '%Y-%m-%d')
253
- # #=> {:year=>2001, :mon=>2, :mday=>3}
251
+ # See also [strptime(3)](https://man7.org/linux/man-pages/man3/strptime.3.html).
254
252
  #
255
- # See also strptime(3) and #strftime.
253
+ # Related: Date.strptime (returns a Date object).
256
254
  #
257
255
  def self._strptime: (String str, ?String format) -> Hash[Symbol, Integer]
258
256
 
259
257
  # <!--
260
258
  # rdoc-file=ext/date/date_core.c
261
- # - Date._xmlschema(string, limit: 128) -> hash
259
+ # - Date._xmlschema(string, limit: 128) -> hash
262
260
  # -->
263
- # Returns a hash of parsed elements.
261
+ # Returns a hash of values parsed from `string`, which should be a valid XML
262
+ # date format:
264
263
  #
265
- # Raise an ArgumentError when the string length is longer than *limit*. You can
266
- # stop this check by passing `limit: nil`, but note that it may take a long time
267
- # to parse.
264
+ # d = Date.new(2001, 2, 3)
265
+ # s = d.xmlschema # => "2001-02-03"
266
+ # Date._xmlschema(s) # => {:year=>2001, :mon=>2, :mday=>3}
267
+ #
268
+ # See argument [limit](rdoc-ref:Date@Argument+limit).
269
+ #
270
+ # Related: Date.xmlschema (returns a Date object).
268
271
  #
269
272
  def self._xmlschema: (String str) -> Hash[Symbol, Integer]
270
273
 
271
274
  # <!--
272
275
  # rdoc-file=ext/date/date_core.c
273
- # - Date.civil([year=-4712[, month=1[, mday=1[, start=Date::ITALY]]]]) -> date
274
- # - Date.new([year=-4712[, month=1[, mday=1[, start=Date::ITALY]]]]) -> date
276
+ # - civil(*args)
275
277
  # -->
276
- # Creates a date object denoting the given calendar date.
277
- #
278
- # In this class, BCE years are counted astronomically. Thus, the year before
279
- # the year 1 is the year zero, and the year preceding the year zero is the year
280
- # -1. The month and the day of month should be a negative or a positive number
281
- # (as a relative month/day from the end of year/month when negative). They
282
- # should not be zero.
283
- #
284
- # The last argument should be a Julian day number which denotes the day of
285
- # calendar reform. Date::ITALY (2299161=1582-10-15), Date::ENGLAND
286
- # (2361222=1752-09-14), Date::GREGORIAN (the proleptic Gregorian calendar) and
287
- # Date::JULIAN (the proleptic Julian calendar) can be specified as a day of
288
- # calendar reform.
289
- #
290
- # Date.new(2001) #=> #<Date: 2001-01-01 ...>
291
- # Date.new(2001,2,3) #=> #<Date: 2001-02-03 ...>
292
- # Date.new(2001,2,-1) #=> #<Date: 2001-02-28 ...>
293
- #
294
- # See also ::jd.
278
+ # Same as Date.new.
295
279
  #
296
280
  def self.civil: (?Integer year, ?Integer month, ?Integer mday, ?Integer start) -> Date
297
281
 
298
282
  # <!--
299
283
  # rdoc-file=ext/date/date_core.c
300
- # - Date.commercial([cwyear=-4712[, cweek=1[, cwday=1[, start=Date::ITALY]]]]) -> date
284
+ # - Date.commercial(cwyear = -4712, cweek = 1, cwday = 1, start = Date::ITALY) -> date
301
285
  # -->
302
- # Creates a date object denoting the given week date.
286
+ # Returns a new Date object constructed from the arguments.
287
+ #
288
+ # Argument `cwyear` gives the year, and should be an integer.
289
+ #
290
+ # Argument `cweek` gives the index of the week within the year, and should be in
291
+ # range (1..53) or (-53..-1); in some years, 53 or -53 will be out-of-range; if
292
+ # negative, counts backward from the end of the year:
293
+ #
294
+ # Date.commercial(2022, 1, 1).to_s # => "2022-01-03"
295
+ # Date.commercial(2022, 52, 1).to_s # => "2022-12-26"
296
+ #
297
+ # Argument `cwday` gives the indes of the weekday within the week, and should be
298
+ # in range (1..7) or (-7..-1); 1 or -7 is Monday; if negative, counts backward
299
+ # from the end of the week:
300
+ #
301
+ # Date.commercial(2022, 1, 1).to_s # => "2022-01-03"
302
+ # Date.commercial(2022, 1, -7).to_s # => "2022-01-03"
303
303
  #
304
- # The week and the day of week should be a negative or a positive number (as a
305
- # relative week/day from the end of year/week when negative). They should not
306
- # be zero.
304
+ # When `cweek` is 1:
307
305
  #
308
- # Date.commercial(2001) #=> #<Date: 2001-01-01 ...>
309
- # Date.commercial(2002) #=> #<Date: 2001-12-31 ...>
310
- # Date.commercial(2001,5,6) #=> #<Date: 2001-02-03 ...>
306
+ # * If January 1 is a Friday, Saturday, or Sunday, the first week begins in
307
+ # the week after:
311
308
  #
312
- # See also ::jd and ::new.
309
+ # Date::ABBR_DAYNAMES[Date.new(2023, 1, 1).wday] # => "Sun"
310
+ # Date.commercial(2023, 1, 1).to_s # => "2023-01-02"
311
+ # Date.commercial(2023, 1, 7).to_s # => "2023-01-08"
312
+ #
313
+ # * Otherwise, the first week is the week of January 1, which may mean some of
314
+ # the days fall on the year before:
315
+ #
316
+ # Date::ABBR_DAYNAMES[Date.new(2020, 1, 1).wday] # => "Wed"
317
+ # Date.commercial(2020, 1, 1).to_s # => "2019-12-30"
318
+ # Date.commercial(2020, 1, 7).to_s # => "2020-01-05"
319
+ #
320
+ #
321
+ # See argument [start](rdoc-ref:calendars.rdoc@Argument+start).
322
+ #
323
+ # Related: Date.jd, Date.new, Date.ordinal.
313
324
  #
314
325
  def self.commercial: (?Integer cwyear, ?Integer cweek, ?Integer cwday, ?Integer start) -> Date
315
326
 
316
327
  # <!--
317
328
  # rdoc-file=ext/date/date_core.c
318
- # - Date.gregorian_leap?(year) -> bool
319
- # - Date.leap?(year) -> bool
329
+ # - Date.gregorian_leap?(year) -> true or false
320
330
  # -->
321
- # Returns true if the given year is a leap year of the proleptic Gregorian
322
- # calendar.
331
+ # Returns `true` if the given year is a leap year in the [proleptic Gregorian
332
+ # calendar](https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar), `false`
333
+ # otherwise:
334
+ #
335
+ # Date.gregorian_leap?(2000) # => true
336
+ # Date.gregorian_leap?(2001) # => false
323
337
  #
324
- # Date.gregorian_leap?(1900) #=> false
325
- # Date.gregorian_leap?(2000) #=> true
338
+ # Date.leap? is an alias for Date.gregorian_leap?.
339
+ #
340
+ # Related: Date.julian_leap?.
326
341
  #
327
342
  def self.gregorian_leap?: (Integer year) -> bool
328
343
 
329
344
  # <!--
330
345
  # rdoc-file=ext/date/date_core.c
331
- # - Date.httpdate(string='Mon, 01 Jan -4712 00:00:00 GMT'[, start=Date::ITALY], limit: 128) -> date
346
+ # - Date.httpdate(string = 'Mon, 01 Jan -4712 00:00:00 GMT', start = Date::ITALY, limit: 128) -> date
332
347
  # -->
333
- # Creates a new Date object by parsing from a string according to some RFC 2616
334
- # format.
348
+ # Returns a new Date object with values parsed from `string`, which should be a
349
+ # valid [HTTP date format](rdoc-ref:strftime_formatting.rdoc@HTTP+Format):
350
+ #
351
+ # d = Date.new(2001, 2, 3)
352
+ # s = d.httpdate # => "Sat, 03 Feb 2001 00:00:00 GMT"
353
+ # Date.httpdate(s) # => #<Date: 2001-02-03>
354
+ #
355
+ # See:
335
356
  #
336
- # Date.httpdate('Sat, 03 Feb 2001 00:00:00 GMT')
337
- # #=> #<Date: 2001-02-03 ...>
357
+ # * Argument [start](rdoc-ref:calendars.rdoc@Argument+start).
358
+ # * Argument [limit](rdoc-ref:Date@Argument+limit).
338
359
  #
339
- # Raise an ArgumentError when the string length is longer than *limit*. You can
340
- # stop this check by passing `limit: nil`, but note that it may take a long time
341
- # to parse.
360
+ #
361
+ # Related: Date._httpdate (returns a hash).
342
362
  #
343
363
  def self.httpdate: (String str, ?Integer start) -> Date
344
364
 
345
365
  # <!--
346
366
  # rdoc-file=ext/date/date_core.c
347
- # - Date.iso8601(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
367
+ # - Date.iso8601(string = '-4712-01-01', start = Date::ITALY, limit: 128) -> date
348
368
  # -->
349
- # Creates a new Date object by parsing from a string according to some typical
350
- # ISO 8601 formats.
369
+ # Returns a new Date object with values parsed from `string`, which should
370
+ # contain an [ISO 8601 formatted
371
+ # date](rdoc-ref:strftime_formatting.rdoc@ISO+8601+Format+Specifications):
372
+ #
373
+ # d = Date.new(2001, 2, 3)
374
+ # s = d.iso8601 # => "2001-02-03"
375
+ # Date.iso8601(s) # => #<Date: 2001-02-03>
376
+ #
377
+ # See:
351
378
  #
352
- # Date.iso8601('2001-02-03') #=> #<Date: 2001-02-03 ...>
353
- # Date.iso8601('20010203') #=> #<Date: 2001-02-03 ...>
354
- # Date.iso8601('2001-W05-6') #=> #<Date: 2001-02-03 ...>
379
+ # * Argument [start](rdoc-ref:calendars.rdoc@Argument+start).
380
+ # * Argument [limit](rdoc-ref:Date@Argument+limit).
355
381
  #
356
- # Raise an ArgumentError when the string length is longer than *limit*. You can
357
- # stop this check by passing `limit: nil`, but note that it may take a long time
358
- # to parse.
382
+ #
383
+ # Related: Date._iso8601 (returns a hash).
359
384
  #
360
385
  def self.iso8601: (String str, ?Integer start) -> Date
361
386
 
362
387
  # <!--
363
388
  # rdoc-file=ext/date/date_core.c
364
- # - Date.jd([jd=0[, start=Date::ITALY]]) -> date
389
+ # - Date.jd(jd = 0, start = Date::ITALY) -> date
365
390
  # -->
366
- # Creates a date object denoting the given chronological Julian day number.
391
+ # Returns a new Date object formed from the arguments:
392
+ #
393
+ # Date.jd(2451944).to_s # => "2001-02-03"
394
+ # Date.jd(2451945).to_s # => "2001-02-04"
395
+ # Date.jd(0).to_s # => "-4712-01-01"
396
+ #
397
+ # The returned date is:
398
+ #
399
+ # * Gregorian, if the argument is greater than or equal to `start`:
400
+ #
401
+ # Date::ITALY # => 2299161
402
+ # Date.jd(Date::ITALY).gregorian? # => true
403
+ # Date.jd(Date::ITALY + 1).gregorian? # => true
404
+ #
405
+ # * Julian, otherwise
367
406
  #
368
- # Date.jd(2451944) #=> #<Date: 2001-02-03 ...>
369
- # Date.jd(2451945) #=> #<Date: 2001-02-04 ...>
370
- # Date.jd(0) #=> #<Date: -4712-01-01 ...>
407
+ # Date.jd(Date::ITALY - 1).julian? # => true
371
408
  #
372
- # See also ::new.
409
+ #
410
+ # See argument [start](rdoc-ref:calendars.rdoc@Argument+start).
411
+ #
412
+ # Related: Date.new.
373
413
  #
374
414
  def self.jd: (Integer jd, ?Integer start) -> Date
375
415
 
376
416
  # <!--
377
417
  # rdoc-file=ext/date/date_core.c
378
- # - Date.jisx0301(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
418
+ # - Date.jisx0301(string = '-4712-01-01', start = Date::ITALY, limit: 128) -> date
379
419
  # -->
380
- # Creates a new Date object by parsing from a string according to some typical
381
- # JIS X 0301 formats.
420
+ # Returns a new Date object with values parsed from `string`, which should be a
421
+ # valid [JIS X 0301
422
+ # format](rdoc-ref:strftime_formatting.rdoc@JIS+X+0301+Format):
382
423
  #
383
- # Date.jisx0301('H13.02.03') #=> #<Date: 2001-02-03 ...>
424
+ # d = Date.new(2001, 2, 3)
425
+ # s = d.jisx0301 # => "H13.02.03"
426
+ # Date.jisx0301(s) # => #<Date: 2001-02-03>
384
427
  #
385
428
  # For no-era year, legacy format, Heisei is assumed.
386
429
  #
387
- # Date.jisx0301('13.02.03') #=> #<Date: 2001-02-03 ...>
430
+ # Date.jisx0301('13.02.03') # => #<Date: 2001-02-03>
431
+ #
432
+ # See:
433
+ #
434
+ # * Argument [start](rdoc-ref:calendars.rdoc@Argument+start).
435
+ # * Argument [limit](rdoc-ref:Date@Argument+limit).
436
+ #
388
437
  #
389
- # Raise an ArgumentError when the string length is longer than *limit*. You can
390
- # stop this check by passing `limit: nil`, but note that it may take a long time
391
- # to parse.
438
+ # Related: Date._jisx0301 (returns a hash).
392
439
  #
393
440
  def self.jisx0301: (String str, ?Integer start) -> Date
394
441
 
395
442
  # <!--
396
443
  # rdoc-file=ext/date/date_core.c
397
- # - Date.julian_leap?(year) -> bool
444
+ # - Date.julian_leap?(year) -> true or false
398
445
  # -->
399
- # Returns true if the given year is a leap year of the proleptic Julian
400
- # calendar.
446
+ # Returns `true` if the given year is a leap year in the [proleptic Julian
447
+ # calendar](https://en.wikipedia.org/wiki/Proleptic_Julian_calendar), `false`
448
+ # otherwise:
401
449
  #
402
- # Date.julian_leap?(1900) #=> true
403
- # Date.julian_leap?(1901) #=> false
450
+ # Date.julian_leap?(1900) # => true
451
+ # Date.julian_leap?(1901) # => false
452
+ #
453
+ # Related: Date.gregorian_leap?.
404
454
  #
405
455
  def self.julian_leap?: (Integer year) -> bool
406
456
 
407
457
  # <!--
408
458
  # rdoc-file=ext/date/date_core.c
409
- # - Date.gregorian_leap?(year) -> bool
410
- # - Date.leap?(year) -> bool
459
+ # - Date.gregorian_leap?(year) -> true or false
411
460
  # -->
412
- # Returns true if the given year is a leap year of the proleptic Gregorian
413
- # calendar.
461
+ # Returns `true` if the given year is a leap year in the [proleptic Gregorian
462
+ # calendar](https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar), `false`
463
+ # otherwise:
464
+ #
465
+ # Date.gregorian_leap?(2000) # => true
466
+ # Date.gregorian_leap?(2001) # => false
467
+ #
468
+ # Date.leap? is an alias for Date.gregorian_leap?.
414
469
  #
415
- # Date.gregorian_leap?(1900) #=> false
416
- # Date.gregorian_leap?(2000) #=> true
470
+ # Related: Date.julian_leap?.
417
471
  #
418
472
  def self.leap?: (Integer year) -> bool
419
473
 
420
474
  # <!--
421
475
  # rdoc-file=ext/date/date_core.c
422
- # - Date.ordinal([year=-4712[, yday=1[, start=Date::ITALY]]]) -> date
476
+ # - Date.ordinal(year = -4712, yday = 1, start = Date::ITALY) -> date
423
477
  # -->
424
- # Creates a date object denoting the given ordinal date.
478
+ # Returns a new Date object formed fom the arguments.
479
+ #
480
+ # With no arguments, returns the date for January 1, -4712:
481
+ #
482
+ # Date.ordinal.to_s # => "-4712-01-01"
483
+ #
484
+ # With argument `year`, returns the date for January 1 of that year:
425
485
  #
426
- # The day of year should be a negative or a positive number (as a relative day
427
- # from the end of year when negative). It should not be zero.
486
+ # Date.ordinal(2001).to_s # => "2001-01-01"
487
+ # Date.ordinal(-2001).to_s # => "-2001-01-01"
428
488
  #
429
- # Date.ordinal(2001) #=> #<Date: 2001-01-01 ...>
430
- # Date.ordinal(2001,34) #=> #<Date: 2001-02-03 ...>
431
- # Date.ordinal(2001,-1) #=> #<Date: 2001-12-31 ...>
489
+ # With positive argument `yday` == `n`, returns the date for the `nth` day of
490
+ # the given year:
432
491
  #
433
- # See also ::jd and ::new.
492
+ # Date.ordinal(2001, 14).to_s # => "2001-01-14"
493
+ #
494
+ # With negative argument `yday`, counts backward from the end of the year:
495
+ #
496
+ # Date.ordinal(2001, -14).to_s # => "2001-12-18"
497
+ #
498
+ # Raises an exception if `yday` is zero or out of range.
499
+ #
500
+ # See argument [start](rdoc-ref:calendars.rdoc@Argument+start).
501
+ #
502
+ # Related: Date.jd, Date.new.
434
503
  #
435
504
  def self.ordinal: (?Integer year, ?Integer yday, ?Integer start) -> Date
436
505
 
437
506
  # <!--
438
507
  # rdoc-file=ext/date/date_core.c
439
- # - Date.parse(string='-4712-01-01'[, comp=true[, start=Date::ITALY]], limit: 128) -> date
508
+ # - Date.parse(string = '-4712-01-01', comp = true, start = Date::ITALY, limit: 128) -> date
440
509
  # -->
441
- # Parses the given representation of date and time, and creates a date object.
510
+ # **Note**: This method recognizes many forms in `string`, but it is not a
511
+ # validator. For formats, see ["Specialized Format Strings" in Formats for Dates
512
+ # and Times](rdoc-ref:strftime_formatting.rdoc@Specialized+Format+Strings) If
513
+ # `string` does not specify a valid date, the result is unpredictable; consider
514
+ # using Date._strptime instead.
515
+ #
516
+ # Returns a new Date object with values parsed from `string`:
442
517
  #
443
- # This method *does not* function as a validator. If the input string does not
444
- # match valid formats strictly, you may get a cryptic result. Should consider
445
- # to use `Date.strptime` instead of this method as possible.
518
+ # Date.parse('2001-02-03') # => #<Date: 2001-02-03>
519
+ # Date.parse('20010203') # => #<Date: 2001-02-03>
520
+ # Date.parse('3rd Feb 2001') # => #<Date: 2001-02-03>
446
521
  #
447
- # If the optional second argument is true and the detected year is in the range
448
- # "00" to "99", considers the year a 2-digit form and makes it full.
522
+ # If `comp` is `true` and the given year is in the range `(0..99)`, the current
523
+ # century is supplied; otherwise, the year is taken as given:
449
524
  #
450
- # Date.parse('2001-02-03') #=> #<Date: 2001-02-03 ...>
451
- # Date.parse('20010203') #=> #<Date: 2001-02-03 ...>
452
- # Date.parse('3rd Feb 2001') #=> #<Date: 2001-02-03 ...>
525
+ # Date.parse('01-02-03', true) # => #<Date: 2001-02-03>
526
+ # Date.parse('01-02-03', false) # => #<Date: 0001-02-03>
453
527
  #
454
- # Raise an ArgumentError when the string length is longer than *limit*. You can
455
- # stop this check by passing `limit: nil`, but note that it may take a long time
456
- # to parse.
528
+ # See:
529
+ #
530
+ # * Argument [start](rdoc-ref:calendars.rdoc@Argument+start).
531
+ # * Argument [limit](rdoc-ref:Date@Argument+limit).
532
+ #
533
+ #
534
+ # Related: Date._parse (returns a hash).
457
535
  #
458
536
  def self.parse: (String str, ?boolish complete, ?Integer start) -> Date
459
537
 
460
538
  # <!--
461
539
  # rdoc-file=ext/date/date_core.c
462
- # - Date.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> date
463
- # - Date.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> date
540
+ # - Date.rfc2822(string = 'Mon, 1 Jan -4712 00:00:00 +0000', start = Date::ITALY, limit: 128) -> date
464
541
  # -->
465
- # Creates a new Date object by parsing from a string according to some typical
466
- # RFC 2822 formats.
542
+ # Returns a new Date object with values parsed from `string`, which should be a
543
+ # valid [RFC 2822 date
544
+ # format](rdoc-ref:strftime_formatting.rdoc@RFC+2822+Format):
545
+ #
546
+ # d = Date.new(2001, 2, 3)
547
+ # s = d.rfc2822 # => "Sat, 3 Feb 2001 00:00:00 +0000"
548
+ # Date.rfc2822(s) # => #<Date: 2001-02-03>
549
+ #
550
+ # See:
551
+ #
552
+ # * Argument [start](rdoc-ref:calendars.rdoc@Argument+start).
553
+ # * Argument [limit](rdoc-ref:Date@Argument+limit).
467
554
  #
468
- # Date.rfc2822('Sat, 3 Feb 2001 00:00:00 +0000')
469
- # #=> #<Date: 2001-02-03 ...>
470
555
  #
471
- # Raise an ArgumentError when the string length is longer than *limit*. You can
472
- # stop this check by passing `limit: nil`, but note that it may take a long time
473
- # to parse.
556
+ # Date.rfc822 is an alias for Date.rfc2822.
557
+ #
558
+ # Related: Date._rfc2822 (returns a hash).
474
559
  #
475
560
  def self.rfc2822: (String str, ?Integer start) -> Date
476
561
 
477
562
  # <!--
478
563
  # rdoc-file=ext/date/date_core.c
479
- # - Date.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> date
564
+ # - Date.rfc3339(string = '-4712-01-01T00:00:00+00:00', start = Date::ITALY, limit: 128) -> date
480
565
  # -->
481
- # Creates a new Date object by parsing from a string according to some typical
482
- # RFC 3339 formats.
566
+ # Returns a new Date object with values parsed from `string`, which should be a
567
+ # valid [RFC 3339 format](rdoc-ref:strftime_formatting.rdoc@RFC+3339+Format):
568
+ #
569
+ # d = Date.new(2001, 2, 3)
570
+ # s = d.rfc3339 # => "2001-02-03T00:00:00+00:00"
571
+ # Date.rfc3339(s) # => #<Date: 2001-02-03>
572
+ #
573
+ # See:
483
574
  #
484
- # Date.rfc3339('2001-02-03T04:05:06+07:00') #=> #<Date: 2001-02-03 ...>
575
+ # * Argument [start](rdoc-ref:calendars.rdoc@Argument+start).
576
+ # * Argument [limit](rdoc-ref:Date@Argument+limit).
485
577
  #
486
- # Raise an ArgumentError when the string length is longer than *limit*. You can
487
- # stop this check by passing `limit: nil`, but note that it may take a long time
488
- # to parse.
578
+ #
579
+ # Related: Date._rfc3339 (returns a hash).
489
580
  #
490
581
  def self.rfc3339: (String str, ?Integer start) -> Date
491
582
 
492
583
  # <!--
493
584
  # rdoc-file=ext/date/date_core.c
494
- # - Date.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> date
495
- # - Date.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> date
585
+ # - Date.rfc2822(string = 'Mon, 1 Jan -4712 00:00:00 +0000', start = Date::ITALY, limit: 128) -> date
496
586
  # -->
497
- # Creates a new Date object by parsing from a string according to some typical
498
- # RFC 2822 formats.
587
+ # Returns a new Date object with values parsed from `string`, which should be a
588
+ # valid [RFC 2822 date
589
+ # format](rdoc-ref:strftime_formatting.rdoc@RFC+2822+Format):
590
+ #
591
+ # d = Date.new(2001, 2, 3)
592
+ # s = d.rfc2822 # => "Sat, 3 Feb 2001 00:00:00 +0000"
593
+ # Date.rfc2822(s) # => #<Date: 2001-02-03>
499
594
  #
500
- # Date.rfc2822('Sat, 3 Feb 2001 00:00:00 +0000')
501
- # #=> #<Date: 2001-02-03 ...>
595
+ # See:
502
596
  #
503
- # Raise an ArgumentError when the string length is longer than *limit*. You can
504
- # stop this check by passing `limit: nil`, but note that it may take a long time
505
- # to parse.
597
+ # * Argument [start](rdoc-ref:calendars.rdoc@Argument+start).
598
+ # * Argument [limit](rdoc-ref:Date@Argument+limit).
599
+ #
600
+ #
601
+ # Date.rfc822 is an alias for Date.rfc2822.
602
+ #
603
+ # Related: Date._rfc2822 (returns a hash).
506
604
  #
507
605
  def self.rfc822: (String str, ?Integer start) -> Date
508
606
 
509
607
  # <!--
510
608
  # rdoc-file=ext/date/date_core.c
511
- # - Date.strptime([string='-4712-01-01'[, format='%F'[, start=Date::ITALY]]]) -> date
609
+ # - Date.strptime(string = '-4712-01-01', format = '%F', start = Date::ITALY) -> date
512
610
  # -->
513
- # Parses the given representation of date and time with the given template, and
514
- # creates a date object. strptime does not support specification of flags and
515
- # width unlike strftime.
611
+ # Returns a new Date object with values parsed from `string`, according to the
612
+ # given `format`:
613
+ #
614
+ # Date.strptime('2001-02-03', '%Y-%m-%d') # => #<Date: 2001-02-03>
615
+ # Date.strptime('03-02-2001', '%d-%m-%Y') # => #<Date: 2001-02-03>
616
+ # Date.strptime('2001-034', '%Y-%j') # => #<Date: 2001-02-03>
617
+ # Date.strptime('2001-W05-6', '%G-W%V-%u') # => #<Date: 2001-02-03>
618
+ # Date.strptime('2001 04 6', '%Y %U %w') # => #<Date: 2001-02-03>
619
+ # Date.strptime('2001 05 6', '%Y %W %u') # => #<Date: 2001-02-03>
620
+ # Date.strptime('sat3feb01', '%a%d%b%y') # => #<Date: 2001-02-03>
621
+ #
622
+ # For other formats, see [Formats for Dates and
623
+ # Times](rdoc-ref:strftime_formatting.rdoc). (Unlike Date.strftime, does not
624
+ # support flags and width.)
625
+ #
626
+ # See argument [start](rdoc-ref:calendars.rdoc@Argument+start).
516
627
  #
517
- # Date.strptime('2001-02-03', '%Y-%m-%d') #=> #<Date: 2001-02-03 ...>
518
- # Date.strptime('03-02-2001', '%d-%m-%Y') #=> #<Date: 2001-02-03 ...>
519
- # Date.strptime('2001-034', '%Y-%j') #=> #<Date: 2001-02-03 ...>
520
- # Date.strptime('2001-W05-6', '%G-W%V-%u') #=> #<Date: 2001-02-03 ...>
521
- # Date.strptime('2001 04 6', '%Y %U %w') #=> #<Date: 2001-02-03 ...>
522
- # Date.strptime('2001 05 6', '%Y %W %u') #=> #<Date: 2001-02-03 ...>
523
- # Date.strptime('sat3feb01', '%a%d%b%y') #=> #<Date: 2001-02-03 ...>
628
+ # See also [strptime(3)](https://man7.org/linux/man-pages/man3/strptime.3.html).
524
629
  #
525
- # See also strptime(3) and #strftime.
630
+ # Related: Date._strptime (returns a hash).
526
631
  #
527
632
  def self.strptime: (String str, ?String format, ?Integer start) -> Date
528
633
 
529
634
  # <!--
530
635
  # rdoc-file=ext/date/date_core.c
531
- # - Date.today([start=Date::ITALY]) -> date
636
+ # - Date.today(start = Date::ITALY) -> date
532
637
  # -->
533
- # Creates a date object denoting the present day.
638
+ # Returns a new Date object constructed from the present date:
534
639
  #
535
- # Date.today #=> #<Date: 2011-06-11 ...>
640
+ # Date.today.to_s # => "2022-07-06"
641
+ #
642
+ # See argument [start](rdoc-ref:calendars.rdoc@Argument+start).
536
643
  #
537
644
  def self.today: (?Integer start) -> Date
538
645
 
539
646
  # <!--
540
647
  # rdoc-file=ext/date/date_core.c
541
- # - Date.valid_civil?(year, month, mday[, start=Date::ITALY]) -> bool
542
- # - Date.valid_date?(year, month, mday[, start=Date::ITALY]) -> bool
648
+ # - Date.valid_civil?(year, month, mday, start = Date::ITALY) -> true or false
543
649
  # -->
544
- # Returns true if the given calendar date is valid, and false if not. Valid in
545
- # this context is whether the arguments passed to this method would be accepted
546
- # by ::new.
650
+ # Returns `true` if the arguments define a valid ordinal date, `false`
651
+ # otherwise:
652
+ #
653
+ # Date.valid_date?(2001, 2, 3) # => true
654
+ # Date.valid_date?(2001, 2, 29) # => false
655
+ # Date.valid_date?(2001, 2, -1) # => true
656
+ #
657
+ # See argument [start](rdoc-ref:calendars.rdoc@Argument+start).
547
658
  #
548
- # Date.valid_date?(2001,2,3) #=> true
549
- # Date.valid_date?(2001,2,29) #=> false
550
- # Date.valid_date?(2001,2,-1) #=> true
659
+ # Date.valid_date? is an alias for Date.valid_civil?.
551
660
  #
552
- # See also ::jd and ::civil.
661
+ # Related: Date.jd, Date.new.
553
662
  #
554
663
  def self.valid_civil?: (Integer year, Integer month, Integer mday, ?Integer start) -> bool
555
664
 
556
665
  # <!--
557
666
  # rdoc-file=ext/date/date_core.c
558
- # - Date.valid_commercial?(cwyear, cweek, cwday[, start=Date::ITALY]) -> bool
667
+ # - Date.valid_commercial?(cwyear, cweek, cwday, start = Date::ITALY) -> true or false
559
668
  # -->
560
- # Returns true if the given week date is valid, and false if not.
669
+ # Returns `true` if the arguments define a valid commercial date, `false`
670
+ # otherwise:
561
671
  #
562
- # Date.valid_commercial?(2001,5,6) #=> true
563
- # Date.valid_commercial?(2001,5,8) #=> false
672
+ # Date.valid_commercial?(2001, 5, 6) # => true
673
+ # Date.valid_commercial?(2001, 5, 8) # => false
564
674
  #
565
- # See also ::jd and ::commercial.
675
+ # See Date.commercial.
676
+ #
677
+ # See argument [start](rdoc-ref:calendars.rdoc@Argument+start).
678
+ #
679
+ # Related: Date.jd, Date.commercial.
566
680
  #
567
681
  def self.valid_commercial?: (Integer cwyear, Integer cweek, Integer cwday, ?Integer start) -> bool
568
682
 
569
683
  # <!--
570
684
  # rdoc-file=ext/date/date_core.c
571
- # - Date.valid_civil?(year, month, mday[, start=Date::ITALY]) -> bool
572
- # - Date.valid_date?(year, month, mday[, start=Date::ITALY]) -> bool
685
+ # - Date.valid_civil?(year, month, mday, start = Date::ITALY) -> true or false
573
686
  # -->
574
- # Returns true if the given calendar date is valid, and false if not. Valid in
575
- # this context is whether the arguments passed to this method would be accepted
576
- # by ::new.
687
+ # Returns `true` if the arguments define a valid ordinal date, `false`
688
+ # otherwise:
689
+ #
690
+ # Date.valid_date?(2001, 2, 3) # => true
691
+ # Date.valid_date?(2001, 2, 29) # => false
692
+ # Date.valid_date?(2001, 2, -1) # => true
577
693
  #
578
- # Date.valid_date?(2001,2,3) #=> true
579
- # Date.valid_date?(2001,2,29) #=> false
580
- # Date.valid_date?(2001,2,-1) #=> true
694
+ # See argument [start](rdoc-ref:calendars.rdoc@Argument+start).
581
695
  #
582
- # See also ::jd and ::civil.
696
+ # Date.valid_date? is an alias for Date.valid_civil?.
697
+ #
698
+ # Related: Date.jd, Date.new.
583
699
  #
584
700
  def self.valid_date?: (Integer year, Integer month, Integer mday, ?Integer start) -> bool
585
701
 
586
702
  # <!--
587
703
  # rdoc-file=ext/date/date_core.c
588
- # - Date.valid_jd?(jd[, start=Date::ITALY]) -> bool
704
+ # - Date.valid_jd?(jd, start = Date::ITALY) -> true
589
705
  # -->
590
- # Just returns true. It's nonsense, but is for symmetry.
706
+ # Implemented for compatibility; returns `true` unless `jd` is invalid (i.e.,
707
+ # not a Numeric).
708
+ #
709
+ # Date.valid_jd?(2451944) # => true
591
710
  #
592
- # Date.valid_jd?(2451944) #=> true
711
+ # See argument [start](rdoc-ref:calendars.rdoc@Argument+start).
593
712
  #
594
- # See also ::jd.
713
+ # Related: Date.jd.
595
714
  #
596
715
  def self.valid_jd?: (Integer jd, ?Integer start) -> bool
597
716
 
598
717
  # <!--
599
718
  # rdoc-file=ext/date/date_core.c
600
- # - Date.valid_ordinal?(year, yday[, start=Date::ITALY]) -> bool
719
+ # - Date.valid_ordinal?(year, yday, start = Date::ITALY) -> true or false
601
720
  # -->
602
- # Returns true if the given ordinal date is valid, and false if not.
721
+ # Returns `true` if the arguments define a valid ordinal date, `false`
722
+ # otherwise:
723
+ #
724
+ # Date.valid_ordinal?(2001, 34) # => true
725
+ # Date.valid_ordinal?(2001, 366) # => false
603
726
  #
604
- # Date.valid_ordinal?(2001,34) #=> true
605
- # Date.valid_ordinal?(2001,366) #=> false
727
+ # See argument [start](rdoc-ref:calendars.rdoc@Argument+start).
606
728
  #
607
- # See also ::jd and ::ordinal.
729
+ # Related: Date.jd, Date.ordinal.
608
730
  #
609
731
  def self.valid_ordinal?: (Integer year, Integer yday, ?Integer start) -> bool
610
732
 
611
733
  # <!--
612
734
  # rdoc-file=ext/date/date_core.c
613
- # - Date.xmlschema(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
735
+ # - Date.xmlschema(string = '-4712-01-01', start = Date::ITALY, limit: 128) -> date
614
736
  # -->
615
- # Creates a new Date object by parsing from a string according to some typical
616
- # XML Schema formats.
737
+ # Returns a new Date object with values parsed from `string`, which should be a
738
+ # valid XML date format:
739
+ #
740
+ # d = Date.new(2001, 2, 3)
741
+ # s = d.xmlschema # => "2001-02-03"
742
+ # Date.xmlschema(s) # => #<Date: 2001-02-03>
743
+ #
744
+ # See:
745
+ #
746
+ # * Argument [start](rdoc-ref:calendars.rdoc@Argument+start).
747
+ # * Argument [limit](rdoc-ref:Date@Argument+limit).
617
748
  #
618
- # Date.xmlschema('2001-02-03') #=> #<Date: 2001-02-03 ...>
619
749
  #
620
- # Raise an ArgumentError when the string length is longer than *limit*. You can
621
- # stop this check by passing `limit: nil`, but note that it may take a long time
622
- # to parse.
750
+ # Related: Date._xmlschema (returns a hash).
623
751
  #
624
752
  def self.xmlschema: (String str, ?Integer start) -> Date
625
753
 
@@ -667,85 +795,134 @@ class Date
667
795
  # rdoc-file=ext/date/date_core.c
668
796
  # - d << n -> date
669
797
  # -->
670
- # Returns a date object pointing `n` months before self. The argument `n` should
671
- # be a numeric value.
798
+ # Returns a new Date object representing the date `n` months earlier; `n` should
799
+ # be a numeric:
672
800
  #
673
- # Date.new(2001,2,3) << 1 #=> #<Date: 2001-01-03 ...>
674
- # Date.new(2001,2,3) << -2 #=> #<Date: 2001-04-03 ...>
801
+ # (Date.new(2001, 2, 3) << 1).to_s # => "2001-01-03"
802
+ # (Date.new(2001, 2, 3) << -2).to_s # => "2001-04-03"
675
803
  #
676
- # When the same day does not exist for the corresponding month, the last day of
677
- # the month is used instead:
804
+ # When the same day does not exist for the new month, the last day of that month
805
+ # is used instead:
678
806
  #
679
- # Date.new(2001,3,28) << 1 #=> #<Date: 2001-02-28 ...>
680
- # Date.new(2001,3,31) << 1 #=> #<Date: 2001-02-28 ...>
807
+ # (Date.new(2001, 3, 31) << 1).to_s # => "2001-02-28"
808
+ # (Date.new(2001, 3, 31) << -6).to_s # => "2001-09-30"
681
809
  #
682
- # This also results in the following, possibly unexpected, behavior:
810
+ # This results in the following, possibly unexpected, behaviors:
683
811
  #
684
- # Date.new(2001,3,31) << 2 #=> #<Date: 2001-01-31 ...>
685
- # Date.new(2001,3,31) << 1 << 1 #=> #<Date: 2001-01-28 ...>
812
+ # d0 = Date.new(2001, 3, 31)
813
+ # d0 << 2 # => #<Date: 2001-01-31>
814
+ # d0 << 1 << 1 # => #<Date: 2001-01-28>
686
815
  #
687
- # Date.new(2001,3,31) << 1 << -1 #=> #<Date: 2001-03-28 ...>
816
+ # d0 = Date.new(2001, 3, 31)
817
+ # d1 = d0 << 1 # => #<Date: 2001-02-28>
818
+ # d2 = d1 << -1 # => #<Date: 2001-03-28>
688
819
  #
689
820
  def <<: (Integer month) -> Date
690
821
 
691
822
  # <!--
692
823
  # rdoc-file=ext/date/date_core.c
693
- # - d <=> other -> -1, 0, +1 or nil
824
+ # - self <=> other -> -1, 0, 1 or nil
694
825
  # -->
695
- # Compares the two dates and returns -1, zero, 1 or nil. The other should be a
696
- # date object or a numeric value as an astronomical Julian day number.
826
+ # Compares `self` and `other`, returning:
827
+ #
828
+ # * `-1` if `other` is larger.
829
+ # * `0` if the two are equal.
830
+ # * `1` if `other` is smaller.
831
+ # * `nil` if the two are incomparable.
832
+ #
833
+ #
834
+ # Argument `other` may be:
835
+ #
836
+ # * Another Date object:
837
+ #
838
+ # d = Date.new(2022, 7, 27) # => #<Date: 2022-07-27 ((2459788j,0s,0n),+0s,2299161j)>
839
+ # prev_date = d.prev_day # => #<Date: 2022-07-26 ((2459787j,0s,0n),+0s,2299161j)>
840
+ # next_date = d.next_day # => #<Date: 2022-07-28 ((2459789j,0s,0n),+0s,2299161j)>
841
+ # d <=> next_date # => -1
842
+ # d <=> d # => 0
843
+ # d <=> prev_date # => 1
697
844
  #
698
- # Date.new(2001,2,3) <=> Date.new(2001,2,4) #=> -1
699
- # Date.new(2001,2,3) <=> Date.new(2001,2,3) #=> 0
700
- # Date.new(2001,2,3) <=> Date.new(2001,2,2) #=> 1
701
- # Date.new(2001,2,3) <=> Object.new #=> nil
702
- # Date.new(2001,2,3) <=> Rational(4903887,2) #=> 0
845
+ # * A DateTime object:
703
846
  #
704
- # See also Comparable.
847
+ # d <=> DateTime.new(2022, 7, 26) # => 1
848
+ # d <=> DateTime.new(2022, 7, 27) # => 0
849
+ # d <=> DateTime.new(2022, 7, 28) # => -1
850
+ #
851
+ # * A numeric (compares `self.ajd` to `other`):
852
+ #
853
+ # d <=> 2459788 # => -1
854
+ # d <=> 2459787 # => 1
855
+ # d <=> 2459786 # => 1
856
+ # d <=> d.ajd # => 0
857
+ #
858
+ # * Any other object:
859
+ #
860
+ # d <=> Object.new # => nil
705
861
  #
706
862
  def <=>: (untyped other) -> Integer?
707
863
 
708
864
  # <!--
709
865
  # rdoc-file=ext/date/date_core.c
710
- # - d === other -> bool
866
+ # - self === other -> true, false, or nil.
711
867
  # -->
712
- # Returns true if they are the same day.
868
+ # Returns `true` if `self` and `other` represent the same date, `false` if not,
869
+ # `nil` if the two are not comparable.
870
+ #
871
+ # Argument `other` may be:
872
+ #
873
+ # * Another Date object:
874
+ #
875
+ # d = Date.new(2022, 7, 27) # => #<Date: 2022-07-27 ((2459788j,0s,0n),+0s,2299161j)>
876
+ # prev_date = d.prev_day # => #<Date: 2022-07-26 ((2459787j,0s,0n),+0s,2299161j)>
877
+ # next_date = d.next_day # => #<Date: 2022-07-28 ((2459789j,0s,0n),+0s,2299161j)>
878
+ # d === prev_date # => false
879
+ # d === d # => true
880
+ # d === next_date # => false
881
+ #
882
+ # * A DateTime object:
883
+ #
884
+ # d === DateTime.new(2022, 7, 26) # => false
885
+ # d === DateTime.new(2022, 7, 27) # => true
886
+ # d === DateTime.new(2022, 7, 28) # => false
887
+ #
888
+ # * A numeric (compares `self.jd` to `other`):
889
+ #
890
+ # d === 2459788 # => true
891
+ # d === 2459787 # => false
892
+ # d === 2459786 # => false
893
+ # d === d.jd # => true
894
+ #
895
+ # * An object not comparable:
713
896
  #
714
- # Date.new(2001,2,3) === Date.new(2001,2,3)
715
- # #=> true
716
- # Date.new(2001,2,3) === Date.new(2001,2,4)
717
- # #=> false
718
- # DateTime.new(2001,2,3) === DateTime.new(2001,2,3,12)
719
- # #=> true
720
- # DateTime.new(2001,2,3) === DateTime.new(2001,2,3,0,0,0,'+24:00')
721
- # #=> true
722
- # DateTime.new(2001,2,3) === DateTime.new(2001,2,4,0,0,0,'+24:00')
723
- # #=> false
897
+ # d === Object.new # => nil
724
898
  #
725
899
  def ===: (Date other) -> bool
726
900
 
727
901
  # <!--
728
902
  # rdoc-file=ext/date/date_core.c
729
- # - d >> n -> date
903
+ # - d >> n -> new_date
730
904
  # -->
731
- # Returns a date object pointing `n` months after self. The argument `n` should
732
- # be a numeric value.
905
+ # Returns a new Date object representing the date `n` months later; `n` should
906
+ # be a numeric:
733
907
  #
734
- # Date.new(2001,2,3) >> 1 #=> #<Date: 2001-03-03 ...>
735
- # Date.new(2001,2,3) >> -2 #=> #<Date: 2000-12-03 ...>
908
+ # (Date.new(2001, 2, 3) >> 1).to_s # => "2001-03-03"
909
+ # (Date.new(2001, 2, 3) >> -2).to_s # => "2000-12-03"
736
910
  #
737
- # When the same day does not exist for the corresponding month, the last day of
738
- # the month is used instead:
911
+ # When the same day does not exist for the new month, the last day of that month
912
+ # is used instead:
739
913
  #
740
- # Date.new(2001,1,28) >> 1 #=> #<Date: 2001-02-28 ...>
741
- # Date.new(2001,1,31) >> 1 #=> #<Date: 2001-02-28 ...>
914
+ # (Date.new(2001, 1, 31) >> 1).to_s # => "2001-02-28"
915
+ # (Date.new(2001, 1, 31) >> -4).to_s # => "2000-09-30"
742
916
  #
743
- # This also results in the following, possibly unexpected, behavior:
917
+ # This results in the following, possibly unexpected, behaviors:
744
918
  #
745
- # Date.new(2001,1,31) >> 2 #=> #<Date: 2001-03-31 ...>
746
- # Date.new(2001,1,31) >> 1 >> 1 #=> #<Date: 2001-03-28 ...>
919
+ # d0 = Date.new(2001, 1, 31)
920
+ # d1 = d0 >> 1 # => #<Date: 2001-02-28>
921
+ # d2 = d1 >> 1 # => #<Date: 2001-03-28>
747
922
  #
748
- # Date.new(2001,1,31) >> 1 >> -1 #=> #<Date: 2001-01-28 ...>
923
+ # d0 = Date.new(2001, 1, 31)
924
+ # d1 = d0 >> 1 # => #<Date: 2001-02-28>
925
+ # d2 = d1 >> -1 # => #<Date: 2001-01-28>
749
926
  #
750
927
  def >>: (Integer month) -> Date
751
928
 
@@ -775,143 +952,194 @@ class Date
775
952
 
776
953
  # <!--
777
954
  # rdoc-file=ext/date/date_core.c
778
- # - d.asctime -> string
779
- # - d.ctime -> string
955
+ # - asctime -> string
780
956
  # -->
781
- # Returns a string in asctime(3) format (but without "n\0" at the end). This
782
- # method is equivalent to strftime('%c').
957
+ # Equivalent to #strftime with argument `'%a %b %e %T %Y'` (or its [shorthand
958
+ # form](rdoc-ref:strftime_formatting.rdoc@Shorthand+Conversion+Specifiers)
959
+ # `'%c'`):
783
960
  #
784
- # See also asctime(3) or ctime(3).
961
+ # Date.new(2001, 2, 3).asctime # => "Sat Feb 3 00:00:00 2001"
962
+ #
963
+ # See [asctime](https://linux.die.net/man/3/asctime).
964
+ #
965
+ # Date#ctime is an alias for Date#asctime.
785
966
  #
786
967
  def asctime: () -> String
787
968
 
788
969
  # <!-- rdoc-file=ext/date/date_core.c -->
789
- # Returns a string in asctime(3) format (but without "n\0" at the end). This
790
- # method is equivalent to strftime('%c').
970
+ # Equivalent to #strftime with argument `'%a %b %e %T %Y'` (or its [shorthand
971
+ # form](rdoc-ref:strftime_formatting.rdoc@Shorthand+Conversion+Specifiers)
972
+ # `'%c'`):
973
+ #
974
+ # Date.new(2001, 2, 3).asctime # => "Sat Feb 3 00:00:00 2001"
791
975
  #
792
- # See also asctime(3) or ctime(3).
976
+ # See [asctime](https://linux.die.net/man/3/asctime).
977
+ #
978
+ # Date#ctime is an alias for Date#asctime.
793
979
  #
794
980
  def ctime: () -> String
795
981
 
796
982
  # <!--
797
983
  # rdoc-file=ext/date/date_core.c
798
- # - d.cwday -> fixnum
984
+ # - cwday -> integer
799
985
  # -->
800
- # Returns the day of calendar week (1-7, Monday is 1).
986
+ # Returns the commercial-date weekday index for `self` (see Date.commercial); 1
987
+ # is Monday:
801
988
  #
802
- # Date.new(2001,2,3).cwday #=> 6
989
+ # Date.new(2001, 2, 3).cwday # => 6
803
990
  #
804
991
  def cwday: () -> Integer
805
992
 
806
993
  # <!--
807
994
  # rdoc-file=ext/date/date_core.c
808
- # - d.cweek -> fixnum
995
+ # - cweek -> integer
809
996
  # -->
810
- # Returns the calendar week number (1-53).
997
+ # Returns commercial-date week index for `self` (see Date.commercial):
811
998
  #
812
- # Date.new(2001,2,3).cweek #=> 5
999
+ # Date.new(2001, 2, 3).cweek # => 5
813
1000
  #
814
1001
  def cweek: () -> Integer
815
1002
 
816
1003
  # <!--
817
1004
  # rdoc-file=ext/date/date_core.c
818
- # - d.cwyear -> integer
1005
+ # - cwyear -> integer
819
1006
  # -->
820
- # Returns the calendar week based year.
1007
+ # Returns commercial-date year for `self` (see Date.commercial):
821
1008
  #
822
- # Date.new(2001,2,3).cwyear #=> 2001
823
- # Date.new(2000,1,1).cwyear #=> 1999
1009
+ # Date.new(2001, 2, 3).cwyear # => 2001
1010
+ # Date.new(2000, 1, 1).cwyear # => 1999
824
1011
  #
825
1012
  def cwyear: () -> Integer
826
1013
 
827
1014
  # <!-- rdoc-file=ext/date/date_core.c -->
828
- # Returns the day of the month (1-31).
1015
+ # Returns the day of the month in range (1..31):
1016
+ #
1017
+ # Date.new(2001, 2, 3).mday # => 3
829
1018
  #
830
- # Date.new(2001,2,3).mday #=> 3
1019
+ # Date#day is an alias for Date#mday.
831
1020
  #
832
1021
  def day: () -> Integer
833
1022
 
834
1023
  # <!--
835
1024
  # rdoc-file=ext/date/date_core.c
836
- # - d.downto(min) -> enumerator
837
- # - d.downto(min){|date| ...} -> self
1025
+ # - deconstruct_keys(array_of_names_or_nil) -> hash
1026
+ # -->
1027
+ # Returns a hash of the name/value pairs, to use in pattern matching. Possible
1028
+ # keys are: `:year`, `:month`, `:day`, `:wday`, `:yday`.
1029
+ #
1030
+ # Possible usages:
1031
+ #
1032
+ # d = Date.new(2022, 10, 5)
1033
+ #
1034
+ # if d in wday: 3, day: ..7 # uses deconstruct_keys underneath
1035
+ # puts "first Wednesday of the month"
1036
+ # end
1037
+ # #=> prints "first Wednesday of the month"
1038
+ #
1039
+ # case d
1040
+ # in year: ...2022
1041
+ # puts "too old"
1042
+ # in month: ..9
1043
+ # puts "quarter 1-3"
1044
+ # in wday: 1..5, month:
1045
+ # puts "working day in month #{month}"
1046
+ # end
1047
+ # #=> prints "working day in month 10"
1048
+ #
1049
+ # Note that deconstruction by pattern can also be combined with class check:
1050
+ #
1051
+ # if d in Date(wday: 3, day: ..7)
1052
+ # puts "first Wednesday of the month"
1053
+ # end
1054
+ #
1055
+ def deconstruct_keys: (Array[Symbol]?) -> Hash[Symbol, Integer]
1056
+
1057
+ # <!--
1058
+ # rdoc-file=ext/date/date_core.c
1059
+ # - downto(min){|date| ... } -> self
838
1060
  # -->
839
- # This method is equivalent to step(min, -1){|date| ...}.
1061
+ # Equivalent to #step with arguments `min` and `-1`.
840
1062
  #
841
1063
  def downto: (Date min) { (Date) -> untyped } -> Date
842
1064
  | (Date min) -> Enumerator[Date, Date]
843
1065
 
844
1066
  # <!--
845
1067
  # rdoc-file=ext/date/date_core.c
846
- # - d.england -> date
1068
+ # - england -> new_date
847
1069
  # -->
848
- # This method is equivalent to new_start(Date::ENGLAND).
1070
+ # Equivalent to Date#new_start with argument Date::ENGLAND.
849
1071
  #
850
1072
  def england: () -> Date
851
1073
 
852
1074
  # <!--
853
1075
  # rdoc-file=ext/date/date_core.c
854
- # - d.friday? -> bool
1076
+ # - friday? -> true or false
855
1077
  # -->
856
- # Returns true if the date is Friday.
1078
+ # Returns `true` if `self` is a Friday, `false` otherwise.
857
1079
  #
858
1080
  def friday?: () -> bool
859
1081
 
860
1082
  # <!--
861
1083
  # rdoc-file=ext/date/date_core.c
862
- # - d.gregorian -> date
1084
+ # - gregorian -> new_date
863
1085
  # -->
864
- # This method is equivalent to new_start(Date::GREGORIAN).
1086
+ # Equivalent to Date#new_start with argument Date::GREGORIAN.
865
1087
  #
866
1088
  def gregorian: () -> Date
867
1089
 
868
1090
  # <!--
869
1091
  # rdoc-file=ext/date/date_core.c
870
- # - d.gregorian? -> bool
1092
+ # - gregorian? -> true or false
871
1093
  # -->
872
- # Returns true if the date is on or after the day of calendar reform.
1094
+ # Returns `true` if the date is on or after the date of calendar reform, `false`
1095
+ # otherwise:
873
1096
  #
874
- # Date.new(1582,10,15).gregorian? #=> true
875
- # (Date.new(1582,10,15) - 1).gregorian? #=> false
1097
+ # Date.new(1582, 10, 15).gregorian? # => true
1098
+ # (Date.new(1582, 10, 15) - 1).gregorian? # => false
876
1099
  #
877
1100
  def gregorian?: () -> bool
878
1101
 
879
1102
  # <!--
880
1103
  # rdoc-file=ext/date/date_core.c
881
- # - d.httpdate -> string
1104
+ # - httpdate -> string
882
1105
  # -->
883
- # This method is equivalent to strftime('%a, %d %b %Y %T GMT'). See also RFC
884
- # 2616.
1106
+ # Equivalent to #strftime with argument `'%a, %d %b %Y %T GMT'`; see [Formats
1107
+ # for Dates and Times](rdoc-ref:strftime_formatting.rdoc):
1108
+ #
1109
+ # Date.new(2001, 2, 3).httpdate # => "Sat, 03 Feb 2001 00:00:00 GMT"
885
1110
  #
886
1111
  def httpdate: () -> String
887
1112
 
888
1113
  # <!--
889
1114
  # rdoc-file=ext/date/date_core.c
890
- # - d.inspect -> string
1115
+ # - inspect -> string
891
1116
  # -->
892
- # Returns the value as a string for inspection.
1117
+ # Returns a string representation of `self`:
893
1118
  #
894
- # Date.new(2001,2,3).inspect
895
- # #=> "#<Date: 2001-02-03>"
896
- # DateTime.new(2001,2,3,4,5,6,'-7').inspect
897
- # #=> "#<DateTime: 2001-02-03T04:05:06-07:00>"
1119
+ # Date.new(2001, 2, 3).inspect
1120
+ # # => "#<Date: 2001-02-03 ((2451944j,0s,0n),+0s,2299161j)>"
898
1121
  #
899
1122
  def inspect: () -> String
900
1123
 
901
1124
  # <!--
902
1125
  # rdoc-file=ext/date/date_core.c
903
- # - d.iso8601 -> string
904
- # - d.xmlschema -> string
1126
+ # - iso8601 -> string
905
1127
  # -->
906
- # This method is equivalent to strftime('%F').
1128
+ # Equivalent to #strftime with argument `'%Y-%m-%d'` (or its [shorthand
1129
+ # form](rdoc-ref:strftime_formatting.rdoc@Shorthand+Conversion+Specifiers)
1130
+ # `'%F'`);
1131
+ #
1132
+ # Date.new(2001, 2, 3).iso8601 # => "2001-02-03"
1133
+ #
1134
+ # Date#xmlschema is an alias for Date#iso8601.
907
1135
  #
908
1136
  def iso8601: () -> String
909
1137
 
910
1138
  # <!--
911
1139
  # rdoc-file=ext/date/date_core.c
912
- # - d.italy -> date
1140
+ # - italy -> new_date
913
1141
  # -->
914
- # This method is equivalent to new_start(Date::ITALY).
1142
+ # Equivalent to Date#new_start with argument Date::ITALY.
915
1143
  #
916
1144
  def italy: () -> Date
917
1145
 
@@ -929,63 +1157,66 @@ class Date
929
1157
 
930
1158
  # <!--
931
1159
  # rdoc-file=ext/date/date_core.c
932
- # - d.jisx0301 -> string
1160
+ # - jisx0301 -> string
933
1161
  # -->
934
- # Returns a string in a JIS X 0301 format.
1162
+ # Returns a string representation of the date in `self` in JIS X 0301 format.
935
1163
  #
936
- # Date.new(2001,2,3).jisx0301 #=> "H13.02.03"
1164
+ # Date.new(2001, 2, 3).jisx0301 # => "H13.02.03"
937
1165
  #
938
1166
  def jisx0301: () -> String
939
1167
 
940
1168
  # <!--
941
1169
  # rdoc-file=ext/date/date_core.c
942
- # - d.julian -> date
1170
+ # - julian -> new_date
943
1171
  # -->
944
- # This method is equivalent to new_start(Date::JULIAN).
1172
+ # Equivalent to Date#new_start with argument Date::JULIAN.
945
1173
  #
946
1174
  def julian: () -> Date
947
1175
 
948
1176
  # <!--
949
1177
  # rdoc-file=ext/date/date_core.c
950
- # - d.julian? -> bool
1178
+ # - d.julian? -> true or false
951
1179
  # -->
952
- # Returns true if the date is before the day of calendar reform.
1180
+ # Returns `true` if the date is before the date of calendar reform, `false`
1181
+ # otherwise:
953
1182
  #
954
- # Date.new(1582,10,15).julian? #=> false
955
- # (Date.new(1582,10,15) - 1).julian? #=> true
1183
+ # (Date.new(1582, 10, 15) - 1).julian? # => true
1184
+ # Date.new(1582, 10, 15).julian? # => false
956
1185
  #
957
1186
  def julian?: () -> bool
958
1187
 
959
1188
  # <!--
960
1189
  # rdoc-file=ext/date/date_core.c
961
- # - d.ld -> integer
1190
+ # - ld -> integer
962
1191
  # -->
963
- # Returns the Lilian day number. This is a whole number, which is adjusted by
964
- # the offset as the local time.
1192
+ # Returns the [Lilian day number](https://en.wikipedia.org/wiki/Lilian_date),
1193
+ # which is the number of days since the beginning of the Gregorian calendar,
1194
+ # October 15, 1582.
965
1195
  #
966
- # Date.new(2001,2,3).ld #=> 152784
1196
+ # Date.new(2001, 2, 3).ld # => 152784
967
1197
  #
968
1198
  def ld: () -> Integer
969
1199
 
970
1200
  # <!--
971
1201
  # rdoc-file=ext/date/date_core.c
972
- # - d.leap? -> bool
1202
+ # - leap? -> true or false
973
1203
  # -->
974
- # Returns true if the year is a leap year.
1204
+ # Returns `true` if the year is a leap year, `false` otherwise:
975
1205
  #
976
- # Date.new(2000).leap? #=> true
977
- # Date.new(2001).leap? #=> false
1206
+ # Date.new(2000).leap? # => true
1207
+ # Date.new(2001).leap? # => false
978
1208
  #
979
1209
  def leap?: () -> bool
980
1210
 
981
1211
  # <!--
982
1212
  # rdoc-file=ext/date/date_core.c
983
- # - d.mday -> fixnum
984
- # - d.day -> fixnum
1213
+ # - mday -> integer
985
1214
  # -->
986
- # Returns the day of the month (1-31).
1215
+ # Returns the day of the month in range (1..31):
987
1216
  #
988
- # Date.new(2001,2,3).mday #=> 3
1217
+ # Date.new(2001, 2, 3).mday # => 3
1218
+ #
1219
+ # Date#day is an alias for Date#mday.
989
1220
  #
990
1221
  def mday: () -> Integer
991
1222
 
@@ -1003,376 +1234,264 @@ class Date
1003
1234
 
1004
1235
  # <!--
1005
1236
  # rdoc-file=ext/date/date_core.c
1006
- # - d.mon -> fixnum
1007
- # - d.month -> fixnum
1237
+ # - mon -> integer
1008
1238
  # -->
1009
- # Returns the month (1-12).
1239
+ # Returns the month in range (1..12):
1240
+ #
1241
+ # Date.new(2001, 2, 3).mon # => 2
1010
1242
  #
1011
- # Date.new(2001,2,3).mon #=> 2
1243
+ # Date#month is an alias for Date#mon.
1012
1244
  #
1013
1245
  def mon: () -> Integer
1014
1246
 
1015
1247
  # <!--
1016
1248
  # rdoc-file=ext/date/date_core.c
1017
- # - d.monday? -> bool
1249
+ # - monday? -> true or false
1018
1250
  # -->
1019
- # Returns true if the date is Monday.
1251
+ # Returns `true` if `self` is a Monday, `false` otherwise.
1020
1252
  #
1021
1253
  def monday?: () -> bool
1022
1254
 
1023
1255
  # <!-- rdoc-file=ext/date/date_core.c -->
1024
- # Returns the month (1-12).
1256
+ # Returns the month in range (1..12):
1257
+ #
1258
+ # Date.new(2001, 2, 3).mon # => 2
1025
1259
  #
1026
- # Date.new(2001,2,3).mon #=> 2
1260
+ # Date#month is an alias for Date#mon.
1027
1261
  #
1028
1262
  def month: () -> Integer
1029
1263
 
1030
1264
  # <!--
1031
1265
  # rdoc-file=ext/date/date_core.c
1032
- # - d.new_start([start=Date::ITALY]) -> date
1266
+ # - new_start(start = Date::ITALY]) -> new_date
1033
1267
  # -->
1034
- # Duplicates self and resets its day of calendar reform.
1268
+ # Returns a copy of `self` with the given `start` value:
1035
1269
  #
1036
- # d = Date.new(1582,10,15)
1037
- # d.new_start(Date::JULIAN) #=> #<Date: 1582-10-05 ...>
1270
+ # d0 = Date.new(2000, 2, 3)
1271
+ # d0.julian? # => false
1272
+ # d1 = d0.new_start(Date::JULIAN)
1273
+ # d1.julian? # => true
1274
+ #
1275
+ # See argument [start](rdoc-ref:calendars.rdoc@Argument+start).
1038
1276
  #
1039
1277
  def new_start: (?Integer start) -> Date
1040
1278
 
1041
1279
  # <!--
1042
1280
  # rdoc-file=ext/date/date_core.c
1043
- # - d.succ -> date
1044
- # - d.next -> date
1281
+ # - d.next -> new_date
1045
1282
  # -->
1046
- # Returns a date object denoting the following day.
1283
+ # Returns a new Date object representing the following day:
1284
+ #
1285
+ # d = Date.new(2001, 2, 3)
1286
+ # d.to_s # => "2001-02-03"
1287
+ # d.next.to_s # => "2001-02-04"
1288
+ #
1289
+ # Date#succ is an alias for Date#next.
1047
1290
  #
1048
1291
  def next: () -> Date
1049
1292
 
1050
1293
  # <!--
1051
1294
  # rdoc-file=ext/date/date_core.c
1052
- # - d.next_day([n=1]) -> date
1295
+ # - next_day(n = 1) -> new_date
1053
1296
  # -->
1054
- # This method is equivalent to d + n.
1297
+ # Equivalent to Date#+ with argument `n`.
1055
1298
  #
1056
1299
  def next_day: (?Integer day) -> Date
1057
1300
 
1058
1301
  # <!--
1059
1302
  # rdoc-file=ext/date/date_core.c
1060
- # - d.next_month([n=1]) -> date
1303
+ # - next_month(n = 1) -> new_date
1061
1304
  # -->
1062
- # This method is equivalent to d >> n.
1063
- #
1064
- # See Date#>> for examples.
1305
+ # Equivalent to #>> with argument `n`.
1065
1306
  #
1066
1307
  def next_month: (?Integer month) -> Date
1067
1308
 
1068
1309
  # <!--
1069
1310
  # rdoc-file=ext/date/date_core.c
1070
- # - d.next_year([n=1]) -> date
1311
+ # - next_year(n = 1) -> new_date
1071
1312
  # -->
1072
- # This method is equivalent to d >> (n * 12).
1073
- #
1074
- # Date.new(2001,2,3).next_year #=> #<Date: 2002-02-03 ...>
1075
- # Date.new(2008,2,29).next_year #=> #<Date: 2009-02-28 ...>
1076
- # Date.new(2008,2,29).next_year(4) #=> #<Date: 2012-02-29 ...>
1077
- #
1078
- # See also Date#>>.
1313
+ # Equivalent to #>> with argument `n * 12`.
1079
1314
  #
1080
1315
  def next_year: (?Integer year) -> Date
1081
1316
 
1082
1317
  # <!--
1083
1318
  # rdoc-file=ext/date/date_core.c
1084
- # - d.prev_day([n=1]) -> date
1319
+ # - prev_day(n = 1) -> new_date
1085
1320
  # -->
1086
- # This method is equivalent to d - n.
1321
+ # Equivalent to Date#- with argument `n`.
1087
1322
  #
1088
1323
  def prev_day: (?Integer day) -> Date
1089
1324
 
1090
1325
  # <!--
1091
1326
  # rdoc-file=ext/date/date_core.c
1092
- # - d.prev_month([n=1]) -> date
1327
+ # - prev_month(n = 1) -> new_date
1093
1328
  # -->
1094
- # This method is equivalent to d << n.
1095
- #
1096
- # See Date#<< for examples.
1329
+ # Equivalent to #<< with argument `n`.
1097
1330
  #
1098
1331
  def prev_month: (?Integer month) -> Date
1099
1332
 
1100
1333
  # <!--
1101
1334
  # rdoc-file=ext/date/date_core.c
1102
- # - d.prev_year([n=1]) -> date
1335
+ # - prev_year(n = 1) -> new_date
1103
1336
  # -->
1104
- # This method is equivalent to d << (n * 12).
1105
- #
1106
- # Date.new(2001,2,3).prev_year #=> #<Date: 2000-02-03 ...>
1107
- # Date.new(2008,2,29).prev_year #=> #<Date: 2007-02-28 ...>
1108
- # Date.new(2008,2,29).prev_year(4) #=> #<Date: 2004-02-29 ...>
1109
- #
1110
- # See also Date#<<.
1337
+ # Equivalent to #<< with argument `n * 12`.
1111
1338
  #
1112
1339
  def prev_year: (?Integer year) -> Date
1113
1340
 
1114
1341
  # <!--
1115
1342
  # rdoc-file=ext/date/date_core.c
1116
- # - d.rfc2822 -> string
1117
- # - d.rfc822 -> string
1343
+ # - rfc2822 -> string
1118
1344
  # -->
1119
- # This method is equivalent to strftime('%a, %-d %b %Y %T %z').
1345
+ # Equivalent to #strftime with argument `'%a, %-d %b %Y %T %z'`; see [Formats
1346
+ # for Dates and Times](rdoc-ref:strftime_formatting.rdoc):
1347
+ #
1348
+ # Date.new(2001, 2, 3).rfc2822 # => "Sat, 3 Feb 2001 00:00:00 +0000"
1349
+ #
1350
+ # Date#rfc822 is an alias for Date#rfc2822.
1120
1351
  #
1121
1352
  def rfc2822: () -> String
1122
1353
 
1123
1354
  # <!--
1124
1355
  # rdoc-file=ext/date/date_core.c
1125
- # - d.rfc3339 -> string
1356
+ # - rfc3339 -> string
1126
1357
  # -->
1127
- # This method is equivalent to strftime('%FT%T%:z').
1358
+ # Equivalent to #strftime with argument `'%FT%T%:z'`; see [Formats for Dates and
1359
+ # Times](rdoc-ref:strftime_formatting.rdoc):
1360
+ #
1361
+ # Date.new(2001, 2, 3).rfc3339 # => "2001-02-03T00:00:00+00:00"
1128
1362
  #
1129
1363
  def rfc3339: () -> String
1130
1364
 
1131
1365
  # <!-- rdoc-file=ext/date/date_core.c -->
1132
- # Creates a new Date object by parsing from a string according to some typical
1133
- # RFC 2822 formats.
1366
+ # Returns a new Date object with values parsed from `string`, which should be a
1367
+ # valid [RFC 2822 date
1368
+ # format](rdoc-ref:strftime_formatting.rdoc@RFC+2822+Format):
1369
+ #
1370
+ # d = Date.new(2001, 2, 3)
1371
+ # s = d.rfc2822 # => "Sat, 3 Feb 2001 00:00:00 +0000"
1372
+ # Date.rfc2822(s) # => #<Date: 2001-02-03>
1373
+ #
1374
+ # See:
1134
1375
  #
1135
- # Date.rfc2822('Sat, 3 Feb 2001 00:00:00 +0000')
1136
- # #=> #<Date: 2001-02-03 ...>
1376
+ # * Argument [start](rdoc-ref:calendars.rdoc@Argument+start).
1377
+ # * Argument [limit](rdoc-ref:Date@Argument+limit).
1137
1378
  #
1138
- # Raise an ArgumentError when the string length is longer than *limit*. You can
1139
- # stop this check by passing `limit: nil`, but note that it may take a long time
1140
- # to parse.
1379
+ #
1380
+ # Date.rfc822 is an alias for Date.rfc2822.
1381
+ #
1382
+ # Related: Date._rfc2822 (returns a hash).
1141
1383
  #
1142
1384
  def rfc822: () -> String
1143
1385
 
1144
1386
  # <!--
1145
1387
  # rdoc-file=ext/date/date_core.c
1146
- # - d.saturday? -> bool
1388
+ # - saturday? -> true or false
1147
1389
  # -->
1148
- # Returns true if the date is Saturday.
1390
+ # Returns `true` if `self` is a Saturday, `false` otherwise.
1149
1391
  #
1150
1392
  def saturday?: () -> bool
1151
1393
 
1152
1394
  # <!--
1153
1395
  # rdoc-file=ext/date/date_core.c
1154
- # - d.start -> float
1396
+ # - start -> float
1155
1397
  # -->
1156
- # Returns the Julian day number denoting the day of calendar reform.
1398
+ # Returns the Julian start date for calendar reform; if not an infinity, the
1399
+ # returned value is suitable for passing to Date#jd:
1400
+ #
1401
+ # d = Date.new(2001, 2, 3, Date::ITALY)
1402
+ # s = d.start # => 2299161.0
1403
+ # Date.jd(s).to_s # => "1582-10-15"
1157
1404
  #
1158
- # Date.new(2001,2,3).start #=> 2299161.0
1159
- # Date.new(2001,2,3,Date::GREGORIAN).start #=> -Infinity
1405
+ # d = Date.new(2001, 2, 3, Date::ENGLAND)
1406
+ # s = d.start # => 2361222.0
1407
+ # Date.jd(s).to_s # => "1752-09-14"
1408
+ #
1409
+ # Date.new(2001, 2, 3, Date::GREGORIAN).start # => -Infinity
1410
+ # Date.new(2001, 2, 3, Date::JULIAN).start # => Infinity
1411
+ #
1412
+ # See argument [start](rdoc-ref:calendars.rdoc@Argument+start).
1160
1413
  #
1161
1414
  def start: () -> Float
1162
1415
 
1163
1416
  # <!--
1164
1417
  # rdoc-file=ext/date/date_core.c
1165
- # - d.step(limit[, step=1]) -> enumerator
1166
- # - d.step(limit[, step=1]){|date| ...} -> self
1418
+ # - step(limit, step = 1){|date| ... } -> self
1167
1419
  # -->
1168
- # Iterates evaluation of the given block, which takes a date object. The limit
1169
- # should be a date object.
1420
+ # Calls the block with specified dates; returns `self`.
1421
+ #
1422
+ # * The first `date` is `self`.
1423
+ # * Each successive `date` is `date + step`, where `step` is the numeric step
1424
+ # size in days.
1425
+ # * The last date is the last one that is before or equal to `limit`, which
1426
+ # should be a Date object.
1427
+ #
1428
+ #
1429
+ # Example:
1430
+ #
1431
+ # limit = Date.new(2001, 12, 31)
1432
+ # Date.new(2001).step(limit){|date| p date.to_s if date.mday == 31 }
1170
1433
  #
1171
- # Date.new(2001).step(Date.new(2001,-1,-1)).select{|d| d.sunday?}.size
1172
- # #=> 52
1434
+ # Output:
1435
+ #
1436
+ # "2001-01-31"
1437
+ # "2001-03-31"
1438
+ # "2001-05-31"
1439
+ # "2001-07-31"
1440
+ # "2001-08-31"
1441
+ # "2001-10-31"
1442
+ # "2001-12-31"
1443
+ #
1444
+ # Returns an Enumerator if no block is given.
1173
1445
  #
1174
1446
  def step: (Date limit, ?Integer step) { (Date) -> untyped } -> Date
1175
1447
  | (Date limit, ?Integer step) -> ::Enumerator[Date, Date]
1176
1448
 
1177
1449
  # <!--
1178
1450
  # rdoc-file=ext/date/date_core.c
1179
- # - d.strftime([format='%F']) -> string
1180
- # -->
1181
- # Formats date according to the directives in the given format string. The
1182
- # directives begin with a percent (%) character. Any text not listed as a
1183
- # directive will be passed through to the output string.
1184
- #
1185
- # A directive consists of a percent (%) character, zero or more flags, an
1186
- # optional minimum field width, an optional modifier, and a conversion specifier
1187
- # as follows.
1188
- #
1189
- # %<flags><width><modifier><conversion>
1190
- #
1191
- # Flags:
1192
- # - don't pad a numerical output.
1193
- # _ use spaces for padding.
1194
- # 0 use zeros for padding.
1195
- # ^ upcase the result string.
1196
- # # change case.
1197
- #
1198
- # The minimum field width specifies the minimum width.
1199
- #
1200
- # The modifiers are "E", "O", ":", "::" and ":::". "E" and "O" are ignored. No
1201
- # effect to result currently.
1202
- #
1203
- # Format directives:
1204
- #
1205
- # Date (Year, Month, Day):
1206
- # %Y - Year with century (can be negative, 4 digits at least)
1207
- # -0001, 0000, 1995, 2009, 14292, etc.
1208
- # %C - year / 100 (round down. 20 in 2009)
1209
- # %y - year % 100 (00..99)
1210
- #
1211
- # %m - Month of the year, zero-padded (01..12)
1212
- # %_m blank-padded ( 1..12)
1213
- # %-m no-padded (1..12)
1214
- # %B - The full month name (``January'')
1215
- # %^B uppercased (``JANUARY'')
1216
- # %b - The abbreviated month name (``Jan'')
1217
- # %^b uppercased (``JAN'')
1218
- # %h - Equivalent to %b
1219
- #
1220
- # %d - Day of the month, zero-padded (01..31)
1221
- # %-d no-padded (1..31)
1222
- # %e - Day of the month, blank-padded ( 1..31)
1223
- #
1224
- # %j - Day of the year (001..366)
1225
- #
1226
- # Time (Hour, Minute, Second, Subsecond):
1227
- # %H - Hour of the day, 24-hour clock, zero-padded (00..23)
1228
- # %k - Hour of the day, 24-hour clock, blank-padded ( 0..23)
1229
- # %I - Hour of the day, 12-hour clock, zero-padded (01..12)
1230
- # %l - Hour of the day, 12-hour clock, blank-padded ( 1..12)
1231
- # %P - Meridian indicator, lowercase (``am'' or ``pm'')
1232
- # %p - Meridian indicator, uppercase (``AM'' or ``PM'')
1233
- #
1234
- # %M - Minute of the hour (00..59)
1235
- #
1236
- # %S - Second of the minute (00..60)
1237
- #
1238
- # %L - Millisecond of the second (000..999)
1239
- # %N - Fractional seconds digits, default is 9 digits (nanosecond)
1240
- # %3N millisecond (3 digits) %15N femtosecond (15 digits)
1241
- # %6N microsecond (6 digits) %18N attosecond (18 digits)
1242
- # %9N nanosecond (9 digits) %21N zeptosecond (21 digits)
1243
- # %12N picosecond (12 digits) %24N yoctosecond (24 digits)
1244
- #
1245
- # Time zone:
1246
- # %z - Time zone as hour and minute offset from UTC (e.g. +0900)
1247
- # %:z - hour and minute offset from UTC with a colon (e.g. +09:00)
1248
- # %::z - hour, minute and second offset from UTC (e.g. +09:00:00)
1249
- # %:::z - hour, minute and second offset from UTC
1250
- # (e.g. +09, +09:30, +09:30:30)
1251
- # %Z - Equivalent to %:z (e.g. +09:00)
1252
- #
1253
- # Weekday:
1254
- # %A - The full weekday name (``Sunday'')
1255
- # %^A uppercased (``SUNDAY'')
1256
- # %a - The abbreviated name (``Sun'')
1257
- # %^a uppercased (``SUN'')
1258
- # %u - Day of the week (Monday is 1, 1..7)
1259
- # %w - Day of the week (Sunday is 0, 0..6)
1260
- #
1261
- # ISO 8601 week-based year and week number:
1262
- # The week 1 of YYYY starts with a Monday and includes YYYY-01-04.
1263
- # The days in the year before the first week are in the last week of
1264
- # the previous year.
1265
- # %G - The week-based year
1266
- # %g - The last 2 digits of the week-based year (00..99)
1267
- # %V - Week number of the week-based year (01..53)
1268
- #
1269
- # Week number:
1270
- # The week 1 of YYYY starts with a Sunday or Monday (according to %U
1271
- # or %W). The days in the year before the first week are in week 0.
1272
- # %U - Week number of the year. The week starts with Sunday. (00..53)
1273
- # %W - Week number of the year. The week starts with Monday. (00..53)
1274
- #
1275
- # Seconds since the Unix Epoch:
1276
- # %s - Number of seconds since 1970-01-01 00:00:00 UTC.
1277
- # %Q - Number of milliseconds since 1970-01-01 00:00:00 UTC.
1278
- #
1279
- # Literal string:
1280
- # %n - Newline character (\n)
1281
- # %t - Tab character (\t)
1282
- # %% - Literal ``%'' character
1283
- #
1284
- # Combination:
1285
- # %c - date and time (%a %b %e %T %Y)
1286
- # %D - Date (%m/%d/%y)
1287
- # %F - The ISO 8601 date format (%Y-%m-%d)
1288
- # %v - VMS date (%e-%^b-%Y)
1289
- # %x - Same as %D
1290
- # %X - Same as %T
1291
- # %r - 12-hour time (%I:%M:%S %p)
1292
- # %R - 24-hour time (%H:%M)
1293
- # %T - 24-hour time (%H:%M:%S)
1294
- # %+ - date(1) (%a %b %e %H:%M:%S %Z %Y)
1295
- #
1296
- # This method is similar to the strftime() function defined in ISO C and POSIX.
1297
- # Several directives (%a, %A, %b, %B, %c, %p, %r, %x, %X, %E*, %O* and %Z) are
1298
- # locale dependent in the function. However, this method is locale independent.
1299
- # So, the result may differ even if the same format string is used in other
1300
- # systems such as C. It is good practice to avoid %x and %X because there are
1301
- # corresponding locale independent representations, %D and %T.
1302
- #
1303
- # Examples:
1304
- #
1305
- # d = DateTime.new(2007,11,19,8,37,48,"-06:00")
1306
- # #=> #<DateTime: 2007-11-19T08:37:48-0600 ...>
1307
- # d.strftime("Printed on %m/%d/%Y") #=> "Printed on 11/19/2007"
1308
- # d.strftime("at %I:%M%p") #=> "at 08:37AM"
1309
- #
1310
- # Various ISO 8601 formats:
1311
- # %Y%m%d => 20071119 Calendar date (basic)
1312
- # %F => 2007-11-19 Calendar date (extended)
1313
- # %Y-%m => 2007-11 Calendar date, reduced accuracy, specific month
1314
- # %Y => 2007 Calendar date, reduced accuracy, specific year
1315
- # %C => 20 Calendar date, reduced accuracy, specific century
1316
- # %Y%j => 2007323 Ordinal date (basic)
1317
- # %Y-%j => 2007-323 Ordinal date (extended)
1318
- # %GW%V%u => 2007W471 Week date (basic)
1319
- # %G-W%V-%u => 2007-W47-1 Week date (extended)
1320
- # %GW%V => 2007W47 Week date, reduced accuracy, specific week (basic)
1321
- # %G-W%V => 2007-W47 Week date, reduced accuracy, specific week (extended)
1322
- # %H%M%S => 083748 Local time (basic)
1323
- # %T => 08:37:48 Local time (extended)
1324
- # %H%M => 0837 Local time, reduced accuracy, specific minute (basic)
1325
- # %H:%M => 08:37 Local time, reduced accuracy, specific minute (extended)
1326
- # %H => 08 Local time, reduced accuracy, specific hour
1327
- # %H%M%S,%L => 083748,000 Local time with decimal fraction, comma as decimal sign (basic)
1328
- # %T,%L => 08:37:48,000 Local time with decimal fraction, comma as decimal sign (extended)
1329
- # %H%M%S.%L => 083748.000 Local time with decimal fraction, full stop as decimal sign (basic)
1330
- # %T.%L => 08:37:48.000 Local time with decimal fraction, full stop as decimal sign (extended)
1331
- # %H%M%S%z => 083748-0600 Local time and the difference from UTC (basic)
1332
- # %T%:z => 08:37:48-06:00 Local time and the difference from UTC (extended)
1333
- # %Y%m%dT%H%M%S%z => 20071119T083748-0600 Date and time of day for calendar date (basic)
1334
- # %FT%T%:z => 2007-11-19T08:37:48-06:00 Date and time of day for calendar date (extended)
1335
- # %Y%jT%H%M%S%z => 2007323T083748-0600 Date and time of day for ordinal date (basic)
1336
- # %Y-%jT%T%:z => 2007-323T08:37:48-06:00 Date and time of day for ordinal date (extended)
1337
- # %GW%V%uT%H%M%S%z => 2007W471T083748-0600 Date and time of day for week date (basic)
1338
- # %G-W%V-%uT%T%:z => 2007-W47-1T08:37:48-06:00 Date and time of day for week date (extended)
1339
- # %Y%m%dT%H%M => 20071119T0837 Calendar date and local time (basic)
1340
- # %FT%R => 2007-11-19T08:37 Calendar date and local time (extended)
1341
- # %Y%jT%H%MZ => 2007323T0837Z Ordinal date and UTC of day (basic)
1342
- # %Y-%jT%RZ => 2007-323T08:37Z Ordinal date and UTC of day (extended)
1343
- # %GW%V%uT%H%M%z => 2007W471T0837-0600 Week date and local time and difference from UTC (basic)
1344
- # %G-W%V-%uT%R%:z => 2007-W47-1T08:37-06:00 Week date and local time and difference from UTC (extended)
1345
- #
1346
- # See also strftime(3) and ::strptime.
1451
+ # - strftime(format = '%F') -> string
1452
+ # -->
1453
+ # Returns a string representation of the date in `self`, formatted according the
1454
+ # given `format`:
1455
+ #
1456
+ # Date.new(2001, 2, 3).strftime # => "2001-02-03"
1457
+ #
1458
+ # For other formats, see [Formats for Dates and
1459
+ # Times](rdoc-ref:strftime_formatting.rdoc).
1347
1460
  #
1348
1461
  def strftime: (?String format) -> String
1349
1462
 
1350
1463
  # <!-- rdoc-file=ext/date/date_core.c -->
1351
- # Returns a date object denoting the following day.
1464
+ # Returns a new Date object representing the following day:
1465
+ #
1466
+ # d = Date.new(2001, 2, 3)
1467
+ # d.to_s # => "2001-02-03"
1468
+ # d.next.to_s # => "2001-02-04"
1469
+ #
1470
+ # Date#succ is an alias for Date#next.
1352
1471
  #
1353
1472
  def succ: () -> Date
1354
1473
 
1355
1474
  # <!--
1356
1475
  # rdoc-file=ext/date/date_core.c
1357
- # - d.sunday? -> bool
1476
+ # - sunday? -> true or false
1358
1477
  # -->
1359
- # Returns true if the date is Sunday.
1478
+ # Returns `true` if `self` is a Sunday, `false` otherwise.
1360
1479
  #
1361
1480
  def sunday?: () -> bool
1362
1481
 
1363
1482
  # <!--
1364
1483
  # rdoc-file=ext/date/date_core.c
1365
- # - d.thursday? -> bool
1484
+ # - thursday? -> true or false
1366
1485
  # -->
1367
- # Returns true if the date is Thursday.
1486
+ # Returns `true` if `self` is a Thursday, `false` otherwise.
1368
1487
  #
1369
1488
  def thursday?: () -> bool
1370
1489
 
1371
1490
  # <!--
1372
1491
  # rdoc-file=ext/date/date_core.c
1373
- # - d.to_date -> self
1492
+ # - to_date -> self
1374
1493
  # -->
1375
- # Returns self.
1494
+ # Returns `self`.
1376
1495
  #
1377
1496
  def to_date: () -> Date
1378
1497
 
@@ -1380,89 +1499,100 @@ class Date
1380
1499
  # rdoc-file=ext/date/date_core.c
1381
1500
  # - d.to_datetime -> datetime
1382
1501
  # -->
1383
- # Returns a DateTime object which denotes self.
1502
+ # Returns a DateTime whose value is the same as `self`:
1503
+ #
1504
+ # Date.new(2001, 2, 3).to_datetime # => #<DateTime: 2001-02-03T00:00:00+00:00>
1384
1505
  #
1385
1506
  def to_datetime: () -> DateTime
1386
1507
 
1387
1508
  # <!--
1388
1509
  # rdoc-file=ext/date/date_core.c
1389
- # - d.to_s -> string
1510
+ # - to_s -> string
1390
1511
  # -->
1391
- # Returns a string in an ISO 8601 format. (This method doesn't use the expanded
1392
- # representations.)
1512
+ # Returns a string representation of the date in `self` in [ISO 8601 extended
1513
+ # date format](rdoc-ref:strftime_formatting.rdoc@ISO+8601+Format+Specifications)
1514
+ # (`'%Y-%m-%d'`):
1393
1515
  #
1394
- # Date.new(2001,2,3).to_s #=> "2001-02-03"
1516
+ # Date.new(2001, 2, 3).to_s # => "2001-02-03"
1395
1517
  #
1396
1518
  def to_s: () -> String
1397
1519
 
1398
1520
  # <!--
1399
1521
  # rdoc-file=ext/date/date_core.c
1400
- # - d.to_time -> time
1522
+ # - to_time -> time
1401
1523
  # -->
1402
- # Returns a Time object which denotes self. If self is a julian date, convert it
1403
- # to a gregorian date before converting it to Time.
1524
+ # Returns a new Time object with the same value as `self`; if `self` is a Julian
1525
+ # date, derives its Gregorian date for conversion to the Time object:
1526
+ #
1527
+ # Date.new(2001, 2, 3).to_time # => 2001-02-03 00:00:00 -0600
1528
+ # Date.new(2001, 2, 3, Date::JULIAN).to_time # => 2001-02-16 00:00:00 -0600
1404
1529
  #
1405
1530
  def to_time: () -> Time
1406
1531
 
1407
1532
  # <!--
1408
1533
  # rdoc-file=ext/date/date_core.c
1409
- # - d.tuesday? -> bool
1534
+ # - tuesday? -> true or false
1410
1535
  # -->
1411
- # Returns true if the date is Tuesday.
1536
+ # Returns `true` if `self` is a Tuesday, `false` otherwise.
1412
1537
  #
1413
1538
  def tuesday?: () -> bool
1414
1539
 
1415
1540
  # <!--
1416
1541
  # rdoc-file=ext/date/date_core.c
1417
- # - d.upto(max) -> enumerator
1418
- # - d.upto(max){|date| ...} -> self
1542
+ # - upto(max){|date| ... } -> self
1419
1543
  # -->
1420
- # This method is equivalent to step(max, 1){|date| ...}.
1544
+ # Equivalent to #step with arguments `max` and `1`.
1421
1545
  #
1422
1546
  def upto: (Date max) { (Date) -> untyped } -> Date
1423
1547
  | (Date max) -> ::Enumerator[Date, Date]
1424
1548
 
1425
1549
  # <!--
1426
1550
  # rdoc-file=ext/date/date_core.c
1427
- # - d.wday -> fixnum
1551
+ # - wday -> integer
1428
1552
  # -->
1429
- # Returns the day of week (0-6, Sunday is zero).
1553
+ # Returns the day of week in range (0..6); Sunday is 0:
1430
1554
  #
1431
- # Date.new(2001,2,3).wday #=> 6
1555
+ # Date.new(2001, 2, 3).wday # => 6
1432
1556
  #
1433
1557
  def wday: () -> Integer
1434
1558
 
1435
1559
  # <!--
1436
1560
  # rdoc-file=ext/date/date_core.c
1437
- # - d.wednesday? -> bool
1561
+ # - wednesday? -> true or false
1438
1562
  # -->
1439
- # Returns true if the date is Wednesday.
1563
+ # Returns `true` if `self` is a Wednesday, `false` otherwise.
1440
1564
  #
1441
1565
  def wednesday?: () -> bool
1442
1566
 
1443
1567
  # <!-- rdoc-file=ext/date/date_core.c -->
1444
- # This method is equivalent to strftime('%F').
1568
+ # Equivalent to #strftime with argument `'%Y-%m-%d'` (or its [shorthand
1569
+ # form](rdoc-ref:strftime_formatting.rdoc@Shorthand+Conversion+Specifiers)
1570
+ # `'%F'`);
1571
+ #
1572
+ # Date.new(2001, 2, 3).iso8601 # => "2001-02-03"
1573
+ #
1574
+ # Date#xmlschema is an alias for Date#iso8601.
1445
1575
  #
1446
1576
  def xmlschema: () -> String
1447
1577
 
1448
1578
  # <!--
1449
1579
  # rdoc-file=ext/date/date_core.c
1450
- # - d.yday -> fixnum
1580
+ # - yday -> integer
1451
1581
  # -->
1452
- # Returns the day of the year (1-366).
1582
+ # Returns the day of the year, in range (1..366):
1453
1583
  #
1454
- # Date.new(2001,2,3).yday #=> 34
1584
+ # Date.new(2001, 2, 3).yday # => 34
1455
1585
  #
1456
1586
  def yday: () -> Integer
1457
1587
 
1458
1588
  # <!--
1459
1589
  # rdoc-file=ext/date/date_core.c
1460
- # - d.year -> integer
1590
+ # - year -> integer
1461
1591
  # -->
1462
- # Returns the year.
1592
+ # Returns the year:
1463
1593
  #
1464
- # Date.new(2001,2,3).year #=> 2001
1465
- # (Date.new(1,1,1) - 1).year #=> 0
1594
+ # Date.new(2001, 2, 3).year # => 2001
1595
+ # (Date.new(1, 1, 1) - 1).year # => 0
1466
1596
  #
1467
1597
  def year: () -> Integer
1468
1598
  end