steep 0.14.0 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/exe/rbs +1 -1
- data/lib/steep/annotation_parser.rb +4 -4
- data/lib/steep/ast/buffer.rb +11 -7
- data/lib/steep/ast/builtin.rb +8 -0
- data/lib/steep/ast/types/factory.rb +55 -55
- data/lib/steep/drivers/check.rb +20 -4
- data/lib/steep/drivers/langserver.rb +6 -1
- data/lib/steep/drivers/vendor.rb +2 -2
- data/lib/steep/project/completion_provider.rb +5 -11
- data/lib/steep/project/dsl.rb +14 -0
- data/lib/steep/project/file.rb +42 -46
- data/lib/steep/project/hover_content.rb +11 -5
- data/lib/steep/project/options.rb +25 -3
- data/lib/steep/project/target.rb +10 -4
- data/lib/steep/signature/errors.rb +1 -1
- data/lib/steep/signature/validator.rb +8 -8
- data/lib/steep/source.rb +1 -1
- data/lib/steep/type_construction.rb +987 -711
- data/lib/steep/type_inference/constant_env.rb +1 -1
- data/lib/steep/type_inference/context.rb +7 -3
- data/lib/steep/type_inference/context_array.rb +111 -0
- data/lib/steep/type_inference/local_variable_type_env.rb +226 -0
- data/lib/steep/type_inference/logic.rb +130 -0
- data/lib/steep/type_inference/type_env.rb +5 -69
- data/lib/steep/typing.rb +79 -22
- data/lib/steep/version.rb +1 -1
- data/lib/steep.rb +6 -1
- data/smoke/alias/Steepfile +1 -0
- data/smoke/and/Steepfile +1 -0
- data/smoke/array/Steepfile +1 -0
- data/smoke/array/b.rb +0 -2
- data/smoke/block/Steepfile +1 -0
- data/smoke/case/Steepfile +1 -0
- data/smoke/class/Steepfile +1 -0
- data/smoke/const/Steepfile +1 -0
- data/smoke/dstr/Steepfile +1 -0
- data/smoke/ensure/Steepfile +1 -0
- data/smoke/enumerator/Steepfile +1 -0
- data/smoke/extension/Steepfile +1 -0
- data/smoke/extension/c.rb +1 -0
- data/smoke/hash/Steepfile +1 -0
- data/smoke/hello/Steepfile +1 -0
- data/smoke/if/Steepfile +1 -0
- data/smoke/if/a.rb +1 -1
- data/smoke/implements/Steepfile +1 -0
- data/smoke/initialize/Steepfile +1 -0
- data/smoke/integer/Steepfile +1 -0
- data/smoke/interface/Steepfile +1 -0
- data/smoke/kwbegin/Steepfile +1 -0
- data/smoke/lambda/Steepfile +1 -0
- data/smoke/literal/Steepfile +1 -0
- data/smoke/map/Steepfile +1 -0
- data/smoke/method/Steepfile +1 -0
- data/smoke/module/Steepfile +1 -0
- data/smoke/regexp/Steepfile +1 -0
- data/smoke/regression/Steepfile +1 -0
- data/smoke/rescue/Steepfile +1 -0
- data/smoke/rescue/a.rb +1 -1
- data/smoke/self/Steepfile +1 -0
- data/smoke/skip/Steepfile +1 -0
- data/smoke/stdout/Steepfile +1 -0
- data/smoke/super/Steepfile +1 -0
- data/smoke/type_case/Steepfile +1 -0
- data/smoke/yield/Steepfile +1 -0
- data/steep.gemspec +1 -1
- data/vendor/ruby-signature/.gitignore +2 -2
- data/vendor/ruby-signature/README.md +2 -2
- data/vendor/ruby-signature/Rakefile +2 -2
- data/vendor/ruby-signature/bin/annotate-with-rdoc +14 -13
- data/vendor/ruby-signature/bin/console +1 -1
- data/vendor/ruby-signature/bin/sort +7 -6
- data/vendor/ruby-signature/bin/test_runner.rb +0 -1
- data/vendor/ruby-signature/docs/CONTRIBUTING.md +1 -1
- data/vendor/ruby-signature/docs/sigs.md +3 -3
- data/vendor/ruby-signature/docs/stdlib.md +1 -1
- data/vendor/ruby-signature/docs/syntax.md +9 -9
- data/vendor/ruby-signature/exe/rbs +5 -1
- data/vendor/ruby-signature/lib/rbs/ast/annotation.rb +27 -0
- data/vendor/ruby-signature/lib/rbs/ast/comment.rb +27 -0
- data/vendor/ruby-signature/lib/rbs/ast/declarations.rb +395 -0
- data/vendor/ruby-signature/lib/rbs/ast/members.rb +362 -0
- data/vendor/ruby-signature/lib/rbs/buffer.rb +50 -0
- data/vendor/ruby-signature/lib/rbs/builtin_names.rb +55 -0
- data/vendor/ruby-signature/lib/rbs/cli.rb +558 -0
- data/vendor/ruby-signature/lib/rbs/constant.rb +26 -0
- data/vendor/ruby-signature/lib/rbs/constant_table.rb +150 -0
- data/vendor/ruby-signature/lib/rbs/definition.rb +170 -0
- data/vendor/ruby-signature/lib/rbs/definition_builder.rb +919 -0
- data/vendor/ruby-signature/lib/rbs/environment.rb +281 -0
- data/vendor/ruby-signature/lib/rbs/environment_loader.rb +136 -0
- data/vendor/ruby-signature/lib/rbs/environment_walker.rb +124 -0
- data/vendor/ruby-signature/lib/rbs/errors.rb +187 -0
- data/vendor/ruby-signature/lib/rbs/location.rb +102 -0
- data/vendor/ruby-signature/lib/rbs/method_type.rb +123 -0
- data/vendor/ruby-signature/lib/rbs/namespace.rb +91 -0
- data/vendor/ruby-signature/lib/{ruby/signature → rbs}/parser.rb +21 -23
- data/vendor/ruby-signature/lib/{ruby/signature → rbs}/parser.y +18 -18
- data/vendor/ruby-signature/lib/rbs/prototype/rb.rb +553 -0
- data/vendor/ruby-signature/lib/rbs/prototype/rbi.rb +587 -0
- data/vendor/ruby-signature/lib/rbs/prototype/runtime.rb +381 -0
- data/vendor/ruby-signature/lib/rbs/substitution.rb +46 -0
- data/vendor/ruby-signature/lib/rbs/test/errors.rb +61 -0
- data/vendor/ruby-signature/lib/rbs/test/hook.rb +294 -0
- data/vendor/ruby-signature/lib/{ruby/signature → rbs}/test/setup.rb +7 -7
- data/vendor/ruby-signature/lib/rbs/test/spy.rb +325 -0
- data/vendor/ruby-signature/lib/rbs/test/test_helper.rb +183 -0
- data/vendor/ruby-signature/lib/rbs/test/type_check.rb +254 -0
- data/vendor/ruby-signature/lib/rbs/test.rb +26 -0
- data/vendor/ruby-signature/lib/rbs/type_name.rb +70 -0
- data/vendor/ruby-signature/lib/rbs/types.rb +936 -0
- data/vendor/ruby-signature/lib/rbs/variance_calculator.rb +138 -0
- data/vendor/ruby-signature/lib/rbs/vendorer.rb +47 -0
- data/vendor/ruby-signature/lib/rbs/version.rb +3 -0
- data/vendor/ruby-signature/lib/rbs/writer.rb +269 -0
- data/vendor/ruby-signature/lib/rbs.rb +64 -0
- data/vendor/ruby-signature/lib/ruby/signature.rb +4 -61
- data/vendor/ruby-signature/{ruby-signature.gemspec → rbs.gemspec} +4 -4
- data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +58 -1
- data/vendor/ruby-signature/stdlib/base64/base64.rbs +69 -13
- data/vendor/ruby-signature/stdlib/benchmark/benchmark.rbs +372 -0
- data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +9 -0
- data/vendor/ruby-signature/stdlib/builtin/dir.rbs +1 -7
- data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +2 -1
- data/vendor/ruby-signature/stdlib/builtin/exception.rbs +3 -2
- data/vendor/ruby-signature/stdlib/builtin/file.rbs +902 -302
- data/vendor/ruby-signature/stdlib/builtin/gc.rbs +190 -68
- data/vendor/ruby-signature/stdlib/builtin/integer.rbs +3 -6
- data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +6 -4
- data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +146 -120
- data/vendor/ruby-signature/stdlib/builtin/math.rbs +310 -7
- data/vendor/ruby-signature/stdlib/builtin/method.rbs +11 -8
- data/vendor/ruby-signature/stdlib/builtin/module.rbs +959 -103
- data/vendor/ruby-signature/stdlib/builtin/proc.rbs +3 -0
- data/vendor/ruby-signature/stdlib/builtin/process.rbs +981 -108
- data/vendor/ruby-signature/stdlib/builtin/random.rbs +215 -41
- data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +47 -0
- data/vendor/ruby-signature/stdlib/builtin/string.rbs +9 -2
- data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +282 -11
- data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +11 -13
- data/vendor/ruby-signature/stdlib/builtin/thread.rbs +25 -29
- data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +1 -1
- data/vendor/ruby-signature/stdlib/builtin/time.rbs +875 -567
- data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +243 -44
- data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +103 -109
- data/vendor/ruby-signature/stdlib/coverage/coverage.rbs +62 -0
- data/vendor/ruby-signature/stdlib/csv/csv.rbs +773 -0
- data/vendor/ruby-signature/stdlib/erb/erb.rbs +375 -1
- data/vendor/ruby-signature/stdlib/find/find.rbs +0 -4
- data/vendor/ruby-signature/stdlib/ipaddr/ipaddr.rbs +247 -0
- data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +1088 -16
- data/vendor/ruby-signature/stdlib/set/set.rbs +251 -27
- metadata +49 -44
- data/exe/ruby-signature +0 -3
- data/vendor/ruby-signature/exe/ruby-signature +0 -7
- data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +0 -29
- data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +0 -29
- data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +0 -391
- data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +0 -364
- data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +0 -52
- data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +0 -54
- data/vendor/ruby-signature/lib/ruby/signature/cli.rb +0 -555
- data/vendor/ruby-signature/lib/ruby/signature/constant.rb +0 -28
- data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +0 -152
- data/vendor/ruby-signature/lib/ruby/signature/definition.rb +0 -172
- data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +0 -921
- data/vendor/ruby-signature/lib/ruby/signature/environment.rb +0 -283
- data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +0 -138
- data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +0 -126
- data/vendor/ruby-signature/lib/ruby/signature/errors.rb +0 -189
- data/vendor/ruby-signature/lib/ruby/signature/location.rb +0 -104
- data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +0 -125
- data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +0 -93
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -444
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +0 -579
- data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +0 -383
- data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +0 -48
- data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +0 -63
- data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +0 -290
- data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +0 -327
- data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +0 -185
- data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +0 -256
- data/vendor/ruby-signature/lib/ruby/signature/test.rb +0 -28
- data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +0 -72
- data/vendor/ruby-signature/lib/ruby/signature/types.rb +0 -932
- data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +0 -140
- data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +0 -49
- data/vendor/ruby-signature/lib/ruby/signature/version.rb +0 -5
- data/vendor/ruby-signature/lib/ruby/signature/writer.rb +0 -271
@@ -1,186 +1,208 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
# (before 1823, after 2116, under nanosecond),
|
21
|
-
# [Time](Time) works slower as when integer is used.
|
22
|
-
#
|
23
|
-
#
|
1
|
+
# Time is an abstraction of dates and times. Time is stored internally as the
|
2
|
+
# number of seconds with fraction since the *Epoch*, January 1, 1970 00:00 UTC.
|
3
|
+
# Also see the library module Date. The Time class treats GMT (Greenwich Mean
|
4
|
+
# Time) and UTC (Coordinated Universal Time) as equivalent. GMT is the older way
|
5
|
+
# of referring to these baseline times but persists in the names of calls on
|
6
|
+
# POSIX systems.
|
7
|
+
#
|
8
|
+
# All times may have fraction. Be aware of this fact when comparing times with
|
9
|
+
# each other -- times that are apparently equal when displayed may be different
|
10
|
+
# when compared.
|
11
|
+
#
|
12
|
+
# Since Ruby 1.9.2, Time implementation uses a signed 63 bit integer, Bignum or
|
13
|
+
# Rational. The integer is a number of nanoseconds since the *Epoch* which can
|
14
|
+
# represent 1823-11-12 to 2116-02-20. When Bignum or Rational is used (before
|
15
|
+
# 1823, after 2116, under nanosecond), Time works slower as when integer is
|
16
|
+
# used.
|
17
|
+
#
|
18
|
+
# # Examples
|
19
|
+
#
|
24
20
|
# All of these examples were done using the EST timezone which is GMT-5.
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
# current system time.
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
# Time.new(2002, 10) #=> 2002-10-01 00:00:00 -0500
|
40
|
-
# Time.new(2002, 10, 31) #=> 2002-10-31 00:00:00 -0500
|
41
|
-
# ```
|
42
|
-
#
|
21
|
+
#
|
22
|
+
# ## Creating a new Time instance
|
23
|
+
#
|
24
|
+
# You can create a new instance of Time with Time::new. This will use the
|
25
|
+
# current system time. Time::now is an alias for this. You can also pass parts
|
26
|
+
# of the time to Time::new such as year, month, minute, etc. When you want to
|
27
|
+
# construct a time this way you must pass at least a year. If you pass the year
|
28
|
+
# with nothing else time will default to January 1 of that year at 00:00:00 with
|
29
|
+
# the current system timezone. Here are some examples:
|
30
|
+
#
|
31
|
+
# Time.new(2002) #=> 2002-01-01 00:00:00 -0500
|
32
|
+
# Time.new(2002, 10) #=> 2002-10-01 00:00:00 -0500
|
33
|
+
# Time.new(2002, 10, 31) #=> 2002-10-31 00:00:00 -0500
|
34
|
+
#
|
43
35
|
# You can pass a UTC offset:
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
# ```
|
48
|
-
#
|
36
|
+
#
|
37
|
+
# Time.new(2002, 10, 31, 2, 2, 2, "+02:00") #=> 2002-10-31 02:02:02 +0200
|
38
|
+
#
|
49
39
|
# Or a timezone object:
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
# You can also use [::gm](Time#method-c-gm),
|
57
|
-
# [::local](Time#method-c-local) and
|
58
|
-
# [::utc](Time#method-c-utc) to infer GMT, local and
|
40
|
+
#
|
41
|
+
# tz = timezone("Europe/Athens") # Eastern European Time, UTC+2
|
42
|
+
# Time.new(2002, 10, 31, 2, 2, 2, tz) #=> 2002-10-31 02:02:02 +0200
|
43
|
+
#
|
44
|
+
# You can also use Time::gm, Time::local and Time::utc to infer GMT, local and
|
59
45
|
# UTC timezones instead of using the current system setting.
|
60
|
-
#
|
61
|
-
# You can also create a new time using
|
62
|
-
# [::at](Time#method-c-at) which takes the number of
|
46
|
+
#
|
47
|
+
# You can also create a new time using Time::at which takes the number of
|
63
48
|
# seconds (or fraction of seconds) since the [Unix
|
64
49
|
# Epoch](http://en.wikipedia.org/wiki/Unix_time).
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
# ```ruby
|
77
|
-
# t = Time.new(1993, 02, 24, 12, 0, 0, "+09:00")
|
78
|
-
# ```
|
79
|
-
#
|
50
|
+
#
|
51
|
+
# Time.at(628232400) #=> 1989-11-28 00:00:00 -0500
|
52
|
+
#
|
53
|
+
# ## Working with an instance of Time
|
54
|
+
#
|
55
|
+
# Once you have an instance of Time there is a multitude of things you can do
|
56
|
+
# with it. Below are some examples. For all of the following examples, we will
|
57
|
+
# work on the assumption that you have done the following:
|
58
|
+
#
|
59
|
+
# t = Time.new(1993, 02, 24, 12, 0, 0, "+09:00")
|
60
|
+
#
|
80
61
|
# Was that a monday?
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
# ```
|
85
|
-
#
|
62
|
+
#
|
63
|
+
# t.monday? #=> false
|
64
|
+
#
|
86
65
|
# What year was that again?
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
90
|
-
# ```
|
91
|
-
#
|
66
|
+
#
|
67
|
+
# t.year #=> 1993
|
68
|
+
#
|
92
69
|
# Was it daylight savings at the time?
|
93
|
-
#
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
97
|
-
#
|
98
|
-
#
|
99
|
-
#
|
100
|
-
# ```ruby
|
101
|
-
# t + (60*60*24*365) #=> 1994-02-24 12:00:00 +0900
|
102
|
-
# ```
|
103
|
-
#
|
70
|
+
#
|
71
|
+
# t.dst? #=> false
|
72
|
+
#
|
73
|
+
# What's the day a year later?
|
74
|
+
#
|
75
|
+
# t + (60*60*24*365) #=> 1994-02-24 12:00:00 +0900
|
76
|
+
#
|
104
77
|
# How many seconds was that since the Unix Epoch?
|
105
|
-
#
|
106
|
-
#
|
107
|
-
#
|
108
|
-
# ```
|
109
|
-
#
|
78
|
+
#
|
79
|
+
# t.to_i #=> 730522800
|
80
|
+
#
|
110
81
|
# You can also do standard functions like compare two times.
|
111
|
-
#
|
112
|
-
#
|
113
|
-
#
|
114
|
-
#
|
115
|
-
#
|
116
|
-
#
|
117
|
-
#
|
118
|
-
#
|
119
|
-
#
|
120
|
-
#
|
121
|
-
#
|
122
|
-
#
|
123
|
-
#
|
124
|
-
#
|
125
|
-
#
|
126
|
-
#
|
127
|
-
#
|
128
|
-
#
|
129
|
-
#
|
130
|
-
#
|
131
|
-
#
|
132
|
-
#
|
133
|
-
#
|
134
|
-
#
|
135
|
-
# has attribute readers for the parts, e.g.
|
136
|
-
# [year](Time#method-i-year),
|
137
|
-
# [month](Time#method-i-month), and so on, and epoch
|
138
|
-
# time readers, [to\_i](Time#method-i-to_i). The
|
139
|
-
# sub-second attributes are fixed as 0, and
|
140
|
-
# [utc\_offset](Time#method-i-utc_offset),
|
141
|
-
# [zone](Time#method-i-zone),
|
142
|
-
# [isdst](Time#method-i-isdst), and their aliases are
|
143
|
-
# same as a [Time](Time) object in UTC. Also to\_time,
|
144
|
-
# \#+, and \#- methods are defined.
|
145
|
-
#
|
146
|
-
# The `name` method is used for marshaling. If this method is not defined
|
147
|
-
# on a timezone object, [Time](Time) objects using
|
148
|
-
# that timezone object can not be dumped by
|
149
|
-
# [Marshal](https://ruby-doc.org/core-2.6.3/Marshal.html).
|
150
|
-
#
|
151
|
-
# The `abbr` method is used by ‘%Z’ in
|
152
|
-
# [strftime](Time#method-i-strftime).
|
153
|
-
#
|
154
|
-
#
|
155
|
-
# At loading marshaled data, a timezone name will be converted to a
|
156
|
-
# timezone object by `find_timezone` class method, if the method is
|
82
|
+
#
|
83
|
+
# t1 = Time.new(2010)
|
84
|
+
# t2 = Time.new(2011)
|
85
|
+
#
|
86
|
+
# t1 == t2 #=> false
|
87
|
+
# t1 == t1 #=> true
|
88
|
+
# t1 < t2 #=> true
|
89
|
+
# t1 > t2 #=> false
|
90
|
+
#
|
91
|
+
# Time.new(2010,10,31).between?(t1, t2) #=> true
|
92
|
+
#
|
93
|
+
# ## Timezone argument
|
94
|
+
#
|
95
|
+
# A timezone argument must have `local_to_utc` and `utc_to_local` methods, and
|
96
|
+
# may have `name`, `abbr`, and `dst?` methods.
|
97
|
+
#
|
98
|
+
# The `local_to_utc` method should convert a Time-like object from the timezone
|
99
|
+
# to UTC, and `utc_to_local` is the opposite. The result also should be a Time
|
100
|
+
# or Time-like object (not necessary to be the same class). The #zone of the
|
101
|
+
# result is just ignored. Time-like argument to these methods is similar to a
|
102
|
+
# Time object in UTC without sub-second; it has attribute readers for the parts,
|
103
|
+
# e.g. #year, #month, and so on, and epoch time readers, #to_i. The sub-second
|
104
|
+
# attributes are fixed as 0, and #utc_offset, #zone, #isdst, and their aliases
|
105
|
+
# are same as a Time object in UTC. Also #to_time, #+, and #- methods are
|
157
106
|
# defined.
|
158
|
-
#
|
159
|
-
#
|
160
|
-
#
|
107
|
+
#
|
108
|
+
# The `name` method is used for marshaling. If this method is not defined on a
|
109
|
+
# timezone object, Time objects using that timezone object can not be dumped by
|
110
|
+
# Marshal.
|
111
|
+
#
|
112
|
+
# The `abbr` method is used by '%Z' in #strftime.
|
113
|
+
#
|
114
|
+
# The `dst?` method is called with a `Time` value and should return whether the
|
115
|
+
# `Time` value is in daylight savings time in the zone.
|
116
|
+
#
|
117
|
+
# ### Auto conversion to Timezone
|
118
|
+
#
|
119
|
+
# At loading marshaled data, a timezone name will be converted to a timezone
|
120
|
+
# object by `find_timezone` class method, if the method is defined.
|
121
|
+
#
|
122
|
+
# Similarly, that class method will be called when a timezone argument does not
|
123
|
+
# have the necessary methods mentioned above.
|
124
|
+
#
|
161
125
|
class Time < Object
|
162
126
|
include Comparable
|
163
127
|
|
128
|
+
# Creates a new Time object with the value given by `time`, the given number of
|
129
|
+
# `seconds_with_frac`, or `seconds` and `microseconds_with_frac` since the
|
130
|
+
# Epoch. `seconds_with_frac` and `microseconds_with_frac` can be an Integer,
|
131
|
+
# Float, Rational, or other Numeric. non-portable feature allows the offset to
|
132
|
+
# be negative on some systems.
|
133
|
+
#
|
134
|
+
# If `in` argument is given, the result is in that timezone or UTC offset, or if
|
135
|
+
# a numeric argument is given, the result is in local time.
|
136
|
+
#
|
137
|
+
# Time.at(0) #=> 1969-12-31 18:00:00 -0600
|
138
|
+
# Time.at(Time.at(0)) #=> 1969-12-31 18:00:00 -0600
|
139
|
+
# Time.at(946702800) #=> 1999-12-31 23:00:00 -0600
|
140
|
+
# Time.at(-284061600) #=> 1960-12-31 00:00:00 -0600
|
141
|
+
# Time.at(946684800.2).usec #=> 200000
|
142
|
+
# Time.at(946684800, 123456.789).nsec #=> 123456789
|
143
|
+
# Time.at(946684800, 123456789, :nsec).nsec #=> 123456789
|
144
|
+
#
|
164
145
|
def self.at: (Time | Numeric seconds) -> Time
|
165
146
|
| (Numeric seconds, ?Numeric microseconds_with_frac) -> Time
|
166
147
|
|
148
|
+
# Creates a Time object based on given values, interpreted as UTC (GMT). The
|
149
|
+
# year must be specified. Other values default to the minimum value for that
|
150
|
+
# field (and may be `nil` or omitted). Months may be specified by numbers from 1
|
151
|
+
# to 12, or by the three-letter English month names. Hours are specified on a
|
152
|
+
# 24-hour clock (0..23). Raises an ArgumentError if any values are out of range.
|
153
|
+
# Will also accept ten arguments in the order output by Time#to_a.
|
154
|
+
#
|
155
|
+
# `sec_with_frac` and `usec_with_frac` can have a fractional part.
|
156
|
+
#
|
157
|
+
# Time.utc(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 UTC
|
158
|
+
# Time.gm(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 UTC
|
159
|
+
#
|
167
160
|
def self.gm: (Integer year, ?Integer | String month, ?Integer day, ?Integer hour, ?Integer min, ?Numeric sec, ?Numeric usec_with_frac) -> Time
|
168
161
|
|
162
|
+
# Same as Time::gm, but interprets the values in the local time zone.
|
163
|
+
#
|
164
|
+
# Time.local(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 -0600
|
165
|
+
#
|
169
166
|
def self.local: (Integer year, ?Integer | String month, ?Integer day, ?Integer hour, ?Integer min, ?Numeric sec, ?Numeric usec_with_frac) -> Time
|
170
167
|
|
171
|
-
# Creates a new
|
172
|
-
# time. This is same as [::new](Time.downloaded.ruby_doc#method-c-new)
|
168
|
+
# Creates a new Time object for the current time. This is same as Time.new
|
173
169
|
# without arguments.
|
174
|
-
#
|
175
|
-
#
|
176
|
-
#
|
177
|
-
# ```
|
170
|
+
#
|
171
|
+
# Time.now #=> 2009-06-24 12:39:54 +0900
|
172
|
+
#
|
178
173
|
def self.now: () -> Time
|
179
174
|
|
175
|
+
# Creates a Time object based on given values, interpreted as UTC (GMT). The
|
176
|
+
# year must be specified. Other values default to the minimum value for that
|
177
|
+
# field (and may be `nil` or omitted). Months may be specified by numbers from 1
|
178
|
+
# to 12, or by the three-letter English month names. Hours are specified on a
|
179
|
+
# 24-hour clock (0..23). Raises an ArgumentError if any values are out of range.
|
180
|
+
# Will also accept ten arguments in the order output by Time#to_a.
|
181
|
+
#
|
182
|
+
# `sec_with_frac` and `usec_with_frac` can have a fractional part.
|
183
|
+
#
|
184
|
+
# Time.utc(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 UTC
|
185
|
+
# Time.gm(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 UTC
|
186
|
+
#
|
180
187
|
def self.utc: (Integer year, ?Integer | String month, ?Integer day, ?Integer hour, ?Integer min, ?Numeric sec, ?Numeric usec_with_frac) -> Time
|
181
188
|
|
189
|
+
# Addition --- Adds some number of seconds (possibly fractional) to *time* and
|
190
|
+
# returns that value as a new Time object.
|
191
|
+
#
|
192
|
+
# t = Time.now #=> 2007-11-19 08:22:21 -0600
|
193
|
+
# t + (60 * 60 * 24) #=> 2007-11-20 08:22:21 -0600
|
194
|
+
#
|
182
195
|
def +: (Numeric arg0) -> Time
|
183
196
|
|
197
|
+
# Difference --- Returns a difference in seconds as a Float between *time* and
|
198
|
+
# `other_time`, or subtracts the given number of seconds in `numeric` from
|
199
|
+
# *time*.
|
200
|
+
#
|
201
|
+
# t = Time.now #=> 2007-11-19 08:23:10 -0600
|
202
|
+
# t2 = t + 2592000 #=> 2007-12-19 08:23:10 -0600
|
203
|
+
# t2 - t #=> 2592000.0
|
204
|
+
# t2 - 2592000 #=> 2007-11-19 08:23:10 -0600
|
205
|
+
#
|
184
206
|
def -: (Time arg0) -> Float
|
185
207
|
| (Numeric arg0) -> Time
|
186
208
|
|
@@ -188,549 +210,835 @@ class Time < Object
|
|
188
210
|
|
189
211
|
def <=: (Time arg0) -> bool
|
190
212
|
|
213
|
+
# Comparison---Compares `time` with `other_time`.
|
214
|
+
#
|
215
|
+
# -1, 0, +1 or nil depending on whether `time` is less than, equal to, or
|
216
|
+
# greater than `other_time`.
|
217
|
+
#
|
218
|
+
# `nil` is returned if the two values are incomparable.
|
219
|
+
#
|
220
|
+
# t = Time.now #=> 2007-11-19 08:12:12 -0600
|
221
|
+
# t2 = t + 2592000 #=> 2007-12-19 08:12:12 -0600
|
222
|
+
# t <=> t2 #=> -1
|
223
|
+
# t2 <=> t #=> 1
|
224
|
+
#
|
225
|
+
# t = Time.now #=> 2007-11-19 08:13:38 -0600
|
226
|
+
# t2 = t + 0.1 #=> 2007-11-19 08:13:38 -0600
|
227
|
+
# t.nsec #=> 98222999
|
228
|
+
# t2.nsec #=> 198222999
|
229
|
+
# t <=> t2 #=> -1
|
230
|
+
# t2 <=> t #=> 1
|
231
|
+
# t <=> t #=> 0
|
232
|
+
#
|
191
233
|
def <=>: (Time other) -> Integer?
|
192
234
|
|
193
235
|
def >: (Time arg0) -> bool
|
194
236
|
|
195
237
|
def >=: (Time arg0) -> bool
|
196
238
|
|
197
|
-
# Returns a canonical string representation of *time
|
198
|
-
#
|
199
|
-
#
|
200
|
-
#
|
201
|
-
#
|
202
|
-
# ```
|
239
|
+
# Returns a canonical string representation of *time*.
|
240
|
+
#
|
241
|
+
# Time.now.asctime #=> "Wed Apr 9 08:56:03 2003"
|
242
|
+
# Time.now.ctime #=> "Wed Apr 9 08:56:03 2003"
|
243
|
+
#
|
203
244
|
def asctime: () -> String
|
204
245
|
|
205
|
-
# Returns a canonical string representation of *time
|
206
|
-
#
|
207
|
-
#
|
208
|
-
#
|
209
|
-
#
|
210
|
-
# ```
|
246
|
+
# Returns a canonical string representation of *time*.
|
247
|
+
#
|
248
|
+
# Time.now.asctime #=> "Wed Apr 9 08:56:03 2003"
|
249
|
+
# Time.now.ctime #=> "Wed Apr 9 08:56:03 2003"
|
250
|
+
#
|
211
251
|
def ctime: () -> String
|
212
252
|
|
213
|
-
# Returns the day of the month (1..n) for *time
|
214
|
-
#
|
215
|
-
#
|
216
|
-
#
|
217
|
-
#
|
218
|
-
#
|
219
|
-
# ```
|
253
|
+
# Returns the day of the month (1..n) for *time*.
|
254
|
+
#
|
255
|
+
# t = Time.now #=> 2007-11-19 08:27:03 -0600
|
256
|
+
# t.day #=> 19
|
257
|
+
# t.mday #=> 19
|
258
|
+
#
|
220
259
|
def day: () -> Integer
|
221
260
|
|
222
|
-
# Returns `true` if *time* occurs during Daylight Saving
|
223
|
-
#
|
224
|
-
#
|
225
|
-
#
|
226
|
-
#
|
227
|
-
#
|
228
|
-
#
|
229
|
-
#
|
230
|
-
#
|
231
|
-
#
|
232
|
-
#
|
233
|
-
#
|
234
|
-
#
|
235
|
-
#
|
236
|
-
#
|
237
|
-
#
|
238
|
-
#
|
239
|
-
#
|
240
|
-
# Time.local(2000, 7, 1).dst? #=> false
|
241
|
-
# ```
|
261
|
+
# Returns `true` if *time* occurs during Daylight Saving Time in its time zone.
|
262
|
+
#
|
263
|
+
# # CST6CDT:
|
264
|
+
# Time.local(2000, 1, 1).zone #=> "CST"
|
265
|
+
# Time.local(2000, 1, 1).isdst #=> false
|
266
|
+
# Time.local(2000, 1, 1).dst? #=> false
|
267
|
+
# Time.local(2000, 7, 1).zone #=> "CDT"
|
268
|
+
# Time.local(2000, 7, 1).isdst #=> true
|
269
|
+
# Time.local(2000, 7, 1).dst? #=> true
|
270
|
+
#
|
271
|
+
# # Asia/Tokyo:
|
272
|
+
# Time.local(2000, 1, 1).zone #=> "JST"
|
273
|
+
# Time.local(2000, 1, 1).isdst #=> false
|
274
|
+
# Time.local(2000, 1, 1).dst? #=> false
|
275
|
+
# Time.local(2000, 7, 1).zone #=> "JST"
|
276
|
+
# Time.local(2000, 7, 1).isdst #=> false
|
277
|
+
# Time.local(2000, 7, 1).dst? #=> false
|
278
|
+
#
|
242
279
|
def dst?: () -> bool
|
243
280
|
|
281
|
+
# Returns `true` if *time* and `other_time` are both Time objects with the same
|
282
|
+
# seconds and fractional seconds.
|
283
|
+
#
|
244
284
|
def eql?: (untyped arg0) -> bool
|
245
285
|
|
246
286
|
# Returns `true` if *time* represents Friday.
|
247
|
-
#
|
248
|
-
#
|
249
|
-
#
|
250
|
-
#
|
251
|
-
# ```
|
287
|
+
#
|
288
|
+
# t = Time.local(1987, 12, 18) #=> 1987-12-18 00:00:00 -0600
|
289
|
+
# t.friday? #=> true
|
290
|
+
#
|
252
291
|
def friday?: () -> bool
|
253
292
|
|
254
|
-
# Returns a new
|
255
|
-
#
|
256
|
-
#
|
257
|
-
#
|
258
|
-
#
|
259
|
-
#
|
260
|
-
# y
|
261
|
-
#
|
262
|
-
# t == y #=> true
|
263
|
-
# ```
|
293
|
+
# Returns a new Time object representing *time* in UTC.
|
294
|
+
#
|
295
|
+
# t = Time.local(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 -0600
|
296
|
+
# t.gmt? #=> false
|
297
|
+
# y = t.getgm #=> 2000-01-02 02:15:01 UTC
|
298
|
+
# y.gmt? #=> true
|
299
|
+
# t == y #=> true
|
300
|
+
#
|
264
301
|
def getgm: () -> Time
|
265
302
|
|
303
|
+
# Returns a new Time object representing *time* in local time (using the local
|
304
|
+
# time zone in effect for this process).
|
305
|
+
#
|
306
|
+
# If `utc_offset` is given, it is used instead of the local time. `utc_offset`
|
307
|
+
# can be given as a human-readable string (eg. `"+09:00"`) or as a number of
|
308
|
+
# seconds (eg. `32400`).
|
309
|
+
#
|
310
|
+
# t = Time.utc(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 UTC
|
311
|
+
# t.utc? #=> true
|
312
|
+
#
|
313
|
+
# l = t.getlocal #=> 2000-01-01 14:15:01 -0600
|
314
|
+
# l.utc? #=> false
|
315
|
+
# t == l #=> true
|
316
|
+
#
|
317
|
+
# j = t.getlocal("+09:00") #=> 2000-01-02 05:15:01 +0900
|
318
|
+
# j.utc? #=> false
|
319
|
+
# t == j #=> true
|
320
|
+
#
|
321
|
+
# k = t.getlocal(9*60*60) #=> 2000-01-02 05:15:01 +0900
|
322
|
+
# k.utc? #=> false
|
323
|
+
# t == k #=> true
|
324
|
+
#
|
266
325
|
def getlocal: (?Integer utc_offset) -> Time
|
267
326
|
|
268
|
-
# Returns a new
|
269
|
-
#
|
270
|
-
#
|
271
|
-
#
|
272
|
-
#
|
273
|
-
#
|
274
|
-
# y
|
275
|
-
#
|
276
|
-
# t == y #=> true
|
277
|
-
# ```
|
327
|
+
# Returns a new Time object representing *time* in UTC.
|
328
|
+
#
|
329
|
+
# t = Time.local(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 -0600
|
330
|
+
# t.gmt? #=> false
|
331
|
+
# y = t.getgm #=> 2000-01-02 02:15:01 UTC
|
332
|
+
# y.gmt? #=> true
|
333
|
+
# t == y #=> true
|
334
|
+
#
|
278
335
|
def getutc: () -> Time
|
279
336
|
|
280
337
|
# Returns `true` if *time* represents a time in UTC (GMT).
|
281
|
-
#
|
282
|
-
#
|
283
|
-
#
|
284
|
-
#
|
285
|
-
#
|
286
|
-
#
|
287
|
-
#
|
288
|
-
#
|
289
|
-
#
|
290
|
-
#
|
291
|
-
#
|
292
|
-
# ```
|
338
|
+
#
|
339
|
+
# t = Time.now #=> 2007-11-19 08:15:23 -0600
|
340
|
+
# t.utc? #=> false
|
341
|
+
# t = Time.gm(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 UTC
|
342
|
+
# t.utc? #=> true
|
343
|
+
#
|
344
|
+
# t = Time.now #=> 2007-11-19 08:16:03 -0600
|
345
|
+
# t.gmt? #=> false
|
346
|
+
# t = Time.gm(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 UTC
|
347
|
+
# t.gmt? #=> true
|
348
|
+
#
|
293
349
|
def gmt?: () -> bool
|
294
350
|
|
295
351
|
# Returns the offset in seconds between the timezone of *time* and UTC.
|
296
|
-
#
|
297
|
-
#
|
298
|
-
#
|
299
|
-
# t.
|
300
|
-
#
|
301
|
-
#
|
302
|
-
# ```
|
352
|
+
#
|
353
|
+
# t = Time.gm(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 UTC
|
354
|
+
# t.gmt_offset #=> 0
|
355
|
+
# l = t.getlocal #=> 2000-01-01 14:15:01 -0600
|
356
|
+
# l.gmt_offset #=> -21600
|
357
|
+
#
|
303
358
|
def gmt_offset: () -> Integer
|
304
359
|
|
305
360
|
# Converts *time* to UTC (GMT), modifying the receiver.
|
306
|
-
#
|
307
|
-
#
|
308
|
-
#
|
309
|
-
#
|
310
|
-
#
|
311
|
-
#
|
312
|
-
#
|
313
|
-
#
|
314
|
-
#
|
315
|
-
#
|
316
|
-
#
|
317
|
-
# ```
|
361
|
+
#
|
362
|
+
# t = Time.now #=> 2007-11-19 08:18:31 -0600
|
363
|
+
# t.gmt? #=> false
|
364
|
+
# t.gmtime #=> 2007-11-19 14:18:31 UTC
|
365
|
+
# t.gmt? #=> true
|
366
|
+
#
|
367
|
+
# t = Time.now #=> 2007-11-19 08:18:51 -0600
|
368
|
+
# t.utc? #=> false
|
369
|
+
# t.utc #=> 2007-11-19 14:18:51 UTC
|
370
|
+
# t.utc? #=> true
|
371
|
+
#
|
318
372
|
def gmtime: () -> Time
|
319
373
|
|
320
|
-
# Returns a hash code for this
|
321
|
-
#
|
322
|
-
# See also Object
|
374
|
+
# Returns a hash code for this Time object.
|
375
|
+
#
|
376
|
+
# See also Object#hash.
|
377
|
+
#
|
323
378
|
def hash: () -> Integer
|
324
379
|
|
325
|
-
# Returns the hour of the day (0..23) for *time
|
326
|
-
#
|
327
|
-
#
|
328
|
-
#
|
329
|
-
#
|
330
|
-
# ```
|
380
|
+
# Returns the hour of the day (0..23) for *time*.
|
381
|
+
#
|
382
|
+
# t = Time.now #=> 2007-11-19 08:26:20 -0600
|
383
|
+
# t.hour #=> 8
|
384
|
+
#
|
331
385
|
def hour: () -> Integer
|
332
386
|
|
387
|
+
# Returns a Time object.
|
388
|
+
#
|
389
|
+
# It is initialized to the current system time if no argument is given.
|
390
|
+
#
|
391
|
+
# **Note:** The new object will use the resolution available on your system
|
392
|
+
# clock, and may include fractional seconds.
|
393
|
+
#
|
394
|
+
# If one or more arguments are specified, the time is initialized to the
|
395
|
+
# specified time.
|
396
|
+
#
|
397
|
+
# `sec` may have fraction if it is a rational.
|
398
|
+
#
|
399
|
+
# `tz` specifies the timezone. It can be an offset from UTC, given either as a
|
400
|
+
# string such as "+09:00" or a single letter "A".."Z" excluding "J" (so-called
|
401
|
+
# military time zone), or as a number of seconds such as 32400. Or it can be a
|
402
|
+
# timezone object, see [Timezone argument](#class-Time-label-Timezone+argument)
|
403
|
+
# for details.
|
404
|
+
#
|
405
|
+
# a = Time.new #=> 2007-11-19 07:50:02 -0600
|
406
|
+
# b = Time.new #=> 2007-11-19 07:50:02 -0600
|
407
|
+
# a == b #=> false
|
408
|
+
# "%.6f" % a.to_f #=> "1195480202.282373"
|
409
|
+
# "%.6f" % b.to_f #=> "1195480202.283415"
|
410
|
+
#
|
411
|
+
# Time.new(2008,6,21, 13,30,0, "+09:00") #=> 2008-06-21 13:30:00 +0900
|
412
|
+
#
|
413
|
+
# # A trip for RubyConf 2007
|
414
|
+
# t1 = Time.new(2007,11,1,15,25,0, "+09:00") # JST (Narita)
|
415
|
+
# t2 = Time.new(2007,11,1,12, 5,0, "-05:00") # CDT (Minneapolis)
|
416
|
+
# t3 = Time.new(2007,11,1,13,25,0, "-05:00") # CDT (Minneapolis)
|
417
|
+
# t4 = Time.new(2007,11,1,16,53,0, "-04:00") # EDT (Charlotte)
|
418
|
+
# t5 = Time.new(2007,11,5, 9,24,0, "-05:00") # EST (Charlotte)
|
419
|
+
# t6 = Time.new(2007,11,5,11,21,0, "-05:00") # EST (Detroit)
|
420
|
+
# t7 = Time.new(2007,11,5,13,45,0, "-05:00") # EST (Detroit)
|
421
|
+
# t8 = Time.new(2007,11,6,17,10,0, "+09:00") # JST (Narita)
|
422
|
+
# (t2-t1)/3600.0 #=> 10.666666666666666
|
423
|
+
# (t4-t3)/3600.0 #=> 2.466666666666667
|
424
|
+
# (t6-t5)/3600.0 #=> 1.95
|
425
|
+
# (t8-t7)/3600.0 #=> 13.416666666666666
|
426
|
+
#
|
333
427
|
def initialize: (?Integer | String year, ?Integer | String month, ?Integer | String day, ?Integer | String hour, ?Integer | String min, ?Numeric | String sec, ?Numeric | String usec_with_frac) -> void
|
334
428
|
|
335
|
-
# Returns a string representing *time
|
336
|
-
#
|
337
|
-
#
|
338
|
-
#
|
339
|
-
#
|
340
|
-
#
|
341
|
-
#
|
342
|
-
#
|
343
|
-
#
|
344
|
-
#
|
345
|
-
# t.strftime "%Y-%m-%d %H:%M:%S UTC" #=> "2012-11-10 17:16:12 UTC"
|
346
|
-
# ```
|
429
|
+
# Returns a detailed string representing *time*. Unlike to_s, preserves
|
430
|
+
# nanoseconds in the representation for easier debugging.
|
431
|
+
#
|
432
|
+
# t = Time.now
|
433
|
+
# t.inspect #=> "2012-11-10 18:16:12.261257655 +0100"
|
434
|
+
# t.strftime "%Y-%m-%d %H:%M:%S.%N %z" #=> "2012-11-10 18:16:12.261257655 +0100"
|
435
|
+
#
|
436
|
+
# t.utc.inspect #=> "2012-11-10 17:16:12.261257655 UTC"
|
437
|
+
# t.strftime "%Y-%m-%d %H:%M:%S.%N UTC" #=> "2012-11-10 17:16:12.261257655 UTC"
|
438
|
+
#
|
347
439
|
def inspect: () -> String
|
348
440
|
|
349
|
-
# Returns `true` if *time* occurs during Daylight Saving
|
350
|
-
#
|
351
|
-
#
|
352
|
-
#
|
353
|
-
#
|
354
|
-
#
|
355
|
-
#
|
356
|
-
#
|
357
|
-
#
|
358
|
-
#
|
359
|
-
#
|
360
|
-
#
|
361
|
-
#
|
362
|
-
#
|
363
|
-
#
|
364
|
-
#
|
365
|
-
#
|
366
|
-
#
|
367
|
-
# Time.local(2000, 7, 1).dst? #=> false
|
368
|
-
# ```
|
441
|
+
# Returns `true` if *time* occurs during Daylight Saving Time in its time zone.
|
442
|
+
#
|
443
|
+
# # CST6CDT:
|
444
|
+
# Time.local(2000, 1, 1).zone #=> "CST"
|
445
|
+
# Time.local(2000, 1, 1).isdst #=> false
|
446
|
+
# Time.local(2000, 1, 1).dst? #=> false
|
447
|
+
# Time.local(2000, 7, 1).zone #=> "CDT"
|
448
|
+
# Time.local(2000, 7, 1).isdst #=> true
|
449
|
+
# Time.local(2000, 7, 1).dst? #=> true
|
450
|
+
#
|
451
|
+
# # Asia/Tokyo:
|
452
|
+
# Time.local(2000, 1, 1).zone #=> "JST"
|
453
|
+
# Time.local(2000, 1, 1).isdst #=> false
|
454
|
+
# Time.local(2000, 1, 1).dst? #=> false
|
455
|
+
# Time.local(2000, 7, 1).zone #=> "JST"
|
456
|
+
# Time.local(2000, 7, 1).isdst #=> false
|
457
|
+
# Time.local(2000, 7, 1).dst? #=> false
|
458
|
+
#
|
369
459
|
def isdst: () -> bool
|
370
460
|
|
461
|
+
# Converts *time* to local time (using the local time zone in effect at the
|
462
|
+
# creation time of *time*) modifying the receiver.
|
463
|
+
#
|
464
|
+
# If `utc_offset` is given, it is used instead of the local time.
|
465
|
+
#
|
466
|
+
# t = Time.utc(2000, "jan", 1, 20, 15, 1) #=> 2000-01-01 20:15:01 UTC
|
467
|
+
# t.utc? #=> true
|
468
|
+
#
|
469
|
+
# t.localtime #=> 2000-01-01 14:15:01 -0600
|
470
|
+
# t.utc? #=> false
|
471
|
+
#
|
472
|
+
# t.localtime("+09:00") #=> 2000-01-02 05:15:01 +0900
|
473
|
+
# t.utc? #=> false
|
474
|
+
#
|
475
|
+
# If `utc_offset` is not given and *time* is local time, just returns the
|
476
|
+
# receiver.
|
477
|
+
#
|
371
478
|
def localtime: (?String utc_offset) -> Time
|
372
479
|
|
373
|
-
# Returns the day of the month (1..n) for *time
|
374
|
-
#
|
375
|
-
#
|
376
|
-
#
|
377
|
-
#
|
378
|
-
#
|
379
|
-
# ```
|
480
|
+
# Returns the day of the month (1..n) for *time*.
|
481
|
+
#
|
482
|
+
# t = Time.now #=> 2007-11-19 08:27:03 -0600
|
483
|
+
# t.day #=> 19
|
484
|
+
# t.mday #=> 19
|
485
|
+
#
|
380
486
|
def mday: () -> Integer
|
381
487
|
|
382
|
-
# Returns the minute of the hour (0..59) for *time
|
383
|
-
#
|
384
|
-
#
|
385
|
-
#
|
386
|
-
#
|
387
|
-
# ```
|
488
|
+
# Returns the minute of the hour (0..59) for *time*.
|
489
|
+
#
|
490
|
+
# t = Time.now #=> 2007-11-19 08:25:51 -0600
|
491
|
+
# t.min #=> 25
|
492
|
+
#
|
388
493
|
def min: () -> Integer
|
389
494
|
|
390
|
-
# Returns the month of the year (1..12) for *time
|
391
|
-
#
|
392
|
-
#
|
393
|
-
#
|
394
|
-
#
|
395
|
-
#
|
396
|
-
# ```
|
495
|
+
# Returns the month of the year (1..12) for *time*.
|
496
|
+
#
|
497
|
+
# t = Time.now #=> 2007-11-19 08:27:30 -0600
|
498
|
+
# t.mon #=> 11
|
499
|
+
# t.month #=> 11
|
500
|
+
#
|
397
501
|
def mon: () -> Integer
|
398
502
|
|
399
503
|
# Returns `true` if *time* represents Monday.
|
400
|
-
#
|
401
|
-
#
|
402
|
-
#
|
403
|
-
#
|
404
|
-
# ```
|
504
|
+
#
|
505
|
+
# t = Time.local(2003, 8, 4) #=> 2003-08-04 00:00:00 -0500
|
506
|
+
# t.monday? #=> true
|
507
|
+
#
|
405
508
|
def monday?: () -> bool
|
406
509
|
|
407
|
-
# Returns the number of nanoseconds for *time
|
408
|
-
#
|
409
|
-
#
|
410
|
-
# t
|
411
|
-
#
|
412
|
-
#
|
413
|
-
#
|
414
|
-
#
|
415
|
-
#
|
416
|
-
#
|
417
|
-
#
|
418
|
-
#
|
419
|
-
#
|
420
|
-
# The more accurate value is returned by
|
421
|
-
# [nsec](Time.downloaded.ruby_doc#method-i-nsec).
|
510
|
+
# Returns the number of nanoseconds for *time*.
|
511
|
+
#
|
512
|
+
# t = Time.now #=> 2007-11-17 15:18:03 +0900
|
513
|
+
# "%10.9f" % t.to_f #=> "1195280283.536151409"
|
514
|
+
# t.nsec #=> 536151406
|
515
|
+
#
|
516
|
+
# The lowest digits of #to_f and #nsec are different because IEEE 754 double is
|
517
|
+
# not accurate enough to represent the exact number of nanoseconds since the
|
518
|
+
# Epoch.
|
519
|
+
#
|
520
|
+
# The more accurate value is returned by #nsec.
|
521
|
+
#
|
422
522
|
def nsec: () -> Integer
|
423
523
|
|
424
|
-
|
524
|
+
# Rounds sub seconds to a given precision in decimal digits (0 digits by
|
525
|
+
# default). It returns a new Time object. `ndigits` should be zero or a positive
|
526
|
+
# integer.
|
527
|
+
#
|
528
|
+
# require 'time'
|
529
|
+
#
|
530
|
+
# t = Time.utc(2010,3,30, 5,43,25.123456789r)
|
531
|
+
# t.iso8601(10) #=> "2010-03-30T05:43:25.1234567890Z"
|
532
|
+
# t.round.iso8601(10) #=> "2010-03-30T05:43:25.0000000000Z"
|
533
|
+
# t.round(0).iso8601(10) #=> "2010-03-30T05:43:25.0000000000Z"
|
534
|
+
# t.round(1).iso8601(10) #=> "2010-03-30T05:43:25.1000000000Z"
|
535
|
+
# t.round(2).iso8601(10) #=> "2010-03-30T05:43:25.1200000000Z"
|
536
|
+
# t.round(3).iso8601(10) #=> "2010-03-30T05:43:25.1230000000Z"
|
537
|
+
# t.round(4).iso8601(10) #=> "2010-03-30T05:43:25.1235000000Z"
|
538
|
+
#
|
539
|
+
# t = Time.utc(1999,12,31, 23,59,59)
|
540
|
+
# (t + 0.4).round.iso8601(3) #=> "1999-12-31T23:59:59.000Z"
|
541
|
+
# (t + 0.49).round.iso8601(3) #=> "1999-12-31T23:59:59.000Z"
|
542
|
+
# (t + 0.5).round.iso8601(3) #=> "2000-01-01T00:00:00.000Z"
|
543
|
+
# (t + 1.4).round.iso8601(3) #=> "2000-01-01T00:00:00.000Z"
|
544
|
+
# (t + 1.49).round.iso8601(3) #=> "2000-01-01T00:00:00.000Z"
|
545
|
+
# (t + 1.5).round.iso8601(3) #=> "2000-01-01T00:00:01.000Z"
|
546
|
+
#
|
547
|
+
# t = Time.utc(1999,12,31, 23,59,59)
|
548
|
+
# (t + 0.123456789).round(4).iso8601(6) #=> "1999-12-31T23:59:59.123500Z"
|
549
|
+
#
|
550
|
+
def round: (?Integer arg0) -> Time
|
425
551
|
|
426
552
|
# Returns `true` if *time* represents Saturday.
|
427
|
-
#
|
428
|
-
#
|
429
|
-
#
|
430
|
-
#
|
431
|
-
# ```
|
553
|
+
#
|
554
|
+
# t = Time.local(2006, 6, 10) #=> 2006-06-10 00:00:00 -0500
|
555
|
+
# t.saturday? #=> true
|
556
|
+
#
|
432
557
|
def saturday?: () -> bool
|
433
558
|
|
434
|
-
# Returns the second of the minute (0..60) for *time
|
435
|
-
#
|
436
|
-
# **Note:** Seconds range from zero to 60 to allow the system to inject
|
437
|
-
#
|
438
|
-
#
|
439
|
-
#
|
440
|
-
#
|
441
|
-
#
|
442
|
-
# t = Time.now #=> 2007-11-19 08:25:02 -0600
|
443
|
-
# t.sec #=> 2
|
444
|
-
# ```
|
559
|
+
# Returns the second of the minute (0..60) for *time*.
|
560
|
+
#
|
561
|
+
# **Note:** Seconds range from zero to 60 to allow the system to inject leap
|
562
|
+
# seconds. See http://en.wikipedia.org/wiki/Leap_second for further details.
|
563
|
+
#
|
564
|
+
# t = Time.now #=> 2007-11-19 08:25:02 -0600
|
565
|
+
# t.sec #=> 2
|
566
|
+
#
|
445
567
|
def sec: () -> Integer
|
446
568
|
|
569
|
+
# Formats *time* according to the directives in the given format string.
|
570
|
+
#
|
571
|
+
# The directives begin with a percent (%) character. Any text not listed as a
|
572
|
+
# directive will be passed through to the output string.
|
573
|
+
#
|
574
|
+
# The directive consists of a percent (%) character, zero or more flags,
|
575
|
+
# optional minimum field width, optional modifier and a conversion specifier as
|
576
|
+
# follows:
|
577
|
+
#
|
578
|
+
# %<flags><width><modifier><conversion>
|
579
|
+
#
|
580
|
+
# Flags:
|
581
|
+
# - don't pad a numerical output
|
582
|
+
# _ use spaces for padding
|
583
|
+
# 0 use zeros for padding
|
584
|
+
# ^ upcase the result string
|
585
|
+
# # change case
|
586
|
+
# : use colons for %z
|
587
|
+
#
|
588
|
+
# The minimum field width specifies the minimum width.
|
589
|
+
#
|
590
|
+
# The modifiers are "E" and "O". They are ignored.
|
591
|
+
#
|
592
|
+
# Format directives:
|
593
|
+
#
|
594
|
+
# Date (Year, Month, Day):
|
595
|
+
# %Y - Year with century if provided, will pad result at least 4 digits.
|
596
|
+
# -0001, 0000, 1995, 2009, 14292, etc.
|
597
|
+
# %C - year / 100 (rounded down such as 20 in 2009)
|
598
|
+
# %y - year % 100 (00..99)
|
599
|
+
#
|
600
|
+
# %m - Month of the year, zero-padded (01..12)
|
601
|
+
# %_m blank-padded ( 1..12)
|
602
|
+
# %-m no-padded (1..12)
|
603
|
+
# %B - The full month name (``January'')
|
604
|
+
# %^B uppercased (``JANUARY'')
|
605
|
+
# %b - The abbreviated month name (``Jan'')
|
606
|
+
# %^b uppercased (``JAN'')
|
607
|
+
# %h - Equivalent to %b
|
608
|
+
#
|
609
|
+
# %d - Day of the month, zero-padded (01..31)
|
610
|
+
# %-d no-padded (1..31)
|
611
|
+
# %e - Day of the month, blank-padded ( 1..31)
|
612
|
+
#
|
613
|
+
# %j - Day of the year (001..366)
|
614
|
+
#
|
615
|
+
# Time (Hour, Minute, Second, Subsecond):
|
616
|
+
# %H - Hour of the day, 24-hour clock, zero-padded (00..23)
|
617
|
+
# %k - Hour of the day, 24-hour clock, blank-padded ( 0..23)
|
618
|
+
# %I - Hour of the day, 12-hour clock, zero-padded (01..12)
|
619
|
+
# %l - Hour of the day, 12-hour clock, blank-padded ( 1..12)
|
620
|
+
# %P - Meridian indicator, lowercase (``am'' or ``pm'')
|
621
|
+
# %p - Meridian indicator, uppercase (``AM'' or ``PM'')
|
622
|
+
#
|
623
|
+
# %M - Minute of the hour (00..59)
|
624
|
+
#
|
625
|
+
# %S - Second of the minute (00..60)
|
626
|
+
#
|
627
|
+
# %L - Millisecond of the second (000..999)
|
628
|
+
# The digits under millisecond are truncated to not produce 1000.
|
629
|
+
# %N - Fractional seconds digits, default is 9 digits (nanosecond)
|
630
|
+
# %3N millisecond (3 digits)
|
631
|
+
# %6N microsecond (6 digits)
|
632
|
+
# %9N nanosecond (9 digits)
|
633
|
+
# %12N picosecond (12 digits)
|
634
|
+
# %15N femtosecond (15 digits)
|
635
|
+
# %18N attosecond (18 digits)
|
636
|
+
# %21N zeptosecond (21 digits)
|
637
|
+
# %24N yoctosecond (24 digits)
|
638
|
+
# The digits under the specified length are truncated to avoid
|
639
|
+
# carry up.
|
640
|
+
#
|
641
|
+
# Time zone:
|
642
|
+
# %z - Time zone as hour and minute offset from UTC (e.g. +0900)
|
643
|
+
# %:z - hour and minute offset from UTC with a colon (e.g. +09:00)
|
644
|
+
# %::z - hour, minute and second offset from UTC (e.g. +09:00:00)
|
645
|
+
# %Z - Abbreviated time zone name or similar information. (OS dependent)
|
646
|
+
#
|
647
|
+
# Weekday:
|
648
|
+
# %A - The full weekday name (``Sunday'')
|
649
|
+
# %^A uppercased (``SUNDAY'')
|
650
|
+
# %a - The abbreviated name (``Sun'')
|
651
|
+
# %^a uppercased (``SUN'')
|
652
|
+
# %u - Day of the week (Monday is 1, 1..7)
|
653
|
+
# %w - Day of the week (Sunday is 0, 0..6)
|
654
|
+
#
|
655
|
+
# ISO 8601 week-based year and week number:
|
656
|
+
# The first week of YYYY starts with a Monday and includes YYYY-01-04.
|
657
|
+
# The days in the year before the first week are in the last week of
|
658
|
+
# the previous year.
|
659
|
+
# %G - The week-based year
|
660
|
+
# %g - The last 2 digits of the week-based year (00..99)
|
661
|
+
# %V - Week number of the week-based year (01..53)
|
662
|
+
#
|
663
|
+
# Week number:
|
664
|
+
# The first week of YYYY that starts with a Sunday or Monday (according to %U
|
665
|
+
# or %W). The days in the year before the first week are in week 0.
|
666
|
+
# %U - Week number of the year. The week starts with Sunday. (00..53)
|
667
|
+
# %W - Week number of the year. The week starts with Monday. (00..53)
|
668
|
+
#
|
669
|
+
# Seconds since the Epoch:
|
670
|
+
# %s - Number of seconds since 1970-01-01 00:00:00 UTC.
|
671
|
+
#
|
672
|
+
# Literal string:
|
673
|
+
# %n - Newline character (\n)
|
674
|
+
# %t - Tab character (\t)
|
675
|
+
# %% - Literal ``%'' character
|
676
|
+
#
|
677
|
+
# Combination:
|
678
|
+
# %c - date and time (%a %b %e %T %Y)
|
679
|
+
# %D - Date (%m/%d/%y)
|
680
|
+
# %F - The ISO 8601 date format (%Y-%m-%d)
|
681
|
+
# %v - VMS date (%e-%^b-%4Y)
|
682
|
+
# %x - Same as %D
|
683
|
+
# %X - Same as %T
|
684
|
+
# %r - 12-hour time (%I:%M:%S %p)
|
685
|
+
# %R - 24-hour time (%H:%M)
|
686
|
+
# %T - 24-hour time (%H:%M:%S)
|
687
|
+
#
|
688
|
+
# This method is similar to strftime() function defined in ISO C and POSIX.
|
689
|
+
#
|
690
|
+
# While all directives are locale independent since Ruby 1.9, %Z is platform
|
691
|
+
# dependent. So, the result may differ even if the same format string is used in
|
692
|
+
# other systems such as C.
|
693
|
+
#
|
694
|
+
# %z is recommended over %Z. %Z doesn't identify the timezone. For example,
|
695
|
+
# "CST" is used at America/Chicago (-06:00), America/Havana (-05:00),
|
696
|
+
# Asia/Harbin (+08:00), Australia/Darwin (+09:30) and Australia/Adelaide
|
697
|
+
# (+10:30). Also, %Z is highly dependent on the operating system. For example,
|
698
|
+
# it may generate a non ASCII string on Japanese Windows, i.e. the result can be
|
699
|
+
# different to "JST". So the numeric time zone offset, %z, is recommended.
|
700
|
+
#
|
701
|
+
# Examples:
|
702
|
+
#
|
703
|
+
# t = Time.new(2007,11,19,8,37,48,"-06:00") #=> 2007-11-19 08:37:48 -0600
|
704
|
+
# t.strftime("Printed on %m/%d/%Y") #=> "Printed on 11/19/2007"
|
705
|
+
# t.strftime("at %I:%M %p") #=> "at 08:37 AM"
|
706
|
+
#
|
707
|
+
# Various ISO 8601 formats:
|
708
|
+
# %Y%m%d => 20071119 Calendar date (basic)
|
709
|
+
# %F => 2007-11-19 Calendar date (extended)
|
710
|
+
# %Y-%m => 2007-11 Calendar date, reduced accuracy, specific month
|
711
|
+
# %Y => 2007 Calendar date, reduced accuracy, specific year
|
712
|
+
# %C => 20 Calendar date, reduced accuracy, specific century
|
713
|
+
# %Y%j => 2007323 Ordinal date (basic)
|
714
|
+
# %Y-%j => 2007-323 Ordinal date (extended)
|
715
|
+
# %GW%V%u => 2007W471 Week date (basic)
|
716
|
+
# %G-W%V-%u => 2007-W47-1 Week date (extended)
|
717
|
+
# %GW%V => 2007W47 Week date, reduced accuracy, specific week (basic)
|
718
|
+
# %G-W%V => 2007-W47 Week date, reduced accuracy, specific week (extended)
|
719
|
+
# %H%M%S => 083748 Local time (basic)
|
720
|
+
# %T => 08:37:48 Local time (extended)
|
721
|
+
# %H%M => 0837 Local time, reduced accuracy, specific minute (basic)
|
722
|
+
# %H:%M => 08:37 Local time, reduced accuracy, specific minute (extended)
|
723
|
+
# %H => 08 Local time, reduced accuracy, specific hour
|
724
|
+
# %H%M%S,%L => 083748,000 Local time with decimal fraction, comma as decimal sign (basic)
|
725
|
+
# %T,%L => 08:37:48,000 Local time with decimal fraction, comma as decimal sign (extended)
|
726
|
+
# %H%M%S.%L => 083748.000 Local time with decimal fraction, full stop as decimal sign (basic)
|
727
|
+
# %T.%L => 08:37:48.000 Local time with decimal fraction, full stop as decimal sign (extended)
|
728
|
+
# %H%M%S%z => 083748-0600 Local time and the difference from UTC (basic)
|
729
|
+
# %T%:z => 08:37:48-06:00 Local time and the difference from UTC (extended)
|
730
|
+
# %Y%m%dT%H%M%S%z => 20071119T083748-0600 Date and time of day for calendar date (basic)
|
731
|
+
# %FT%T%:z => 2007-11-19T08:37:48-06:00 Date and time of day for calendar date (extended)
|
732
|
+
# %Y%jT%H%M%S%z => 2007323T083748-0600 Date and time of day for ordinal date (basic)
|
733
|
+
# %Y-%jT%T%:z => 2007-323T08:37:48-06:00 Date and time of day for ordinal date (extended)
|
734
|
+
# %GW%V%uT%H%M%S%z => 2007W471T083748-0600 Date and time of day for week date (basic)
|
735
|
+
# %G-W%V-%uT%T%:z => 2007-W47-1T08:37:48-06:00 Date and time of day for week date (extended)
|
736
|
+
# %Y%m%dT%H%M => 20071119T0837 Calendar date and local time (basic)
|
737
|
+
# %FT%R => 2007-11-19T08:37 Calendar date and local time (extended)
|
738
|
+
# %Y%jT%H%MZ => 2007323T0837Z Ordinal date and UTC of day (basic)
|
739
|
+
# %Y-%jT%RZ => 2007-323T08:37Z Ordinal date and UTC of day (extended)
|
740
|
+
# %GW%V%uT%H%M%z => 2007W471T0837-0600 Week date and local time and difference from UTC (basic)
|
741
|
+
# %G-W%V-%uT%R%:z => 2007-W47-1T08:37-06:00 Week date and local time and difference from UTC (extended)
|
742
|
+
#
|
447
743
|
def strftime: (String arg0) -> String
|
448
744
|
|
449
|
-
# Returns the fraction for *time
|
450
|
-
#
|
745
|
+
# Returns the fraction for *time*.
|
746
|
+
#
|
451
747
|
# The return value can be a rational number.
|
452
|
-
#
|
453
|
-
#
|
454
|
-
# t
|
455
|
-
#
|
456
|
-
#
|
457
|
-
#
|
458
|
-
#
|
459
|
-
#
|
460
|
-
#
|
461
|
-
#
|
462
|
-
#
|
463
|
-
# The more accurate value is returned by
|
464
|
-
# [subsec](Time.downloaded.ruby_doc#method-i-subsec).
|
748
|
+
#
|
749
|
+
# t = Time.now #=> 2009-03-26 22:33:12 +0900
|
750
|
+
# "%10.9f" % t.to_f #=> "1238074392.940563917"
|
751
|
+
# t.subsec #=> (94056401/100000000)
|
752
|
+
#
|
753
|
+
# The lowest digits of #to_f and #subsec are different because IEEE 754 double
|
754
|
+
# is not accurate enough to represent the rational number.
|
755
|
+
#
|
756
|
+
# The more accurate value is returned by #subsec.
|
757
|
+
#
|
465
758
|
def subsec: () -> Numeric
|
466
759
|
|
467
|
-
# Returns a new
|
468
|
-
#
|
469
|
-
#
|
470
|
-
#
|
471
|
-
#
|
472
|
-
#
|
473
|
-
# t.succ #=> 2007-11-19 08:23:58 -0600
|
474
|
-
# ```
|
475
|
-
#
|
760
|
+
# Returns a new Time object, one second later than *time*. Time#succ is obsolete
|
761
|
+
# since 1.9.2 for time is not a discrete value.
|
762
|
+
#
|
763
|
+
# t = Time.now #=> 2007-11-19 08:23:57 -0600
|
764
|
+
# t.succ #=> 2007-11-19 08:23:58 -0600
|
765
|
+
#
|
476
766
|
# Use instead `time + 1`
|
477
|
-
#
|
478
|
-
#
|
479
|
-
#
|
480
|
-
# ```
|
767
|
+
#
|
768
|
+
# t + 1 #=> 2007-11-19 08:23:58 -0600
|
769
|
+
#
|
481
770
|
def succ: () -> Time
|
482
771
|
|
483
772
|
# Returns `true` if *time* represents Sunday.
|
484
|
-
#
|
485
|
-
#
|
486
|
-
#
|
487
|
-
#
|
488
|
-
# ```
|
773
|
+
#
|
774
|
+
# t = Time.local(1990, 4, 1) #=> 1990-04-01 00:00:00 -0600
|
775
|
+
# t.sunday? #=> true
|
776
|
+
#
|
489
777
|
def sunday?: () -> bool
|
490
778
|
|
491
779
|
# Returns `true` if *time* represents Thursday.
|
492
|
-
#
|
493
|
-
#
|
494
|
-
#
|
495
|
-
#
|
496
|
-
# ```
|
780
|
+
#
|
781
|
+
# t = Time.local(1995, 12, 21) #=> 1995-12-21 00:00:00 -0600
|
782
|
+
# t.thursday? #=> true
|
783
|
+
#
|
497
784
|
def thursday?: () -> bool
|
498
785
|
|
499
|
-
# Returns a ten-element *array* of values for *time
|
500
|
-
#
|
501
|
-
#
|
502
|
-
#
|
503
|
-
#
|
504
|
-
#
|
505
|
-
#
|
506
|
-
#
|
507
|
-
#
|
508
|
-
#
|
509
|
-
#
|
510
|
-
#
|
511
|
-
# ```ruby
|
512
|
-
# t = Time.now #=> 2007-11-19 08:36:01 -0600
|
513
|
-
# now = t.to_a #=> [1, 36, 8, 19, 11, 2007, 1, 323, false, "CST"]
|
514
|
-
# ```
|
786
|
+
# Returns a ten-element *array* of values for *time*:
|
787
|
+
#
|
788
|
+
# [sec, min, hour, day, month, year, wday, yday, isdst, zone]
|
789
|
+
#
|
790
|
+
# See the individual methods for an explanation of the valid ranges of each
|
791
|
+
# value. The ten elements can be passed directly to Time::utc or Time::local to
|
792
|
+
# create a new Time object.
|
793
|
+
#
|
794
|
+
# t = Time.now #=> 2007-11-19 08:36:01 -0600
|
795
|
+
# now = t.to_a #=> [1, 36, 8, 19, 11, 2007, 1, 323, false, "CST"]
|
796
|
+
#
|
515
797
|
def to_a: () -> [ Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, bool, String ]
|
516
798
|
|
517
|
-
# Returns the value of *time* as a floating point number of seconds since
|
518
|
-
#
|
519
|
-
#
|
520
|
-
#
|
521
|
-
# t
|
522
|
-
#
|
523
|
-
#
|
524
|
-
#
|
525
|
-
#
|
526
|
-
#
|
527
|
-
# number of nanoseconds since the Epoch.
|
799
|
+
# Returns the value of *time* as a floating point number of seconds since the
|
800
|
+
# Epoch.
|
801
|
+
#
|
802
|
+
# t = Time.now
|
803
|
+
# "%10.5f" % t.to_f #=> "1270968744.77658"
|
804
|
+
# t.to_i #=> 1270968744
|
805
|
+
#
|
806
|
+
# Note that IEEE 754 double is not accurate enough to represent the exact number
|
807
|
+
# of nanoseconds since the Epoch.
|
808
|
+
#
|
528
809
|
def to_f: () -> Float
|
529
810
|
|
530
|
-
# Returns the value of *time* as an integer number of seconds since the
|
531
|
-
#
|
532
|
-
#
|
533
|
-
#
|
534
|
-
#
|
535
|
-
#
|
536
|
-
# t.to_i #=> 1270968656
|
537
|
-
# ```
|
811
|
+
# Returns the value of *time* as an integer number of seconds since the Epoch.
|
812
|
+
#
|
813
|
+
# t = Time.now
|
814
|
+
# "%10.5f" % t.to_f #=> "1270968656.89607"
|
815
|
+
# t.to_i #=> 1270968656
|
816
|
+
#
|
538
817
|
def to_i: () -> Integer
|
539
818
|
|
540
|
-
# Returns the value of *time* as a rational number of seconds since the
|
541
|
-
#
|
542
|
-
#
|
543
|
-
#
|
544
|
-
#
|
545
|
-
#
|
546
|
-
#
|
547
|
-
#
|
548
|
-
#
|
549
|
-
# representing the nanoseconds since the Epoch. You can use this method to
|
550
|
-
# convert *time* to another Epoch.
|
819
|
+
# Returns the value of *time* as a rational number of seconds since the Epoch.
|
820
|
+
#
|
821
|
+
# t = Time.now
|
822
|
+
# t.to_r #=> (1270968792716287611/1000000000)
|
823
|
+
#
|
824
|
+
# This methods is intended to be used to get an accurate value representing the
|
825
|
+
# nanoseconds since the Epoch. You can use this method to convert *time* to
|
826
|
+
# another Epoch.
|
827
|
+
#
|
551
828
|
def to_r: () -> Rational
|
552
829
|
|
553
|
-
# Returns a string representing *time
|
554
|
-
# [strftime](Time.downloaded.ruby_doc#method-i-strftime) with the
|
830
|
+
# Returns a string representing *time*. Equivalent to calling #strftime with the
|
555
831
|
# appropriate format string.
|
556
|
-
#
|
557
|
-
#
|
558
|
-
#
|
559
|
-
#
|
560
|
-
#
|
561
|
-
#
|
562
|
-
#
|
563
|
-
#
|
564
|
-
# ```
|
832
|
+
#
|
833
|
+
# t = Time.now
|
834
|
+
# t.to_s #=> "2012-11-10 18:16:12 +0100"
|
835
|
+
# t.strftime "%Y-%m-%d %H:%M:%S %z" #=> "2012-11-10 18:16:12 +0100"
|
836
|
+
#
|
837
|
+
# t.utc.to_s #=> "2012-11-10 17:16:12 UTC"
|
838
|
+
# t.strftime "%Y-%m-%d %H:%M:%S UTC" #=> "2012-11-10 17:16:12 UTC"
|
839
|
+
#
|
565
840
|
def to_s: () -> String
|
566
841
|
|
567
842
|
# Returns `true` if *time* represents Tuesday.
|
568
|
-
#
|
569
|
-
#
|
570
|
-
#
|
571
|
-
#
|
572
|
-
# ```
|
843
|
+
#
|
844
|
+
# t = Time.local(1991, 2, 19) #=> 1991-02-19 00:00:00 -0600
|
845
|
+
# t.tuesday? #=> true
|
846
|
+
#
|
573
847
|
def tuesday?: () -> bool
|
574
848
|
|
575
|
-
# Returns the number of nanoseconds for *time
|
576
|
-
#
|
577
|
-
#
|
578
|
-
# t
|
579
|
-
#
|
580
|
-
#
|
581
|
-
#
|
582
|
-
#
|
583
|
-
#
|
584
|
-
#
|
585
|
-
#
|
586
|
-
#
|
587
|
-
#
|
588
|
-
# The more accurate value is returned by
|
589
|
-
# [nsec](Time.downloaded.ruby_doc#method-i-nsec).
|
849
|
+
# Returns the number of nanoseconds for *time*.
|
850
|
+
#
|
851
|
+
# t = Time.now #=> 2007-11-17 15:18:03 +0900
|
852
|
+
# "%10.9f" % t.to_f #=> "1195280283.536151409"
|
853
|
+
# t.nsec #=> 536151406
|
854
|
+
#
|
855
|
+
# The lowest digits of #to_f and #nsec are different because IEEE 754 double is
|
856
|
+
# not accurate enough to represent the exact number of nanoseconds since the
|
857
|
+
# Epoch.
|
858
|
+
#
|
859
|
+
# The more accurate value is returned by #nsec.
|
860
|
+
#
|
590
861
|
def tv_nsec: () -> Numeric
|
591
862
|
|
592
|
-
# Returns the value of *time* as an integer number of seconds since the
|
593
|
-
#
|
594
|
-
#
|
595
|
-
#
|
596
|
-
#
|
597
|
-
#
|
598
|
-
# t.to_i #=> 1270968656
|
599
|
-
# ```
|
863
|
+
# Returns the value of *time* as an integer number of seconds since the Epoch.
|
864
|
+
#
|
865
|
+
# t = Time.now
|
866
|
+
# "%10.5f" % t.to_f #=> "1270968656.89607"
|
867
|
+
# t.to_i #=> 1270968656
|
868
|
+
#
|
600
869
|
def tv_sec: () -> Numeric
|
601
870
|
|
602
|
-
# Returns the number of microseconds for *time
|
603
|
-
#
|
604
|
-
#
|
605
|
-
# t
|
606
|
-
#
|
607
|
-
#
|
608
|
-
# ```
|
871
|
+
# Returns the number of microseconds for *time*.
|
872
|
+
#
|
873
|
+
# t = Time.now #=> 2007-11-19 08:03:26 -0600
|
874
|
+
# "%10.6f" % t.to_f #=> "1195481006.775195"
|
875
|
+
# t.usec #=> 775195
|
876
|
+
#
|
609
877
|
def tv_usec: () -> Numeric
|
610
878
|
|
611
|
-
# Returns the number of microseconds for *time
|
612
|
-
#
|
613
|
-
#
|
614
|
-
# t
|
615
|
-
#
|
616
|
-
#
|
617
|
-
# ```
|
879
|
+
# Returns the number of microseconds for *time*.
|
880
|
+
#
|
881
|
+
# t = Time.now #=> 2007-11-19 08:03:26 -0600
|
882
|
+
# "%10.6f" % t.to_f #=> "1195481006.775195"
|
883
|
+
# t.usec #=> 775195
|
884
|
+
#
|
618
885
|
def usec: () -> Numeric
|
619
886
|
|
620
887
|
# Converts *time* to UTC (GMT), modifying the receiver.
|
621
|
-
#
|
622
|
-
#
|
623
|
-
#
|
624
|
-
#
|
625
|
-
#
|
626
|
-
#
|
627
|
-
#
|
628
|
-
#
|
629
|
-
#
|
630
|
-
#
|
631
|
-
#
|
632
|
-
# ```
|
888
|
+
#
|
889
|
+
# t = Time.now #=> 2007-11-19 08:18:31 -0600
|
890
|
+
# t.gmt? #=> false
|
891
|
+
# t.gmtime #=> 2007-11-19 14:18:31 UTC
|
892
|
+
# t.gmt? #=> true
|
893
|
+
#
|
894
|
+
# t = Time.now #=> 2007-11-19 08:18:51 -0600
|
895
|
+
# t.utc? #=> false
|
896
|
+
# t.utc #=> 2007-11-19 14:18:51 UTC
|
897
|
+
# t.utc? #=> true
|
898
|
+
#
|
633
899
|
def utc: () -> Time
|
634
900
|
|
635
901
|
# Returns `true` if *time* represents a time in UTC (GMT).
|
636
|
-
#
|
637
|
-
#
|
638
|
-
#
|
639
|
-
#
|
640
|
-
#
|
641
|
-
#
|
642
|
-
#
|
643
|
-
#
|
644
|
-
#
|
645
|
-
#
|
646
|
-
#
|
647
|
-
# ```
|
902
|
+
#
|
903
|
+
# t = Time.now #=> 2007-11-19 08:15:23 -0600
|
904
|
+
# t.utc? #=> false
|
905
|
+
# t = Time.gm(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 UTC
|
906
|
+
# t.utc? #=> true
|
907
|
+
#
|
908
|
+
# t = Time.now #=> 2007-11-19 08:16:03 -0600
|
909
|
+
# t.gmt? #=> false
|
910
|
+
# t = Time.gm(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 UTC
|
911
|
+
# t.gmt? #=> true
|
912
|
+
#
|
648
913
|
def utc?: () -> bool
|
649
914
|
|
650
915
|
# Returns the offset in seconds between the timezone of *time* and UTC.
|
651
|
-
#
|
652
|
-
#
|
653
|
-
#
|
654
|
-
# t.
|
655
|
-
#
|
656
|
-
#
|
657
|
-
# ```
|
916
|
+
#
|
917
|
+
# t = Time.gm(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 UTC
|
918
|
+
# t.gmt_offset #=> 0
|
919
|
+
# l = t.getlocal #=> 2000-01-01 14:15:01 -0600
|
920
|
+
# l.gmt_offset #=> -21600
|
921
|
+
#
|
658
922
|
def utc_offset: () -> Integer
|
659
923
|
|
660
|
-
# Returns an integer representing the day of the week, 0..6, with Sunday
|
661
|
-
#
|
662
|
-
#
|
663
|
-
#
|
664
|
-
#
|
665
|
-
#
|
666
|
-
#
|
667
|
-
#
|
668
|
-
#
|
669
|
-
#
|
670
|
-
#
|
671
|
-
#
|
672
|
-
# t.saturday? #=> false
|
673
|
-
# ```
|
924
|
+
# Returns an integer representing the day of the week, 0..6, with Sunday == 0.
|
925
|
+
#
|
926
|
+
# t = Time.now #=> 2007-11-20 02:35:35 -0600
|
927
|
+
# t.wday #=> 2
|
928
|
+
# t.sunday? #=> false
|
929
|
+
# t.monday? #=> false
|
930
|
+
# t.tuesday? #=> true
|
931
|
+
# t.wednesday? #=> false
|
932
|
+
# t.thursday? #=> false
|
933
|
+
# t.friday? #=> false
|
934
|
+
# t.saturday? #=> false
|
935
|
+
#
|
674
936
|
def wday: () -> Integer
|
675
937
|
|
676
938
|
# Returns `true` if *time* represents Wednesday.
|
677
|
-
#
|
678
|
-
#
|
679
|
-
#
|
680
|
-
#
|
681
|
-
# ```
|
939
|
+
#
|
940
|
+
# t = Time.local(1993, 2, 24) #=> 1993-02-24 00:00:00 -0600
|
941
|
+
# t.wednesday? #=> true
|
942
|
+
#
|
682
943
|
def wednesday?: () -> bool
|
683
944
|
|
684
945
|
# Returns an integer representing the day of the year, 1..366.
|
685
|
-
#
|
686
|
-
#
|
687
|
-
#
|
688
|
-
#
|
689
|
-
# ```
|
946
|
+
#
|
947
|
+
# t = Time.now #=> 2007-11-19 08:32:31 -0600
|
948
|
+
# t.yday #=> 323
|
949
|
+
#
|
690
950
|
def yday: () -> Integer
|
691
951
|
|
692
952
|
# Returns the year for *time* (including the century).
|
693
|
-
#
|
694
|
-
#
|
695
|
-
#
|
696
|
-
#
|
697
|
-
# ```
|
953
|
+
#
|
954
|
+
# t = Time.now #=> 2007-11-19 08:27:51 -0600
|
955
|
+
# t.year #=> 2007
|
956
|
+
#
|
698
957
|
def year: () -> Integer
|
699
958
|
|
700
|
-
# Returns the name of the time zone used for *time
|
701
|
-
#
|
702
|
-
#
|
703
|
-
#
|
704
|
-
#
|
705
|
-
#
|
706
|
-
#
|
707
|
-
#
|
708
|
-
# ```
|
959
|
+
# Returns the name of the time zone used for *time*. As of Ruby 1.8, returns
|
960
|
+
# ``UTC'' rather than ``GMT'' for UTC times.
|
961
|
+
#
|
962
|
+
# t = Time.gm(2000, "jan", 1, 20, 15, 1)
|
963
|
+
# t.zone #=> "UTC"
|
964
|
+
# t = Time.local(2000, "jan", 1, 20, 15, 1)
|
965
|
+
# t.zone #=> "CST"
|
966
|
+
#
|
709
967
|
def zone: () -> String
|
710
968
|
|
969
|
+
# Same as Time::gm, but interprets the values in the local time zone.
|
970
|
+
#
|
971
|
+
# Time.local(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 -0600
|
972
|
+
#
|
711
973
|
def self.mktime: (Integer year, ?Integer | String month, ?Integer day, ?Integer hour, ?Integer min, ?Numeric sec, ?Numeric usec_with_frac) -> Time
|
712
974
|
|
713
975
|
# Returns the offset in seconds between the timezone of *time* and UTC.
|
714
|
-
#
|
715
|
-
#
|
716
|
-
#
|
717
|
-
# t.
|
718
|
-
#
|
719
|
-
#
|
720
|
-
# ```
|
976
|
+
#
|
977
|
+
# t = Time.gm(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 UTC
|
978
|
+
# t.gmt_offset #=> 0
|
979
|
+
# l = t.getlocal #=> 2000-01-01 14:15:01 -0600
|
980
|
+
# l.gmt_offset #=> -21600
|
981
|
+
#
|
721
982
|
def gmtoff: () -> Integer
|
722
983
|
|
723
|
-
# Returns the month of the year (1..12) for *time
|
724
|
-
#
|
725
|
-
#
|
726
|
-
#
|
727
|
-
#
|
728
|
-
#
|
729
|
-
# ```
|
984
|
+
# Returns the month of the year (1..12) for *time*.
|
985
|
+
#
|
986
|
+
# t = Time.now #=> 2007-11-19 08:27:30 -0600
|
987
|
+
# t.mon #=> 11
|
988
|
+
# t.month #=> 11
|
989
|
+
#
|
730
990
|
def month: () -> Integer
|
731
991
|
|
992
|
+
# Floors sub seconds to a given precision in decimal digits (0 digits by
|
993
|
+
# default). It returns a new Time object. `ndigits` should be zero or a positive
|
994
|
+
# integer.
|
995
|
+
#
|
996
|
+
# require 'time'
|
997
|
+
#
|
998
|
+
# t = Time.utc(2010,3,30, 5,43,25.123456789r)
|
999
|
+
# t.iso8601(10) #=> "2010-03-30T05:43:25.1234567890Z"
|
1000
|
+
# t.floor.iso8601(10) #=> "2010-03-30T05:43:25.0000000000Z"
|
1001
|
+
# t.floor(0).iso8601(10) #=> "2010-03-30T05:43:25.0000000000Z"
|
1002
|
+
# t.floor(1).iso8601(10) #=> "2010-03-30T05:43:25.1000000000Z"
|
1003
|
+
# t.floor(2).iso8601(10) #=> "2010-03-30T05:43:25.1200000000Z"
|
1004
|
+
# t.floor(3).iso8601(10) #=> "2010-03-30T05:43:25.1230000000Z"
|
1005
|
+
# t.floor(4).iso8601(10) #=> "2010-03-30T05:43:25.1234000000Z"
|
1006
|
+
#
|
1007
|
+
# t = Time.utc(1999,12,31, 23,59,59)
|
1008
|
+
# (t + 0.4).floor.iso8601(3) #=> "1999-12-31T23:59:59.000Z"
|
1009
|
+
# (t + 0.9).floor.iso8601(3) #=> "1999-12-31T23:59:59.000Z"
|
1010
|
+
# (t + 1.4).floor.iso8601(3) #=> "2000-01-01T00:00:00.000Z"
|
1011
|
+
# (t + 1.9).floor.iso8601(3) #=> "2000-01-01T00:00:00.000Z"
|
1012
|
+
#
|
1013
|
+
# t = Time.utc(1999,12,31, 23,59,59)
|
1014
|
+
# (t + 0.123456789).floor(4).iso8601(6) #=> "1999-12-31T23:59:59.123400Z"
|
1015
|
+
#
|
732
1016
|
def floor: (?Integer ndigits) -> Time
|
733
1017
|
|
1018
|
+
# Ceils sub seconds to a given precision in decimal digits (0 digits by
|
1019
|
+
# default). It returns a new Time object. `ndigits` should be zero or a positive
|
1020
|
+
# integer.
|
1021
|
+
#
|
1022
|
+
# require 'time'
|
1023
|
+
#
|
1024
|
+
# t = Time.utc(2010,3,30, 5,43,25.0123456789r)
|
1025
|
+
# t.iso8601(10) #=> "2010-03-30T05:43:25.0123456789Z"
|
1026
|
+
# t.ceil.iso8601(10) #=> "2010-03-30T05:43:26.0000000000Z"
|
1027
|
+
# t.ceil(0).iso8601(10) #=> "2010-03-30T05:43:26.0000000000Z"
|
1028
|
+
# t.ceil(1).iso8601(10) #=> "2010-03-30T05:43:25.1000000000Z"
|
1029
|
+
# t.ceil(2).iso8601(10) #=> "2010-03-30T05:43:25.0200000000Z"
|
1030
|
+
# t.ceil(3).iso8601(10) #=> "2010-03-30T05:43:25.0130000000Z"
|
1031
|
+
# t.ceil(4).iso8601(10) #=> "2010-03-30T05:43:25.0124000000Z"
|
1032
|
+
#
|
1033
|
+
# t = Time.utc(1999,12,31, 23,59,59)
|
1034
|
+
# (t + 0.4).ceil.iso8601(3) #=> "2000-01-01T00:00:00.000Z"
|
1035
|
+
# (t + 0.9).ceil.iso8601(3) #=> "2000-01-01T00:00:00.000Z"
|
1036
|
+
# (t + 1.4).ceil.iso8601(3) #=> "2000-01-01T00:00:01.000Z"
|
1037
|
+
# (t + 1.9).ceil.iso8601(3) #=> "2000-01-01T00:00:01.000Z"
|
1038
|
+
#
|
1039
|
+
# t = Time.utc(1999,12,31, 23,59,59)
|
1040
|
+
# (t + 0.123456789).ceil(4).iso8601(6) #=> "1999-12-31T23:59:59.123500Z"
|
1041
|
+
#
|
734
1042
|
def ceil: (?Integer ndigits) -> Time
|
735
1043
|
end
|
736
1044
|
|