rbs 0.9.1 → 0.12.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +9 -9
  3. data/CHANGELOG.md +31 -0
  4. data/Gemfile +1 -0
  5. data/README.md +1 -1
  6. data/Rakefile +16 -6
  7. data/Steepfile +28 -0
  8. data/bin/steep +4 -0
  9. data/bin/test_runner.rb +7 -5
  10. data/docs/syntax.md +14 -1
  11. data/lib/rbs/ast/comment.rb +7 -1
  12. data/lib/rbs/ast/declarations.rb +15 -9
  13. data/lib/rbs/ast/members.rb +3 -8
  14. data/lib/rbs/buffer.rb +1 -1
  15. data/lib/rbs/cli.rb +62 -1
  16. data/lib/rbs/definition.rb +35 -16
  17. data/lib/rbs/definition_builder.rb +99 -68
  18. data/lib/rbs/environment.rb +24 -11
  19. data/lib/rbs/environment_loader.rb +55 -35
  20. data/lib/rbs/location.rb +1 -5
  21. data/lib/rbs/method_type.rb +5 -5
  22. data/lib/rbs/namespace.rb +14 -3
  23. data/lib/rbs/parser.y +2 -12
  24. data/lib/rbs/prototype/rb.rb +3 -5
  25. data/lib/rbs/prototype/rbi.rb +1 -4
  26. data/lib/rbs/prototype/runtime.rb +0 -4
  27. data/lib/rbs/substitution.rb +4 -3
  28. data/lib/rbs/test/hook.rb +1 -0
  29. data/lib/rbs/test/setup.rb +8 -6
  30. data/lib/rbs/test/setup_helper.rb +15 -0
  31. data/lib/rbs/test/tester.rb +55 -11
  32. data/lib/rbs/test/type_check.rb +43 -14
  33. data/lib/rbs/type_name.rb +18 -1
  34. data/lib/rbs/type_name_resolver.rb +10 -3
  35. data/lib/rbs/types.rb +27 -21
  36. data/lib/rbs/variance_calculator.rb +8 -5
  37. data/lib/rbs/version.rb +1 -1
  38. data/lib/rbs/writer.rb +7 -3
  39. data/sig/annotation.rbs +26 -0
  40. data/sig/buffer.rbs +28 -0
  41. data/sig/builtin_names.rbs +41 -0
  42. data/sig/comment.rbs +26 -0
  43. data/sig/declarations.rbs +202 -0
  44. data/sig/definition.rbs +129 -0
  45. data/sig/definition_builder.rbs +95 -0
  46. data/sig/environment.rbs +94 -0
  47. data/sig/environment_loader.rbs +4 -0
  48. data/sig/location.rbs +52 -0
  49. data/sig/members.rbs +160 -0
  50. data/sig/method_types.rbs +40 -0
  51. data/sig/namespace.rbs +124 -0
  52. data/sig/polyfill.rbs +3 -0
  53. data/sig/rbs.rbs +3 -0
  54. data/sig/substitution.rbs +39 -0
  55. data/sig/type_name_resolver.rbs +24 -0
  56. data/sig/typename.rbs +70 -0
  57. data/sig/types.rbs +361 -0
  58. data/sig/util.rbs +13 -0
  59. data/sig/variance_calculator.rbs +35 -0
  60. data/stdlib/bigdecimal/big_decimal.rbs +887 -0
  61. data/stdlib/bigdecimal/math/big_math.rbs +142 -0
  62. data/stdlib/builtin/array.rbs +2 -1
  63. data/stdlib/builtin/builtin.rbs +0 -3
  64. data/stdlib/builtin/hash.rbs +1 -1
  65. data/stdlib/builtin/math.rbs +26 -26
  66. data/stdlib/builtin/struct.rbs +9 -10
  67. data/stdlib/date/date.rbs +1056 -0
  68. data/stdlib/date/date_time.rbs +582 -0
  69. data/stdlib/forwardable/forwardable.rbs +204 -0
  70. data/stdlib/pty/pty.rbs +5 -29
  71. data/stdlib/set/set.rbs +1 -1
  72. data/stdlib/uri/file.rbs +167 -0
  73. data/stdlib/uri/generic.rbs +875 -0
  74. data/stdlib/zlib/zlib.rbs +392 -0
  75. data/steep/Gemfile +3 -0
  76. data/steep/Gemfile.lock +55 -0
  77. metadata +38 -5
@@ -0,0 +1,142 @@
1
+ # Provides mathematical functions.
2
+ #
3
+ # Example:
4
+ #
5
+ # require "bigdecimal/math"
6
+ #
7
+ # include BigMath
8
+ #
9
+ # a = BigDecimal((PI(100)/2).to_s)
10
+ # puts sin(a,100) # => 0.99999999999999999999......e0
11
+ #
12
+ module BigMath
13
+ # Computes e (the base of natural logarithms) to the specified number of digits
14
+ # of precision, `numeric`.
15
+ #
16
+ # BigMath.E(10).to_s
17
+ # #=> "0.271828182845904523536028752390026306410273e1"
18
+ #
19
+ def self.E: (Numeric prec) -> BigDecimal
20
+
21
+ # Computes the value of pi to the specified number of digits of precision,
22
+ # `numeric`.
23
+ #
24
+ # BigMath.PI(10).to_s
25
+ # #=> "0.3141592653589793238462643388813853786957412e1"
26
+ #
27
+ def self.PI: (Numeric prec) -> BigDecimal
28
+
29
+ # Computes the arctangent of `decimal` to the specified number of digits of
30
+ # precision, `numeric`.
31
+ #
32
+ # If `decimal` is NaN, returns NaN.
33
+ #
34
+ # BigMath.atan(BigDecimal('-1'), 16).to_s
35
+ # #=> "-0.785398163397448309615660845819878471907514682065e0"
36
+ #
37
+ def self.atan: (BigDecimal x, Numeric prec) -> BigDecimal
38
+
39
+ # Computes the cosine of `decimal` to the specified number of digits of
40
+ # precision, `numeric`.
41
+ #
42
+ # If `decimal` is Infinity or NaN, returns NaN.
43
+ #
44
+ # BigMath.cos(BigMath.PI(4), 16).to_s
45
+ # #=> "-0.999999999999999999999999999999856613163740061349e0"
46
+ #
47
+ def self.cos: (BigDecimal x, Numeric prec) -> BigDecimal
48
+
49
+ # Computes the value of e (the base of natural logarithms) raised to the power
50
+ # of `decimal`, to the specified number of digits of precision.
51
+ #
52
+ # If `decimal` is infinity, returns Infinity.
53
+ #
54
+ # If `decimal` is NaN, returns NaN.
55
+ #
56
+ def self.exp: (BigDecimal, Numeric prec) -> BigDecimal
57
+
58
+ # Computes the natural logarithm of `decimal` to the specified number of digits
59
+ # of precision, `numeric`.
60
+ #
61
+ # If `decimal` is zero or negative, raises Math::DomainError.
62
+ #
63
+ # If `decimal` is positive infinity, returns Infinity.
64
+ #
65
+ # If `decimal` is NaN, returns NaN.
66
+ #
67
+ def self.log: (BigDecimal, Numeric prec) -> BigDecimal
68
+
69
+ # Computes the sine of `decimal` to the specified number of digits of precision,
70
+ # `numeric`.
71
+ #
72
+ # If `decimal` is Infinity or NaN, returns NaN.
73
+ #
74
+ # BigMath.sin(BigMath.PI(5)/4, 5).to_s
75
+ # #=> "0.70710678118654752440082036563292800375e0"
76
+ #
77
+ def self.sin: (BigDecimal x, Numeric prec) -> BigDecimal
78
+
79
+ # Computes the square root of `decimal` to the specified number of digits of
80
+ # precision, `numeric`.
81
+ #
82
+ # BigMath.sqrt(BigDecimal('2'), 16).to_s
83
+ # #=> "0.1414213562373095048801688724e1"
84
+ #
85
+ def self.sqrt: (BigDecimal x, Numeric prec) -> BigDecimal
86
+
87
+ private
88
+
89
+ # Computes e (the base of natural logarithms) to the specified number of digits
90
+ # of precision, `numeric`.
91
+ #
92
+ # BigMath.E(10).to_s
93
+ # #=> "0.271828182845904523536028752390026306410273e1"
94
+ #
95
+ def E: (Numeric prec) -> BigDecimal
96
+
97
+ # Computes the value of pi to the specified number of digits of precision,
98
+ # `numeric`.
99
+ #
100
+ # BigMath.PI(10).to_s
101
+ # #=> "0.3141592653589793238462643388813853786957412e1"
102
+ #
103
+ def PI: (Numeric prec) -> BigDecimal
104
+
105
+ # Computes the arctangent of `decimal` to the specified number of digits of
106
+ # precision, `numeric`.
107
+ #
108
+ # If `decimal` is NaN, returns NaN.
109
+ #
110
+ # BigMath.atan(BigDecimal('-1'), 16).to_s
111
+ # #=> "-0.785398163397448309615660845819878471907514682065e0"
112
+ #
113
+ def atan: (BigDecimal x, Numeric prec) -> BigDecimal
114
+
115
+ # Computes the cosine of `decimal` to the specified number of digits of
116
+ # precision, `numeric`.
117
+ #
118
+ # If `decimal` is Infinity or NaN, returns NaN.
119
+ #
120
+ # BigMath.cos(BigMath.PI(4), 16).to_s
121
+ # #=> "-0.999999999999999999999999999999856613163740061349e0"
122
+ #
123
+ def cos: (BigDecimal x, Numeric prec) -> BigDecimal
124
+
125
+ # Computes the sine of `decimal` to the specified number of digits of precision,
126
+ # `numeric`.
127
+ #
128
+ # If `decimal` is Infinity or NaN, returns NaN.
129
+ #
130
+ # BigMath.sin(BigMath.PI(5)/4, 5).to_s
131
+ # #=> "0.70710678118654752440082036563292800375e0"
132
+ #
133
+ def sin: (BigDecimal x, Numeric prec) -> BigDecimal
134
+
135
+ # Computes the square root of `decimal` to the specified number of digits of
136
+ # precision, `numeric`.
137
+ #
138
+ # BigMath.sqrt(BigDecimal('2'), 16).to_s
139
+ # #=> "0.1414213562373095048801688724e1"
140
+ #
141
+ def sqrt: (BigDecimal x, Numeric prec) -> BigDecimal
142
+ end
@@ -626,7 +626,8 @@ class Array[unchecked out Elem] < Object
626
626
  # a.collect!.with_index {|x, i| x[0...i] }
627
627
  # a #=> ["", "b", "c!", "d!"]
628
628
  #
629
- def collect!: () { (Elem item) -> Elem } -> self # collect! is monomorphic because of RBS limitation.
629
+ # collect! is monomorphic because of RBS limitation.
630
+ def collect!: () { (Elem item) -> Elem } -> self
630
631
  | () -> ::Enumerator[Elem, self]
631
632
 
632
633
  # When invoked with a block, yields all combinations of length `n` of elements
@@ -35,9 +35,6 @@ interface _Exception
35
35
  | (String arg0) -> Exception
36
36
  end
37
37
 
38
- class BigDecimal
39
- end
40
-
41
38
  type int = Integer | _ToInt
42
39
  type real = Integer | Float | Rational
43
40
 
@@ -1016,7 +1016,7 @@ class Hash[unchecked out K, unchecked out V] < Object
1016
1016
  # h["d"] #=> "Go Fish: d"
1017
1017
  # h.keys #=> ["c", "d"]
1018
1018
  #
1019
- incompatible def initialize: () -> void
1019
+ def initialize: () -> void
1020
1020
  | (untyped default) -> void
1021
1021
  | [A, B] () { (Hash[A, B] hash, A key) -> B } -> void
1022
1022
 
@@ -13,7 +13,7 @@ module Math
13
13
  #
14
14
  # Math.acos(0) == Math::PI/2 #=> true
15
15
  #
16
- def self.acos: (Integer | Float | Rational | BigDecimal x) -> Float
16
+ def self.acos: (Numeric x) -> Float
17
17
 
18
18
  # Computes the inverse hyperbolic cosine of `x`.
19
19
  #
@@ -23,7 +23,7 @@ module Math
23
23
  #
24
24
  # Math.acosh(1) #=> 0.0
25
25
  #
26
- def self.acosh: (Integer | Float | Rational | BigDecimal x) -> Float
26
+ def self.acosh: (Numeric x) -> Float
27
27
 
28
28
  # Computes the arc sine of `x`. Returns -PI/2..PI/2.
29
29
  #
@@ -33,7 +33,7 @@ module Math
33
33
  #
34
34
  # Math.asin(1) == Math::PI/2 #=> true
35
35
  #
36
- def self.asin: (Integer | Float | Rational | BigDecimal x) -> Float
36
+ def self.asin: (Numeric x) -> Float
37
37
 
38
38
  # Computes the inverse hyperbolic sine of `x`.
39
39
  #
@@ -43,7 +43,7 @@ module Math
43
43
  #
44
44
  # Math.asinh(1) #=> 0.881373587019543
45
45
  #
46
- def self.asinh: (Integer | Float | Rational | BigDecimal x) -> Float
46
+ def self.asinh: (Numeric x) -> Float
47
47
 
48
48
  # Computes the arc tangent of `x`. Returns -PI/2..PI/2.
49
49
  #
@@ -53,7 +53,7 @@ module Math
53
53
  #
54
54
  # Math.atan(0) #=> 0.0
55
55
  #
56
- def self.atan: (Integer | Float | Rational | BigDecimal x) -> Float
56
+ def self.atan: (Numeric x) -> Float
57
57
 
58
58
  # Computes the arc tangent given `y` and `x`. Returns a Float in the range
59
59
  # -PI..PI. Return value is a angle in radians between the positive x-axis of
@@ -78,7 +78,7 @@ module Math
78
78
  # Math.atan2(-INFINITY, INFINITY) #=> -0.7853981633974483
79
79
  # Math.atan2(-INFINITY, -INFINITY) #=> -2.356194490192345
80
80
  #
81
- def self.atan2: (Integer | Float | Rational | BigDecimal y, Integer | Float | Rational | BigDecimal x) -> Float
81
+ def self.atan2: (Numeric y, Numeric x) -> Float
82
82
 
83
83
  # Computes the inverse hyperbolic tangent of `x`.
84
84
  #
@@ -88,7 +88,7 @@ module Math
88
88
  #
89
89
  # Math.atanh(1) #=> Infinity
90
90
  #
91
- def self.atanh: (Integer | Float | Rational | BigDecimal x) -> Float
91
+ def self.atanh: (Numeric x) -> Float
92
92
 
93
93
  # Returns the cube root of `x`.
94
94
  #
@@ -119,7 +119,7 @@ module Math
119
119
  # # [8, 2.0, 8.0]
120
120
  # # [9, 2.0800838230519, 9.0]
121
121
  #
122
- def self.cbrt: (Integer | Float | Rational | BigDecimal x) -> Float
122
+ def self.cbrt: (Numeric x) -> Float
123
123
 
124
124
  # Computes the cosine of `x` (expressed in radians). Returns a Float in the
125
125
  # range -1.0..1.0.
@@ -130,7 +130,7 @@ module Math
130
130
  #
131
131
  # Math.cos(Math::PI) #=> -1.0
132
132
  #
133
- def self.cos: (Integer | Float | Rational | BigDecimal x) -> Float
133
+ def self.cos: (Numeric x) -> Float
134
134
 
135
135
  # Computes the hyperbolic cosine of `x` (expressed in radians).
136
136
  #
@@ -140,7 +140,7 @@ module Math
140
140
  #
141
141
  # Math.cosh(0) #=> 1.0
142
142
  #
143
- def self.cosh: (Integer | Float | Rational | BigDecimal x) -> Float
143
+ def self.cosh: (Numeric x) -> Float
144
144
 
145
145
  # Calculates the error function of `x`.
146
146
  #
@@ -150,7 +150,7 @@ module Math
150
150
  #
151
151
  # Math.erf(0) #=> 0.0
152
152
  #
153
- def self.erf: (Integer | Float | Rational | BigDecimal x) -> Float
153
+ def self.erf: (Numeric x) -> Float
154
154
 
155
155
  # Calculates the complementary error function of x.
156
156
  #
@@ -160,7 +160,7 @@ module Math
160
160
  #
161
161
  # Math.erfc(0) #=> 1.0
162
162
  #
163
- def self.erfc: (Integer | Float | Rational | BigDecimal x) -> Float
163
+ def self.erfc: (Numeric x) -> Float
164
164
 
165
165
  # Returns e**x.
166
166
  #
@@ -172,7 +172,7 @@ module Math
172
172
  # Math.exp(1) #=> 2.718281828459045
173
173
  # Math.exp(1.5) #=> 4.4816890703380645
174
174
  #
175
- def self.exp: (Integer | Float | Rational | BigDecimal x) -> Float
175
+ def self.exp: (Numeric x) -> Float
176
176
 
177
177
  # Returns a two-element array containing the normalized fraction (a Float) and
178
178
  # exponent (an Integer) of `x`.
@@ -180,7 +180,7 @@ module Math
180
180
  # fraction, exponent = Math.frexp(1234) #=> [0.6025390625, 11]
181
181
  # fraction * 2**exponent #=> 1234.0
182
182
  #
183
- def self.frexp: (Integer | Float | Rational | BigDecimal x) -> [ Float, Integer ]
183
+ def self.frexp: (Numeric x) -> [ Float, Integer ]
184
184
 
185
185
  # Calculates the gamma function of x.
186
186
  #
@@ -216,21 +216,21 @@ module Math
216
216
  # # [25, 6.204484017332391e+23, 620448401733239439360000]
217
217
  # # [26, 1.5511210043330954e+25, 15511210043330985984000000]
218
218
  #
219
- def self.gamma: (Integer | Float | Rational | BigDecimal x) -> Float
219
+ def self.gamma: (Numeric x) -> Float
220
220
 
221
221
  # Returns sqrt(x**2 + y**2), the hypotenuse of a right-angled triangle with
222
222
  # sides `x` and `y`.
223
223
  #
224
224
  # Math.hypot(3, 4) #=> 5.0
225
225
  #
226
- def self.hypot: (Integer | Float | Rational | BigDecimal x, Integer | Float | Rational | BigDecimal y) -> Float
226
+ def self.hypot: (Numeric x, Numeric y) -> Float
227
227
 
228
228
  # Returns the value of `fraction`*(2**`exponent`).
229
229
  #
230
230
  # fraction, exponent = Math.frexp(1234)
231
231
  # Math.ldexp(fraction, exponent) #=> 1234.0
232
232
  #
233
- def self.ldexp: (Integer | Float | Rational | BigDecimal fraction, Integer | Float | Rational | BigDecimal exponent) -> Float
233
+ def self.ldexp: (Numeric fraction, Numeric exponent) -> Float
234
234
 
235
235
  # Calculates the logarithmic gamma of `x` and the sign of gamma of `x`.
236
236
  #
@@ -241,9 +241,9 @@ module Math
241
241
  #
242
242
  # Math.lgamma(0) #=> [Infinity, 1]
243
243
  #
244
- def self.lgamma: (Integer | Float | Rational | BigDecimal x) -> [ Float, Integer ]
244
+ def self.lgamma: (Numeric x) -> [ Float, Integer ]
245
245
 
246
- def self.log: (Integer | Float | Rational | BigDecimal x, ?Integer | Float | Rational | BigDecimal base) -> Float
246
+ def self.log: (Numeric x, ?Numeric base) -> Float
247
247
 
248
248
  # Returns the base 10 logarithm of `x`.
249
249
  #
@@ -255,7 +255,7 @@ module Math
255
255
  # Math.log10(10) #=> 1.0
256
256
  # Math.log10(10**100) #=> 100.0
257
257
  #
258
- def self.log10: (Integer | Float | Rational | BigDecimal x) -> Float
258
+ def self.log10: (Numeric x) -> Float
259
259
 
260
260
  # Returns the base 2 logarithm of `x`.
261
261
  #
@@ -268,7 +268,7 @@ module Math
268
268
  # Math.log2(32768) #=> 15.0
269
269
  # Math.log2(65536) #=> 16.0
270
270
  #
271
- def self.log2: (Integer | Float | Rational | BigDecimal x) -> Float
271
+ def self.log2: (Numeric x) -> Float
272
272
 
273
273
  # Computes the sine of `x` (expressed in radians). Returns a Float in the range
274
274
  # -1.0..1.0.
@@ -279,7 +279,7 @@ module Math
279
279
  #
280
280
  # Math.sin(Math::PI/2) #=> 1.0
281
281
  #
282
- def self.sin: (Integer | Float | Rational | BigDecimal x) -> Float
282
+ def self.sin: (Numeric x) -> Float
283
283
 
284
284
  # Computes the hyperbolic sine of `x` (expressed in radians).
285
285
  #
@@ -289,7 +289,7 @@ module Math
289
289
  #
290
290
  # Math.sinh(0) #=> 0.0
291
291
  #
292
- def self.sinh: (Integer | Float | Rational | BigDecimal x) -> Float
292
+ def self.sinh: (Numeric x) -> Float
293
293
 
294
294
  # Returns the non-negative square root of `x`.
295
295
  #
@@ -319,7 +319,7 @@ module Math
319
319
  #
320
320
  # See also BigDecimal#sqrt and Integer.sqrt.
321
321
  #
322
- def self.sqrt: (Integer | Float | Rational | BigDecimal x) -> Float
322
+ def self.sqrt: (Numeric x) -> Float
323
323
 
324
324
  # Computes the tangent of `x` (expressed in radians).
325
325
  #
@@ -329,7 +329,7 @@ module Math
329
329
  #
330
330
  # Math.tan(0) #=> 0.0
331
331
  #
332
- def self.tan: (Integer | Float | Rational | BigDecimal x) -> Float
332
+ def self.tan: (Numeric x) -> Float
333
333
 
334
334
  # Computes the hyperbolic tangent of `x` (expressed in radians).
335
335
  #
@@ -339,7 +339,7 @@ module Math
339
339
  #
340
340
  # Math.tanh(0) #=> 0.0
341
341
  #
342
- def self.tanh: (Integer | Float | Rational | BigDecimal x) -> Float
342
+ def self.tanh: (Numeric x) -> Float
343
343
  end
344
344
 
345
345
  # Definition of the mathematical constant E for Euler's number (e) as a Float
@@ -1,40 +1,39 @@
1
1
  # A [Struct](Struct) is a convenient way to bundle a
2
2
  # number of attributes together, using accessor methods, without having to
3
3
  # write an explicit class.
4
- #
4
+ #
5
5
  # The [Struct](Struct) class generates new subclasses
6
6
  # that hold a set of members and their values. For each member a reader
7
7
  # and writer method is created similar to
8
8
  # [Module\#attr\_accessor](https://ruby-doc.org/core-2.6.3/Module.html#method-i-attr_accessor)
9
9
  # .
10
- #
10
+ #
11
11
  # ```ruby
12
12
  # Customer = Struct.new(:name, :address) do
13
13
  # def greeting
14
14
  # "Hello #{name}!"
15
15
  # end
16
16
  # end
17
- #
17
+ #
18
18
  # dave = Customer.new("Dave", "123 Main")
19
19
  # dave.name #=> "Dave"
20
20
  # dave.greeting #=> "Hello Dave!"
21
21
  # ```
22
- #
22
+ #
23
23
  # See [::new](Struct#method-c-new) for further
24
24
  # examples of creating struct subclasses and instances.
25
- #
25
+ #
26
26
  # In the method descriptions that follow, a "member" parameter refers to a
27
27
  # struct member which is either a quoted string ( `"name"` ) or a
28
28
  # [Symbol](https://ruby-doc.org/core-2.6.3/Symbol.html) ( `:name` ).
29
29
  class Struct[Elem] < Object
30
30
  include Enumerable[Elem, Struct[Elem]]
31
31
 
32
- def initialize: (Symbol | String arg0, *Symbol | String arg1, ?keyword_init: bool keyword_init) -> void
32
+ type attribute_name = Symbol | String
33
33
 
34
- def each: () { (Elem arg0) -> untyped } -> untyped
35
- | () -> self
34
+ def initialize: (attribute_name, *attribute_name, ?keyword_init: bool) ?{ () -> void } -> void
36
35
 
37
- def self.members: () -> ::Array[Symbol]
36
+ def each: () { (Elem) -> untyped } -> untyped
38
37
 
39
- def new: (*untyped args) -> Struct[untyped]
38
+ def self.members: () -> ::Array[Symbol]
40
39
  end
@@ -0,0 +1,1056 @@
1
+ # date and datetime class - Tadayoshi Funaba 1998-2011
2
+ #
3
+ # 'date' provides two classes: Date and DateTime.
4
+ #
5
+ # ## Terms and Definitions
6
+ #
7
+ # Some terms and definitions are based on ISO 8601 and JIS X 0301.
8
+ #
9
+ # ### Calendar Date
10
+ #
11
+ # The calendar date is a particular day of a calendar year, identified by its
12
+ # ordinal number within a calendar month within that year.
13
+ #
14
+ # In those classes, this is so-called "civil".
15
+ #
16
+ # ### Ordinal Date
17
+ #
18
+ # The ordinal date is a particular day of a calendar year identified by its
19
+ # ordinal number within the year.
20
+ #
21
+ # In those classes, this is so-called "ordinal".
22
+ #
23
+ # ### Week Date
24
+ #
25
+ # The week date is a date identified by calendar week and day numbers.
26
+ #
27
+ # The calendar week is a seven day period within a calendar year, starting on a
28
+ # Monday and identified by its ordinal number within the year; the first
29
+ # calendar week of the year is the one that includes the first Thursday of that
30
+ # year. In the Gregorian calendar, this is equivalent to the week which includes
31
+ # January 4.
32
+ #
33
+ # In those classes, this is so-called "commercial".
34
+ #
35
+ # ### Julian Day Number
36
+ #
37
+ # The Julian day number is in elapsed days since noon (Greenwich Mean Time) on
38
+ # January 1, 4713 BCE (in the Julian calendar).
39
+ #
40
+ # In this document, the astronomical Julian day number is the same as the
41
+ # original Julian day number. And the chronological Julian day number is a
42
+ # variation of the Julian day number. Its days begin at midnight on local time.
43
+ #
44
+ # In this document, when the term "Julian day number" simply appears, it just
45
+ # refers to "chronological Julian day number", not the original.
46
+ #
47
+ # In those classes, those are so-called "ajd" and "jd".
48
+ #
49
+ # ### Modified Julian Day Number
50
+ #
51
+ # The modified Julian day number is in elapsed days since midnight (Coordinated
52
+ # Universal Time) on November 17, 1858 CE (in the Gregorian calendar).
53
+ #
54
+ # In this document, the astronomical modified Julian day number is the same as
55
+ # the original modified Julian day number. And the chronological modified Julian
56
+ # day number is a variation of the modified Julian day number. Its days begin at
57
+ # midnight on local time.
58
+ #
59
+ # In this document, when the term "modified Julian day number" simply appears,
60
+ # it just refers to "chronological modified Julian day number", not the
61
+ # original.
62
+ #
63
+ # In those classes, those are so-called "amjd" and "mjd".
64
+ #
65
+ # ## Date
66
+ #
67
+ # A subclass of Object that includes the Comparable module and easily handles
68
+ # date.
69
+ #
70
+ # A Date object is created with Date::new, Date::jd, Date::ordinal,
71
+ # Date::commercial, Date::parse, Date::strptime, Date::today, Time#to_date, etc.
72
+ #
73
+ # require 'date'
74
+ #
75
+ # Date.new(2001,2,3)
76
+ # #=> #<Date: 2001-02-03 ...>
77
+ # Date.jd(2451944)
78
+ # #=> #<Date: 2001-02-03 ...>
79
+ # Date.ordinal(2001,34)
80
+ # #=> #<Date: 2001-02-03 ...>
81
+ # Date.commercial(2001,5,6)
82
+ # #=> #<Date: 2001-02-03 ...>
83
+ # Date.parse('2001-02-03')
84
+ # #=> #<Date: 2001-02-03 ...>
85
+ # Date.strptime('03-02-2001', '%d-%m-%Y')
86
+ # #=> #<Date: 2001-02-03 ...>
87
+ # Time.new(2001,2,3).to_date
88
+ # #=> #<Date: 2001-02-03 ...>
89
+ #
90
+ # All date objects are immutable; hence cannot modify themselves.
91
+ #
92
+ # The concept of a date object can be represented as a tuple of the day count,
93
+ # the offset and the day of calendar reform.
94
+ #
95
+ # The day count denotes the absolute position of a temporal dimension. The
96
+ # offset is relative adjustment, which determines decoded local time with the
97
+ # day count. The day of calendar reform denotes the start day of the new style.
98
+ # The old style of the West is the Julian calendar which was adopted by Caesar.
99
+ # The new style is the Gregorian calendar, which is the current civil calendar
100
+ # of many countries.
101
+ #
102
+ # The day count is virtually the astronomical Julian day number. The offset in
103
+ # this class is usually zero, and cannot be specified directly.
104
+ #
105
+ # A Date object can be created with an optional argument, the day of calendar
106
+ # reform as a Julian day number, which should be 2298874 to 2426355 or
107
+ # negative/positive infinity. The default value is `Date::ITALY`
108
+ # (2299161=1582-10-15). See also sample/cal.rb.
109
+ #
110
+ # $ ruby sample/cal.rb -c it 10 1582
111
+ # October 1582
112
+ # S M Tu W Th F S
113
+ # 1 2 3 4 15 16
114
+ # 17 18 19 20 21 22 23
115
+ # 24 25 26 27 28 29 30
116
+ # 31
117
+ #
118
+ # $ ruby sample/cal.rb -c gb 9 1752
119
+ # September 1752
120
+ # S M Tu W Th F S
121
+ # 1 2 14 15 16
122
+ # 17 18 19 20 21 22 23
123
+ # 24 25 26 27 28 29 30
124
+ #
125
+ # A Date object has various methods. See each reference.
126
+ #
127
+ # d = Date.parse('3rd Feb 2001')
128
+ # #=> #<Date: 2001-02-03 ...>
129
+ # d.year #=> 2001
130
+ # d.mon #=> 2
131
+ # d.mday #=> 3
132
+ # d.wday #=> 6
133
+ # d += 1 #=> #<Date: 2001-02-04 ...>
134
+ # d.strftime('%a %d %b %Y') #=> "Sun 04 Feb 2001"
135
+ #
136
+ class Date
137
+ # Creates a date object denoting the given calendar date.
138
+ #
139
+ # In this class, BCE years are counted astronomically. Thus, the year before
140
+ # the year 1 is the year zero, and the year preceding the year zero is the year
141
+ # -1. The month and the day of month should be a negative or a positive number
142
+ # (as a relative month/day from the end of year/month when negative). They
143
+ # should not be zero.
144
+ #
145
+ # The last argument should be a Julian day number which denotes the day of
146
+ # calendar reform. Date::ITALY (2299161=1582-10-15), Date::ENGLAND
147
+ # (2361222=1752-09-14), Date::GREGORIAN (the proleptic Gregorian calendar) and
148
+ # Date::JULIAN (the proleptic Julian calendar) can be specified as a day of
149
+ # calendar reform.
150
+ #
151
+ # Date.new(2001) #=> #<Date: 2001-01-01 ...>
152
+ # Date.new(2001,2,3) #=> #<Date: 2001-02-03 ...>
153
+ # Date.new(2001,2,-1) #=> #<Date: 2001-02-28 ...>
154
+ #
155
+ # See also ::jd.
156
+ #
157
+ def initialize: (?Integer year, ?Integer month, ?Integer mday, ?Integer start) -> void
158
+
159
+ include Comparable
160
+
161
+ # Returns a hash of parsed elements.
162
+ #
163
+ def self._httpdate: (String str) -> Hash[Symbol, Integer]
164
+
165
+ # Returns a hash of parsed elements.
166
+ #
167
+ def self._iso8601: (String str) -> Hash[Symbol, Integer]
168
+
169
+ # Returns a hash of parsed elements.
170
+ #
171
+ def self._jisx0301: (String str) -> Hash[Symbol, Integer]
172
+
173
+ # Parses the given representation of date and time, and returns a hash of parsed
174
+ # elements. This method does not function as a validator.
175
+ #
176
+ # If the optional second argument is true and the detected year is in the range
177
+ # "00" to "99", considers the year a 2-digit form and makes it full.
178
+ #
179
+ # Date._parse('2001-02-03') #=> {:year=>2001, :mon=>2, :mday=>3}
180
+ #
181
+ def self._parse: (String str, ?bool complete) -> Hash[Symbol, Integer]
182
+
183
+ # Returns a hash of parsed elements.
184
+ #
185
+ def self._rfc2822: (String str) -> Hash[Symbol, Integer | String]
186
+
187
+ # Returns a hash of parsed elements.
188
+ #
189
+ def self._rfc3339: (String str) -> Hash[Symbol, Integer | String]
190
+
191
+ # Returns a hash of parsed elements.
192
+ #
193
+ def self._rfc822: (String str) -> Hash[Symbol, Integer | String]
194
+
195
+ # Parses the given representation of date and time with the given template, and
196
+ # returns a hash of parsed elements. _strptime does not support specification
197
+ # of flags and width unlike strftime.
198
+ #
199
+ # Date._strptime('2001-02-03', '%Y-%m-%d')
200
+ # #=> {:year=>2001, :mon=>2, :mday=>3}
201
+ #
202
+ # See also strptime(3) and #strftime.
203
+ #
204
+ def self._strptime: (String str, ?String format) -> Hash[Symbol, Integer]
205
+
206
+ # Returns a hash of parsed elements.
207
+ #
208
+ def self._xmlschema: (String str) -> Hash[Symbol, Integer]
209
+
210
+ # Creates a date object denoting the given calendar date.
211
+ #
212
+ # In this class, BCE years are counted astronomically. Thus, the year before
213
+ # the year 1 is the year zero, and the year preceding the year zero is the year
214
+ # -1. The month and the day of month should be a negative or a positive number
215
+ # (as a relative month/day from the end of year/month when negative). They
216
+ # should not be zero.
217
+ #
218
+ # The last argument should be a Julian day number which denotes the day of
219
+ # calendar reform. Date::ITALY (2299161=1582-10-15), Date::ENGLAND
220
+ # (2361222=1752-09-14), Date::GREGORIAN (the proleptic Gregorian calendar) and
221
+ # Date::JULIAN (the proleptic Julian calendar) can be specified as a day of
222
+ # calendar reform.
223
+ #
224
+ # Date.new(2001) #=> #<Date: 2001-01-01 ...>
225
+ # Date.new(2001,2,3) #=> #<Date: 2001-02-03 ...>
226
+ # Date.new(2001,2,-1) #=> #<Date: 2001-02-28 ...>
227
+ #
228
+ # See also ::jd.
229
+ #
230
+ def self.civil: (?Integer year, ?Integer month, ?Integer mday, ?Integer start) -> Date
231
+
232
+ # Creates a date object denoting the given week date.
233
+ #
234
+ # The week and the day of week should be a negative or a positive number (as a
235
+ # relative week/day from the end of year/week when negative). They should not
236
+ # be zero.
237
+ #
238
+ # Date.commercial(2001) #=> #<Date: 2001-01-01 ...>
239
+ # Date.commercial(2002) #=> #<Date: 2001-12-31 ...>
240
+ # Date.commercial(2001,5,6) #=> #<Date: 2001-02-03 ...>
241
+ #
242
+ # See also ::jd and ::new.
243
+ #
244
+ def self.commercial: (?Integer cwyear, ?Integer cweek, ?Integer cwday, ?Integer start) -> Date
245
+
246
+ # Returns true if the given year is a leap year of the proleptic Gregorian
247
+ # calendar.
248
+ #
249
+ # Date.gregorian_leap?(1900) #=> false
250
+ # Date.gregorian_leap?(2000) #=> true
251
+ #
252
+ def self.gregorian_leap?: (Integer year) -> bool
253
+
254
+ # Creates a new Date object by parsing from a string according to some RFC 2616
255
+ # format.
256
+ #
257
+ # Date.httpdate('Sat, 03 Feb 2001 00:00:00 GMT')
258
+ # #=> #<Date: 2001-02-03 ...>
259
+ #
260
+ def self.httpdate: (String str, ?Integer start) -> Date
261
+
262
+ # Creates a new Date object by parsing from a string according to some typical
263
+ # ISO 8601 formats.
264
+ #
265
+ # Date.iso8601('2001-02-03') #=> #<Date: 2001-02-03 ...>
266
+ # Date.iso8601('20010203') #=> #<Date: 2001-02-03 ...>
267
+ # Date.iso8601('2001-W05-6') #=> #<Date: 2001-02-03 ...>
268
+ #
269
+ def self.iso8601: (String str, ?Integer start) -> Date
270
+
271
+ # Creates a date object denoting the given chronological Julian day number.
272
+ #
273
+ # Date.jd(2451944) #=> #<Date: 2001-02-03 ...>
274
+ # Date.jd(2451945) #=> #<Date: 2001-02-04 ...>
275
+ # Date.jd(0) #=> #<Date: -4712-01-01 ...>
276
+ #
277
+ # See also ::new.
278
+ #
279
+ def self.jd: (Integer jd, ?Integer start) -> Date
280
+
281
+ # Creates a new Date object by parsing from a string according to some typical
282
+ # JIS X 0301 formats.
283
+ #
284
+ # Date.jisx0301('H13.02.03') #=> #<Date: 2001-02-03 ...>
285
+ #
286
+ # For no-era year, legacy format, Heisei is assumed.
287
+ #
288
+ # Date.jisx0301('13.02.03') #=> #<Date: 2001-02-03 ...>
289
+ #
290
+ def self.jisx0301: (String str, ?Integer start) -> Date
291
+
292
+ # Returns true if the given year is a leap year of the proleptic Julian
293
+ # calendar.
294
+ #
295
+ # Date.julian_leap?(1900) #=> true
296
+ # Date.julian_leap?(1901) #=> false
297
+ #
298
+ def self.julian_leap?: (Integer year) -> bool
299
+
300
+ # Returns true if the given year is a leap year of the proleptic Gregorian
301
+ # calendar.
302
+ #
303
+ # Date.gregorian_leap?(1900) #=> false
304
+ # Date.gregorian_leap?(2000) #=> true
305
+ #
306
+ def self.leap?: (Integer year) -> bool
307
+
308
+ # Creates a date object denoting the given ordinal date.
309
+ #
310
+ # The day of year should be a negative or a positive number (as a relative day
311
+ # from the end of year when negative). It should not be zero.
312
+ #
313
+ # Date.ordinal(2001) #=> #<Date: 2001-01-01 ...>
314
+ # Date.ordinal(2001,34) #=> #<Date: 2001-02-03 ...>
315
+ # Date.ordinal(2001,-1) #=> #<Date: 2001-12-31 ...>
316
+ #
317
+ # See also ::jd and ::new.
318
+ #
319
+ def self.ordinal: (?Integer year, ?Integer yday, ?Integer start) -> Date
320
+
321
+ # Parses the given representation of date and time, and creates a date object.
322
+ # This method does not function as a validator.
323
+ #
324
+ # If the optional second argument is true and the detected year is in the range
325
+ # "00" to "99", considers the year a 2-digit form and makes it full.
326
+ #
327
+ # Date.parse('2001-02-03') #=> #<Date: 2001-02-03 ...>
328
+ # Date.parse('20010203') #=> #<Date: 2001-02-03 ...>
329
+ # Date.parse('3rd Feb 2001') #=> #<Date: 2001-02-03 ...>
330
+ #
331
+ def self.parse: (String str, ?bool complete, ?Integer start) -> Date
332
+
333
+ # Creates a new Date object by parsing from a string according to some typical
334
+ # RFC 2822 formats.
335
+ #
336
+ # Date.rfc2822('Sat, 3 Feb 2001 00:00:00 +0000')
337
+ # #=> #<Date: 2001-02-03 ...>
338
+ #
339
+ def self.rfc2822: (String str, ?Integer start) -> Date
340
+
341
+ # Creates a new Date object by parsing from a string according to some typical
342
+ # RFC 3339 formats.
343
+ #
344
+ # Date.rfc3339('2001-02-03T04:05:06+07:00') #=> #<Date: 2001-02-03 ...>
345
+ #
346
+ def self.rfc3339: (String str, ?Integer start) -> Date
347
+
348
+ # Creates a new Date object by parsing from a string according to some typical
349
+ # RFC 2822 formats.
350
+ #
351
+ # Date.rfc2822('Sat, 3 Feb 2001 00:00:00 +0000')
352
+ # #=> #<Date: 2001-02-03 ...>
353
+ #
354
+ def self.rfc822: (String str, ?Integer start) -> Date
355
+
356
+ # Parses the given representation of date and time with the given template, and
357
+ # creates a date object. strptime does not support specification of flags and
358
+ # width unlike strftime.
359
+ #
360
+ # Date.strptime('2001-02-03', '%Y-%m-%d') #=> #<Date: 2001-02-03 ...>
361
+ # Date.strptime('03-02-2001', '%d-%m-%Y') #=> #<Date: 2001-02-03 ...>
362
+ # Date.strptime('2001-034', '%Y-%j') #=> #<Date: 2001-02-03 ...>
363
+ # Date.strptime('2001-W05-6', '%G-W%V-%u') #=> #<Date: 2001-02-03 ...>
364
+ # Date.strptime('2001 04 6', '%Y %U %w') #=> #<Date: 2001-02-03 ...>
365
+ # Date.strptime('2001 05 6', '%Y %W %u') #=> #<Date: 2001-02-03 ...>
366
+ # Date.strptime('sat3feb01', '%a%d%b%y') #=> #<Date: 2001-02-03 ...>
367
+ #
368
+ # See also strptime(3) and #strftime.
369
+ #
370
+ def self.strptime: (String str, ?String format, ?Integer start) -> Date
371
+
372
+ # Creates a date object denoting the present day.
373
+ #
374
+ # Date.today #=> #<Date: 2011-06-11 ...>
375
+ #
376
+ def self.today: (?Integer start) -> Date
377
+
378
+ # Returns true if the given calendar date is valid, and false if not. Valid in
379
+ # this context is whether the arguments passed to this method would be accepted
380
+ # by ::new.
381
+ #
382
+ # Date.valid_date?(2001,2,3) #=> true
383
+ # Date.valid_date?(2001,2,29) #=> false
384
+ # Date.valid_date?(2001,2,-1) #=> true
385
+ #
386
+ # See also ::jd and ::civil.
387
+ #
388
+ def self.valid_civil?: (Integer year, Integer month, Integer mday, ?Integer start) -> bool
389
+
390
+ # Returns true if the given week date is valid, and false if not.
391
+ #
392
+ # Date.valid_commercial?(2001,5,6) #=> true
393
+ # Date.valid_commercial?(2001,5,8) #=> false
394
+ #
395
+ # See also ::jd and ::commercial.
396
+ #
397
+ def self.valid_commercial?: (Integer cwyear, Integer cweek, Integer cwday, ?Integer start) -> bool
398
+
399
+ # Returns true if the given calendar date is valid, and false if not. Valid in
400
+ # this context is whether the arguments passed to this method would be accepted
401
+ # by ::new.
402
+ #
403
+ # Date.valid_date?(2001,2,3) #=> true
404
+ # Date.valid_date?(2001,2,29) #=> false
405
+ # Date.valid_date?(2001,2,-1) #=> true
406
+ #
407
+ # See also ::jd and ::civil.
408
+ #
409
+ def self.valid_date?: (Integer year, Integer month, Integer mday, ?Integer start) -> bool
410
+
411
+ # Just returns true. It's nonsense, but is for symmetry.
412
+ #
413
+ # Date.valid_jd?(2451944) #=> true
414
+ #
415
+ # See also ::jd.
416
+ #
417
+ def self.valid_jd?: (Integer jd, ?Integer start) -> bool
418
+
419
+ # Returns true if the given ordinal date is valid, and false if not.
420
+ #
421
+ # Date.valid_ordinal?(2001,34) #=> true
422
+ # Date.valid_ordinal?(2001,366) #=> false
423
+ #
424
+ # See also ::jd and ::ordinal.
425
+ #
426
+ def self.valid_ordinal?: (Integer year, Integer yday, ?Integer start) -> bool
427
+
428
+ # Creates a new Date object by parsing from a string according to some typical
429
+ # XML Schema formats.
430
+ #
431
+ # Date.xmlschema('2001-02-03') #=> #<Date: 2001-02-03 ...>
432
+ #
433
+ def self.xmlschema: (String str, ?Integer start) -> Date
434
+
435
+ public
436
+
437
+ # Returns a date object pointing `other` days after self. The other should be a
438
+ # numeric value. If the other is a fractional number, assumes its precision is
439
+ # at most nanosecond.
440
+ #
441
+ # Date.new(2001,2,3) + 1 #=> #<Date: 2001-02-04 ...>
442
+ # DateTime.new(2001,2,3) + Rational(1,2)
443
+ # #=> #<DateTime: 2001-02-03T12:00:00+00:00 ...>
444
+ # DateTime.new(2001,2,3) + Rational(-1,2)
445
+ # #=> #<DateTime: 2001-02-02T12:00:00+00:00 ...>
446
+ # DateTime.jd(0,12) + DateTime.new(2001,2,3).ajd
447
+ # #=> #<DateTime: 2001-02-03T00:00:00+00:00 ...>
448
+ #
449
+ def +: (Integer | Rational other) -> Date
450
+
451
+ # Returns the difference between the two dates if the other is a date object.
452
+ # If the other is a numeric value, returns a date object pointing `other` days
453
+ # before self. If the other is a fractional number, assumes its precision is at
454
+ # most nanosecond.
455
+ #
456
+ # Date.new(2001,2,3) - 1 #=> #<Date: 2001-02-02 ...>
457
+ # DateTime.new(2001,2,3) - Rational(1,2)
458
+ # #=> #<DateTime: 2001-02-02T12:00:00+00:00 ...>
459
+ # Date.new(2001,2,3) - Date.new(2001)
460
+ # #=> (33/1)
461
+ # DateTime.new(2001,2,3) - DateTime.new(2001,2,2,12)
462
+ # #=> (1/2)
463
+ #
464
+ def -: (Integer | Rational other) -> Date
465
+ | (Date other) -> Rational
466
+
467
+ # Returns a date object pointing `n` months before self. The argument `n` should
468
+ # be a numeric value.
469
+ #
470
+ # Date.new(2001,2,3) << 1 #=> #<Date: 2001-01-03 ...>
471
+ # Date.new(2001,2,3) << -2 #=> #<Date: 2001-04-03 ...>
472
+ #
473
+ # When the same day does not exist for the corresponding month, the last day of
474
+ # the month is used instead:
475
+ #
476
+ # Date.new(2001,3,28) << 1 #=> #<Date: 2001-02-28 ...>
477
+ # Date.new(2001,3,31) << 1 #=> #<Date: 2001-02-28 ...>
478
+ #
479
+ # This also results in the following, possibly unexpected, behavior:
480
+ #
481
+ # Date.new(2001,3,31) << 2 #=> #<Date: 2001-01-31 ...>
482
+ # Date.new(2001,3,31) << 1 << 1 #=> #<Date: 2001-01-28 ...>
483
+ #
484
+ # Date.new(2001,3,31) << 1 << -1 #=> #<Date: 2001-03-28 ...>
485
+ #
486
+ def <<: (Integer month) -> Date
487
+
488
+ # Compares the two dates and returns -1, zero, 1 or nil. The other should be a
489
+ # date object or a numeric value as an astronomical Julian day number.
490
+ #
491
+ # Date.new(2001,2,3) <=> Date.new(2001,2,4) #=> -1
492
+ # Date.new(2001,2,3) <=> Date.new(2001,2,3) #=> 0
493
+ # Date.new(2001,2,3) <=> Date.new(2001,2,2) #=> 1
494
+ # Date.new(2001,2,3) <=> Object.new #=> nil
495
+ # Date.new(2001,2,3) <=> Rational(4903887,2) #=> 0
496
+ #
497
+ # See also Comparable.
498
+ #
499
+ def <=>: (Date | Rational | Object other) -> Integer?
500
+
501
+ # Returns true if they are the same day.
502
+ #
503
+ # Date.new(2001,2,3) === Date.new(2001,2,3)
504
+ # #=> true
505
+ # Date.new(2001,2,3) === Date.new(2001,2,4)
506
+ # #=> false
507
+ # DateTime.new(2001,2,3) === DateTime.new(2001,2,3,12)
508
+ # #=> true
509
+ # DateTime.new(2001,2,3) === DateTime.new(2001,2,3,0,0,0,'+24:00')
510
+ # #=> true
511
+ # DateTime.new(2001,2,3) === DateTime.new(2001,2,4,0,0,0,'+24:00')
512
+ # #=> false
513
+ #
514
+ def ===: (Date other) -> bool
515
+
516
+ # Returns a date object pointing `n` months after self. The argument `n` should
517
+ # be a numeric value.
518
+ #
519
+ # Date.new(2001,2,3) >> 1 #=> #<Date: 2001-03-03 ...>
520
+ # Date.new(2001,2,3) >> -2 #=> #<Date: 2000-12-03 ...>
521
+ #
522
+ # When the same day does not exist for the corresponding month, the last day of
523
+ # the month is used instead:
524
+ #
525
+ # Date.new(2001,1,28) >> 1 #=> #<Date: 2001-02-28 ...>
526
+ # Date.new(2001,1,31) >> 1 #=> #<Date: 2001-02-28 ...>
527
+ #
528
+ # This also results in the following, possibly unexpected, behavior:
529
+ #
530
+ # Date.new(2001,1,31) >> 2 #=> #<Date: 2001-03-31 ...>
531
+ # Date.new(2001,1,31) >> 1 >> 1 #=> #<Date: 2001-03-28 ...>
532
+ #
533
+ # Date.new(2001,1,31) >> 1 >> -1 #=> #<Date: 2001-01-28 ...>
534
+ #
535
+ def >>: (Integer month) -> Date
536
+
537
+ # Returns the astronomical Julian day number. This is a fractional number,
538
+ # which is not adjusted by the offset.
539
+ #
540
+ # DateTime.new(2001,2,3,4,5,6,'+7').ajd #=> (11769328217/4800)
541
+ # DateTime.new(2001,2,2,14,5,6,'-7').ajd #=> (11769328217/4800)
542
+ #
543
+ def ajd: () -> Rational
544
+
545
+ # Returns the astronomical modified Julian day number. This is a fractional
546
+ # number, which is not adjusted by the offset.
547
+ #
548
+ # DateTime.new(2001,2,3,4,5,6,'+7').amjd #=> (249325817/4800)
549
+ # DateTime.new(2001,2,2,14,5,6,'-7').amjd #=> (249325817/4800)
550
+ #
551
+ def amjd: () -> Rational
552
+
553
+ # Returns a string in asctime(3) format (but without "n\0" at the end). This
554
+ # method is equivalent to strftime('%c').
555
+ #
556
+ # See also asctime(3) or ctime(3).
557
+ #
558
+ def asctime: () -> String
559
+
560
+ # Returns a string in asctime(3) format (but without "n\0" at the end). This
561
+ # method is equivalent to strftime('%c').
562
+ #
563
+ # See also asctime(3) or ctime(3).
564
+ #
565
+ def ctime: () -> String
566
+
567
+ # Returns the day of calendar week (1-7, Monday is 1).
568
+ #
569
+ # Date.new(2001,2,3).cwday #=> 6
570
+ #
571
+ def cwday: () -> Integer
572
+
573
+ # Returns the calendar week number (1-53).
574
+ #
575
+ # Date.new(2001,2,3).cweek #=> 5
576
+ #
577
+ def cweek: () -> Integer
578
+
579
+ # Returns the calendar week based year.
580
+ #
581
+ # Date.new(2001,2,3).cwyear #=> 2001
582
+ # Date.new(2000,1,1).cwyear #=> 1999
583
+ #
584
+ def cwyear: () -> Integer
585
+
586
+ # Returns the day of the month (1-31).
587
+ #
588
+ # Date.new(2001,2,3).mday #=> 3
589
+ #
590
+ def day: () -> Integer
591
+
592
+ # This method is equivalent to step(min, -1){|date| ...}.
593
+ #
594
+ def downto: (Date min) { (Date) -> untyped } -> Date
595
+ | (Date min) -> Enumerator[Date, Date]
596
+
597
+ # This method is equivalent to new_start(Date::ENGLAND).
598
+ #
599
+ def england: () -> Date
600
+
601
+ # Returns true if the date is Friday.
602
+ #
603
+ def friday?: () -> bool
604
+
605
+ # This method is equivalent to new_start(Date::GREGORIAN).
606
+ #
607
+ def gregorian: () -> Date
608
+
609
+ # Returns true if the date is on or after the day of calendar reform.
610
+ #
611
+ # Date.new(1582,10,15).gregorian? #=> true
612
+ # (Date.new(1582,10,15) - 1).gregorian? #=> false
613
+ #
614
+ def gregorian?: () -> bool
615
+
616
+ # This method is equivalent to strftime('%a, %d %b %Y %T GMT'). See also RFC
617
+ # 2616.
618
+ #
619
+ def httpdate: () -> String
620
+
621
+ # Returns the value as a string for inspection.
622
+ #
623
+ # Date.new(2001,2,3).inspect
624
+ # #=> "#<Date: 2001-02-03>"
625
+ # DateTime.new(2001,2,3,4,5,6,'-7').inspect
626
+ # #=> "#<DateTime: 2001-02-03T04:05:06-07:00>"
627
+ #
628
+ def inspect: () -> String
629
+
630
+ # This method is equivalent to strftime('%F').
631
+ #
632
+ def iso8601: () -> String
633
+
634
+ # This method is equivalent to new_start(Date::ITALY).
635
+ #
636
+ def italy: () -> Date
637
+
638
+ # Returns the Julian day number. This is a whole number, which is adjusted by
639
+ # the offset as the local time.
640
+ #
641
+ # DateTime.new(2001,2,3,4,5,6,'+7').jd #=> 2451944
642
+ # DateTime.new(2001,2,3,4,5,6,'-7').jd #=> 2451944
643
+ #
644
+ def jd: () -> Integer
645
+
646
+ # Returns a string in a JIS X 0301 format.
647
+ #
648
+ # Date.new(2001,2,3).jisx0301 #=> "H13.02.03"
649
+ #
650
+ def jisx0301: () -> String
651
+
652
+ # This method is equivalent to new_start(Date::JULIAN).
653
+ #
654
+ def julian: () -> Date
655
+
656
+ # Returns true if the date is before the day of calendar reform.
657
+ #
658
+ # Date.new(1582,10,15).julian? #=> false
659
+ # (Date.new(1582,10,15) - 1).julian? #=> true
660
+ #
661
+ def julian?: () -> bool
662
+
663
+ # Returns the Lilian day number. This is a whole number, which is adjusted by
664
+ # the offset as the local time.
665
+ #
666
+ # Date.new(2001,2,3).ld #=> 152784
667
+ #
668
+ def ld: () -> Integer
669
+
670
+ # Returns true if the year is a leap year.
671
+ #
672
+ # Date.new(2000).leap? #=> true
673
+ # Date.new(2001).leap? #=> false
674
+ #
675
+ def leap?: () -> bool
676
+
677
+ # Returns the day of the month (1-31).
678
+ #
679
+ # Date.new(2001,2,3).mday #=> 3
680
+ #
681
+ def mday: () -> Integer
682
+
683
+ # Returns the modified Julian day number. This is a whole number, which is
684
+ # adjusted by the offset as the local time.
685
+ #
686
+ # DateTime.new(2001,2,3,4,5,6,'+7').mjd #=> 51943
687
+ # DateTime.new(2001,2,3,4,5,6,'-7').mjd #=> 51943
688
+ #
689
+ def mjd: () -> Integer
690
+
691
+ # Returns the month (1-12).
692
+ #
693
+ # Date.new(2001,2,3).mon #=> 2
694
+ #
695
+ def mon: () -> Integer
696
+
697
+ # Returns true if the date is Monday.
698
+ #
699
+ def monday?: () -> bool
700
+
701
+ # Returns the month (1-12).
702
+ #
703
+ # Date.new(2001,2,3).mon #=> 2
704
+ #
705
+ def month: () -> Integer
706
+
707
+ # Duplicates self and resets its day of calendar reform.
708
+ #
709
+ # d = Date.new(1582,10,15)
710
+ # d.new_start(Date::JULIAN) #=> #<Date: 1582-10-05 ...>
711
+ #
712
+ def new_start: (?Integer start) -> Date
713
+
714
+ # Returns a date object denoting the following day.
715
+ #
716
+ def next: () -> Date
717
+
718
+ # This method is equivalent to d + n.
719
+ #
720
+ def next_day: (?Integer day) -> Date
721
+
722
+ # This method is equivalent to d >> n.
723
+ #
724
+ def next_month: (?Integer month) -> Date
725
+
726
+ # This method is equivalent to d >> (n * 12).
727
+ #
728
+ # Date.new(2001,2,3).next_year #=> #<Date: 2002-02-03 ...>
729
+ # Date.new(2008,2,29).next_year #=> #<Date: 2009-02-28 ...>
730
+ # Date.new(2008,2,29).next_year(4) #=> #<Date: 2012-02-29 ...>
731
+ #
732
+ def next_year: (?Integer year) -> Date
733
+
734
+ # This method is equivalent to d - n.
735
+ #
736
+ def prev_day: (?Integer day) -> Date
737
+
738
+ # This method is equivalent to d << n.
739
+ #
740
+ def prev_month: (?Integer month) -> Date
741
+
742
+ # This method is equivalent to d << (n * 12).
743
+ #
744
+ # Date.new(2001,2,3).prev_year #=> #<Date: 2000-02-03 ...>
745
+ # Date.new(2008,2,29).prev_year #=> #<Date: 2007-02-28 ...>
746
+ # Date.new(2008,2,29).prev_year(4) #=> #<Date: 2004-02-29 ...>
747
+ #
748
+ def prev_year: (?Integer year) -> Date
749
+
750
+ # This method is equivalent to strftime('%a, %-d %b %Y %T %z').
751
+ #
752
+ def rfc2822: () -> String
753
+
754
+ # This method is equivalent to strftime('%FT%T%:z').
755
+ #
756
+ def rfc3339: () -> String
757
+
758
+ # This method is equivalent to strftime('%a, %-d %b %Y %T %z').
759
+ #
760
+ def rfc822: () -> String
761
+
762
+ # Returns true if the date is Saturday.
763
+ #
764
+ def saturday?: () -> bool
765
+
766
+ # Returns the Julian day number denoting the day of calendar reform.
767
+ #
768
+ # Date.new(2001,2,3).start #=> 2299161.0
769
+ # Date.new(2001,2,3,Date::GREGORIAN).start #=> -Infinity
770
+ #
771
+ def start: () -> Float
772
+
773
+ # Iterates evaluation of the given block, which takes a date object. The limit
774
+ # should be a date object.
775
+ #
776
+ # Date.new(2001).step(Date.new(2001,-1,-1)).select{|d| d.sunday?}.size
777
+ # #=> 52
778
+ #
779
+ def step: (Date limit, ?Integer step) { (Date) -> untyped } -> Date
780
+ | (Date limit, ?Integer step) -> ::Enumerator[Date, Date]
781
+
782
+ # Formats date according to the directives in the given format string. The
783
+ # directives begin with a percent (%) character. Any text not listed as a
784
+ # directive will be passed through to the output string.
785
+ #
786
+ # A directive consists of a percent (%) character, zero or more flags, an
787
+ # optional minimum field width, an optional modifier, and a conversion specifier
788
+ # as follows.
789
+ #
790
+ # %<flags><width><modifier><conversion>
791
+ #
792
+ # Flags:
793
+ # - don't pad a numerical output.
794
+ # _ use spaces for padding.
795
+ # 0 use zeros for padding.
796
+ # ^ upcase the result string.
797
+ # # change case.
798
+ #
799
+ # The minimum field width specifies the minimum width.
800
+ #
801
+ # The modifiers are "E", "O", ":", "::" and ":::". "E" and "O" are ignored. No
802
+ # effect to result currently.
803
+ #
804
+ # Format directives:
805
+ #
806
+ # Date (Year, Month, Day):
807
+ # %Y - Year with century (can be negative, 4 digits at least)
808
+ # -0001, 0000, 1995, 2009, 14292, etc.
809
+ # %C - year / 100 (round down. 20 in 2009)
810
+ # %y - year % 100 (00..99)
811
+ #
812
+ # %m - Month of the year, zero-padded (01..12)
813
+ # %_m blank-padded ( 1..12)
814
+ # %-m no-padded (1..12)
815
+ # %B - The full month name (``January'')
816
+ # %^B uppercased (``JANUARY'')
817
+ # %b - The abbreviated month name (``Jan'')
818
+ # %^b uppercased (``JAN'')
819
+ # %h - Equivalent to %b
820
+ #
821
+ # %d - Day of the month, zero-padded (01..31)
822
+ # %-d no-padded (1..31)
823
+ # %e - Day of the month, blank-padded ( 1..31)
824
+ #
825
+ # %j - Day of the year (001..366)
826
+ #
827
+ # Time (Hour, Minute, Second, Subsecond):
828
+ # %H - Hour of the day, 24-hour clock, zero-padded (00..23)
829
+ # %k - Hour of the day, 24-hour clock, blank-padded ( 0..23)
830
+ # %I - Hour of the day, 12-hour clock, zero-padded (01..12)
831
+ # %l - Hour of the day, 12-hour clock, blank-padded ( 1..12)
832
+ # %P - Meridian indicator, lowercase (``am'' or ``pm'')
833
+ # %p - Meridian indicator, uppercase (``AM'' or ``PM'')
834
+ #
835
+ # %M - Minute of the hour (00..59)
836
+ #
837
+ # %S - Second of the minute (00..60)
838
+ #
839
+ # %L - Millisecond of the second (000..999)
840
+ # %N - Fractional seconds digits, default is 9 digits (nanosecond)
841
+ # %3N millisecond (3 digits) %15N femtosecond (15 digits)
842
+ # %6N microsecond (6 digits) %18N attosecond (18 digits)
843
+ # %9N nanosecond (9 digits) %21N zeptosecond (21 digits)
844
+ # %12N picosecond (12 digits) %24N yoctosecond (24 digits)
845
+ #
846
+ # Time zone:
847
+ # %z - Time zone as hour and minute offset from UTC (e.g. +0900)
848
+ # %:z - hour and minute offset from UTC with a colon (e.g. +09:00)
849
+ # %::z - hour, minute and second offset from UTC (e.g. +09:00:00)
850
+ # %:::z - hour, minute and second offset from UTC
851
+ # (e.g. +09, +09:30, +09:30:30)
852
+ # %Z - Equivalent to %:z (e.g. +09:00)
853
+ #
854
+ # Weekday:
855
+ # %A - The full weekday name (``Sunday'')
856
+ # %^A uppercased (``SUNDAY'')
857
+ # %a - The abbreviated name (``Sun'')
858
+ # %^a uppercased (``SUN'')
859
+ # %u - Day of the week (Monday is 1, 1..7)
860
+ # %w - Day of the week (Sunday is 0, 0..6)
861
+ #
862
+ # ISO 8601 week-based year and week number:
863
+ # The week 1 of YYYY starts with a Monday and includes YYYY-01-04.
864
+ # The days in the year before the first week are in the last week of
865
+ # the previous year.
866
+ # %G - The week-based year
867
+ # %g - The last 2 digits of the week-based year (00..99)
868
+ # %V - Week number of the week-based year (01..53)
869
+ #
870
+ # Week number:
871
+ # The week 1 of YYYY starts with a Sunday or Monday (according to %U
872
+ # or %W). The days in the year before the first week are in week 0.
873
+ # %U - Week number of the year. The week starts with Sunday. (00..53)
874
+ # %W - Week number of the year. The week starts with Monday. (00..53)
875
+ #
876
+ # Seconds since the Unix Epoch:
877
+ # %s - Number of seconds since 1970-01-01 00:00:00 UTC.
878
+ # %Q - Number of milliseconds since 1970-01-01 00:00:00 UTC.
879
+ #
880
+ # Literal string:
881
+ # %n - Newline character (\n)
882
+ # %t - Tab character (\t)
883
+ # %% - Literal ``%'' character
884
+ #
885
+ # Combination:
886
+ # %c - date and time (%a %b %e %T %Y)
887
+ # %D - Date (%m/%d/%y)
888
+ # %F - The ISO 8601 date format (%Y-%m-%d)
889
+ # %v - VMS date (%e-%b-%Y)
890
+ # %x - Same as %D
891
+ # %X - Same as %T
892
+ # %r - 12-hour time (%I:%M:%S %p)
893
+ # %R - 24-hour time (%H:%M)
894
+ # %T - 24-hour time (%H:%M:%S)
895
+ # %+ - date(1) (%a %b %e %H:%M:%S %Z %Y)
896
+ #
897
+ # This method is similar to the strftime() function defined in ISO C and POSIX.
898
+ # Several directives (%a, %A, %b, %B, %c, %p, %r, %x, %X, %E*, %O* and %Z) are
899
+ # locale dependent in the function. However, this method is locale independent.
900
+ # So, the result may differ even if the same format string is used in other
901
+ # systems such as C. It is good practice to avoid %x and %X because there are
902
+ # corresponding locale independent representations, %D and %T.
903
+ #
904
+ # Examples:
905
+ #
906
+ # d = DateTime.new(2007,11,19,8,37,48,"-06:00")
907
+ # #=> #<DateTime: 2007-11-19T08:37:48-0600 ...>
908
+ # d.strftime("Printed on %m/%d/%Y") #=> "Printed on 11/19/2007"
909
+ # d.strftime("at %I:%M%p") #=> "at 08:37AM"
910
+ #
911
+ # Various ISO 8601 formats:
912
+ # %Y%m%d => 20071119 Calendar date (basic)
913
+ # %F => 2007-11-19 Calendar date (extended)
914
+ # %Y-%m => 2007-11 Calendar date, reduced accuracy, specific month
915
+ # %Y => 2007 Calendar date, reduced accuracy, specific year
916
+ # %C => 20 Calendar date, reduced accuracy, specific century
917
+ # %Y%j => 2007323 Ordinal date (basic)
918
+ # %Y-%j => 2007-323 Ordinal date (extended)
919
+ # %GW%V%u => 2007W471 Week date (basic)
920
+ # %G-W%V-%u => 2007-W47-1 Week date (extended)
921
+ # %GW%V => 2007W47 Week date, reduced accuracy, specific week (basic)
922
+ # %G-W%V => 2007-W47 Week date, reduced accuracy, specific week (extended)
923
+ # %H%M%S => 083748 Local time (basic)
924
+ # %T => 08:37:48 Local time (extended)
925
+ # %H%M => 0837 Local time, reduced accuracy, specific minute (basic)
926
+ # %H:%M => 08:37 Local time, reduced accuracy, specific minute (extended)
927
+ # %H => 08 Local time, reduced accuracy, specific hour
928
+ # %H%M%S,%L => 083748,000 Local time with decimal fraction, comma as decimal sign (basic)
929
+ # %T,%L => 08:37:48,000 Local time with decimal fraction, comma as decimal sign (extended)
930
+ # %H%M%S.%L => 083748.000 Local time with decimal fraction, full stop as decimal sign (basic)
931
+ # %T.%L => 08:37:48.000 Local time with decimal fraction, full stop as decimal sign (extended)
932
+ # %H%M%S%z => 083748-0600 Local time and the difference from UTC (basic)
933
+ # %T%:z => 08:37:48-06:00 Local time and the difference from UTC (extended)
934
+ # %Y%m%dT%H%M%S%z => 20071119T083748-0600 Date and time of day for calendar date (basic)
935
+ # %FT%T%:z => 2007-11-19T08:37:48-06:00 Date and time of day for calendar date (extended)
936
+ # %Y%jT%H%M%S%z => 2007323T083748-0600 Date and time of day for ordinal date (basic)
937
+ # %Y-%jT%T%:z => 2007-323T08:37:48-06:00 Date and time of day for ordinal date (extended)
938
+ # %GW%V%uT%H%M%S%z => 2007W471T083748-0600 Date and time of day for week date (basic)
939
+ # %G-W%V-%uT%T%:z => 2007-W47-1T08:37:48-06:00 Date and time of day for week date (extended)
940
+ # %Y%m%dT%H%M => 20071119T0837 Calendar date and local time (basic)
941
+ # %FT%R => 2007-11-19T08:37 Calendar date and local time (extended)
942
+ # %Y%jT%H%MZ => 2007323T0837Z Ordinal date and UTC of day (basic)
943
+ # %Y-%jT%RZ => 2007-323T08:37Z Ordinal date and UTC of day (extended)
944
+ # %GW%V%uT%H%M%z => 2007W471T0837-0600 Week date and local time and difference from UTC (basic)
945
+ # %G-W%V-%uT%R%:z => 2007-W47-1T08:37-06:00 Week date and local time and difference from UTC (extended)
946
+ #
947
+ # See also strftime(3) and ::strptime.
948
+ #
949
+ def strftime: (?String format) -> String
950
+
951
+ # Returns a date object denoting the following day.
952
+ #
953
+ def succ: () -> Date
954
+
955
+ # Returns true if the date is Sunday.
956
+ #
957
+ def sunday?: () -> bool
958
+
959
+ # Returns true if the date is Thursday.
960
+ #
961
+ def thursday?: () -> bool
962
+
963
+ # Returns self.
964
+ #
965
+ def to_date: () -> Date
966
+
967
+ # Returns a DateTime object which denotes self.
968
+ #
969
+ def to_datetime: () -> DateTime
970
+
971
+ # Returns a string in an ISO 8601 format. (This method doesn't use the expanded
972
+ # representations.)
973
+ #
974
+ # Date.new(2001,2,3).to_s #=> "2001-02-03"
975
+ #
976
+ def to_s: () -> String
977
+
978
+ # Returns a Time object which denotes self. If self is a julian date, convert it
979
+ # to a gregorian date before converting it to Time.
980
+ #
981
+ def to_time: () -> Time
982
+
983
+ # Returns true if the date is Tuesday.
984
+ #
985
+ def tuesday?: () -> bool
986
+
987
+ # This method is equivalent to step(max, 1){|date| ...}.
988
+ #
989
+ def upto: (Date max) { (Date) -> untyped } -> Date
990
+ | (Date max) -> ::Enumerator[Date, Date]
991
+
992
+ # Returns the day of week (0-6, Sunday is zero).
993
+ #
994
+ # Date.new(2001,2,3).wday #=> 6
995
+ #
996
+ def wday: () -> Integer
997
+
998
+ # Returns true if the date is Wednesday.
999
+ #
1000
+ def wednesday?: () -> bool
1001
+
1002
+ # This method is equivalent to strftime('%F').
1003
+ #
1004
+ def xmlschema: () -> String
1005
+
1006
+ # Returns the day of the year (1-366).
1007
+ #
1008
+ # Date.new(2001,2,3).yday #=> 34
1009
+ #
1010
+ def yday: () -> Integer
1011
+
1012
+ # Returns the year.
1013
+ #
1014
+ # Date.new(2001,2,3).year #=> 2001
1015
+ # (Date.new(1,1,1) - 1).year #=> 0
1016
+ #
1017
+ def year: () -> Integer
1018
+ end
1019
+
1020
+ # An array of strings of abbreviated day names in English. The first is "Sun".
1021
+ #
1022
+ Date::ABBR_DAYNAMES: Array[String]
1023
+
1024
+ # An array of strings of abbreviated month names in English. The first element
1025
+ # is nil.
1026
+ #
1027
+ Date::ABBR_MONTHNAMES: Array[String?]
1028
+
1029
+ # An array of strings of the full names of days of the week in English. The
1030
+ # first is "Sunday".
1031
+ #
1032
+ Date::DAYNAMES: Array[String]
1033
+
1034
+ # The Julian day number of the day of calendar reform for England and her
1035
+ # colonies.
1036
+ #
1037
+ Date::ENGLAND: Integer
1038
+
1039
+ # The Julian day number of the day of calendar reform for the proleptic
1040
+ # Gregorian calendar.
1041
+ #
1042
+ Date::GREGORIAN: Integer
1043
+
1044
+ # The Julian day number of the day of calendar reform for Italy and some
1045
+ # catholic countries.
1046
+ #
1047
+ Date::ITALY: Integer
1048
+
1049
+ # The Julian day number of the day of calendar reform for the proleptic Julian
1050
+ # calendar.
1051
+ #
1052
+ Date::JULIAN: Integer
1053
+
1054
+ # An array of strings of full month names in English. The first element is nil.
1055
+ #
1056
+ Date::MONTHNAMES: Array[String?]