rbs 2.8.4 → 3.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (434) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +12 -4
  3. data/.github/workflows/comments.yml +11 -11
  4. data/.github/workflows/dependabot.yml +30 -0
  5. data/.github/workflows/ruby.yml +40 -49
  6. data/.github/workflows/typecheck.yml +36 -0
  7. data/.github/workflows/windows.yml +28 -0
  8. data/.gitignore +1 -0
  9. data/.rubocop.yml +42 -2
  10. data/CHANGELOG.md +845 -1
  11. data/README.md +64 -4
  12. data/Rakefile +198 -18
  13. data/Steepfile +11 -11
  14. data/config.yml +311 -0
  15. data/core/array.rbs +2189 -1914
  16. data/core/basic_object.rbs +59 -84
  17. data/core/binding.rbs +7 -69
  18. data/core/builtin.rbs +210 -11
  19. data/core/class.rbs +37 -0
  20. data/core/comparable.rbs +23 -25
  21. data/core/complex.rbs +449 -227
  22. data/core/constants.rbs +29 -21
  23. data/core/data.rbs +415 -0
  24. data/core/dir.rbs +698 -415
  25. data/core/encoding.rbs +468 -843
  26. data/core/enumerable.rbs +495 -455
  27. data/core/enumerator/product.rbs +92 -0
  28. data/core/enumerator.rbs +106 -9
  29. data/core/env.rbs +1 -1
  30. data/core/errno.rbs +506 -605
  31. data/core/errors.rbs +15 -17
  32. data/core/exception.rbs +361 -145
  33. data/core/false_class.rbs +39 -26
  34. data/core/fiber.rbs +121 -14
  35. data/core/file.rbs +1262 -320
  36. data/core/file_test.rbs +62 -45
  37. data/core/float.rbs +187 -208
  38. data/core/gc.rbs +446 -196
  39. data/core/global_variables.rbs +29 -29
  40. data/core/hash.rbs +242 -349
  41. data/core/integer.rbs +246 -308
  42. data/core/io/buffer.rbs +373 -122
  43. data/core/io/wait.rbs +29 -17
  44. data/core/io.rbs +1881 -1518
  45. data/core/kernel.rbs +2116 -1538
  46. data/core/marshal.rbs +24 -14
  47. data/core/match_data.rbs +413 -166
  48. data/core/math.rbs +531 -291
  49. data/core/method.rbs +101 -32
  50. data/core/module.rbs +228 -64
  51. data/core/nil_class.rbs +106 -47
  52. data/core/numeric.rbs +206 -292
  53. data/core/object.rbs +73 -1168
  54. data/core/object_space/weak_key_map.rbs +166 -0
  55. data/core/object_space.rbs +5 -3
  56. data/core/proc.rbs +280 -39
  57. data/core/process.rbs +1318 -658
  58. data/core/ractor.rbs +200 -134
  59. data/core/random.rbs +21 -4
  60. data/core/range.rbs +309 -153
  61. data/core/rational.rbs +4 -12
  62. data/core/rb_config.rbs +64 -43
  63. data/core/rbs/unnamed/argf.rbs +411 -147
  64. data/core/rbs/unnamed/env_class.rbs +137 -253
  65. data/core/rbs/unnamed/random.rbs +49 -26
  66. data/core/refinement.rbs +16 -1
  67. data/core/regexp.rbs +1568 -862
  68. data/core/ruby_vm.rbs +719 -7
  69. data/core/rubygems/config_file.rbs +3 -0
  70. data/core/rubygems/errors.rbs +69 -6
  71. data/core/rubygems/rubygems.rbs +71 -17
  72. data/core/rubygems/version.rbs +11 -7
  73. data/{stdlib/set/0 → core}/set.rbs +80 -91
  74. data/core/signal.rbs +14 -8
  75. data/core/string.rbs +1732 -1607
  76. data/core/struct.rbs +467 -95
  77. data/core/symbol.rbs +215 -245
  78. data/core/thread.rbs +133 -89
  79. data/core/thread_group.rbs +9 -9
  80. data/core/time.rbs +1141 -841
  81. data/core/trace_point.rbs +181 -121
  82. data/core/true_class.rbs +58 -32
  83. data/core/unbound_method.rbs +103 -30
  84. data/core/warning.rbs +50 -5
  85. data/docs/CONTRIBUTING.md +1 -1
  86. data/docs/architecture.md +110 -0
  87. data/docs/collection.md +59 -5
  88. data/docs/data_and_struct.md +86 -0
  89. data/docs/gem.md +57 -0
  90. data/docs/rbs_by_example.md +16 -35
  91. data/docs/repo.md +1 -1
  92. data/docs/sigs.md +7 -7
  93. data/docs/stdlib.md +63 -5
  94. data/docs/syntax.md +255 -61
  95. data/docs/tools.md +1 -0
  96. data/ext/rbs_extension/extconf.rb +10 -0
  97. data/ext/rbs_extension/lexer.c +1741 -1548
  98. data/ext/rbs_extension/lexer.h +11 -1
  99. data/ext/rbs_extension/lexer.re +12 -6
  100. data/ext/rbs_extension/lexstate.c +26 -3
  101. data/ext/rbs_extension/location.c +119 -111
  102. data/ext/rbs_extension/location.h +32 -7
  103. data/ext/rbs_extension/main.c +3 -0
  104. data/ext/rbs_extension/parser.c +883 -481
  105. data/ext/rbs_extension/parserstate.c +65 -25
  106. data/ext/rbs_extension/parserstate.h +13 -3
  107. data/ext/rbs_extension/rbs_extension.h +1 -10
  108. data/ext/rbs_extension/unescape.c +7 -47
  109. data/goodcheck.yml +2 -2
  110. data/{ext/rbs_extension → include/rbs}/constants.h +26 -15
  111. data/include/rbs/ruby_objs.h +72 -0
  112. data/include/rbs.h +7 -0
  113. data/lib/rbs/annotate/annotations.rb +3 -3
  114. data/lib/rbs/annotate/formatter.rb +13 -3
  115. data/lib/rbs/annotate/rdoc_annotator.rb +1 -1
  116. data/lib/rbs/annotate/rdoc_source.rb +12 -3
  117. data/lib/rbs/ast/declarations.rb +85 -2
  118. data/lib/rbs/ast/directives.rb +39 -0
  119. data/lib/rbs/ast/members.rb +49 -15
  120. data/lib/rbs/ast/type_param.rb +104 -15
  121. data/lib/rbs/ast/visitor.rb +137 -0
  122. data/lib/rbs/buffer.rb +5 -0
  123. data/lib/rbs/cli/colored_io.rb +48 -0
  124. data/lib/rbs/cli/diff.rb +83 -0
  125. data/lib/rbs/cli/validate.rb +356 -0
  126. data/lib/rbs/cli.rb +253 -143
  127. data/lib/rbs/collection/cleaner.rb +8 -1
  128. data/lib/rbs/collection/config/lockfile.rb +92 -0
  129. data/lib/rbs/collection/config/lockfile_generator.rb +154 -65
  130. data/lib/rbs/collection/config.rb +19 -46
  131. data/lib/rbs/collection/installer.rb +12 -13
  132. data/lib/rbs/collection/sources/base.rb +2 -2
  133. data/lib/rbs/collection/sources/git.rb +146 -69
  134. data/lib/rbs/collection/sources/local.rb +81 -0
  135. data/lib/rbs/collection/sources/rubygems.rb +10 -12
  136. data/lib/rbs/collection/sources/stdlib.rb +14 -13
  137. data/lib/rbs/collection/sources.rb +15 -2
  138. data/lib/rbs/collection.rb +2 -1
  139. data/lib/rbs/definition.rb +13 -16
  140. data/lib/rbs/definition_builder/ancestor_builder.rb +100 -24
  141. data/lib/rbs/definition_builder/method_builder.rb +4 -4
  142. data/lib/rbs/definition_builder.rb +489 -584
  143. data/lib/rbs/diff.rb +125 -0
  144. data/lib/rbs/environment/use_map.rb +77 -0
  145. data/lib/rbs/environment.rb +406 -105
  146. data/lib/rbs/environment_loader.rb +48 -44
  147. data/lib/rbs/environment_walker.rb +1 -1
  148. data/lib/rbs/errors.rb +175 -56
  149. data/lib/rbs/file_finder.rb +28 -0
  150. data/lib/rbs/location_aux.rb +8 -7
  151. data/lib/rbs/locator.rb +37 -15
  152. data/lib/rbs/method_type.rb +23 -0
  153. data/lib/rbs/namespace.rb +1 -0
  154. data/lib/rbs/parser/lex_result.rb +15 -0
  155. data/lib/rbs/parser/token.rb +23 -0
  156. data/lib/rbs/parser_aux.rb +22 -13
  157. data/lib/rbs/prototype/helpers.rb +48 -22
  158. data/lib/rbs/prototype/node_usage.rb +99 -0
  159. data/lib/rbs/prototype/rb.rb +125 -31
  160. data/lib/rbs/prototype/rbi.rb +49 -36
  161. data/lib/rbs/prototype/runtime/helpers.rb +59 -0
  162. data/lib/rbs/prototype/runtime/reflection.rb +19 -0
  163. data/lib/rbs/prototype/runtime/value_object_generator.rb +279 -0
  164. data/lib/rbs/prototype/runtime.rb +273 -159
  165. data/lib/rbs/resolver/constant_resolver.rb +24 -8
  166. data/lib/rbs/resolver/type_name_resolver.rb +41 -7
  167. data/lib/rbs/sorter.rb +153 -123
  168. data/lib/rbs/substitution.rb +19 -0
  169. data/lib/rbs/subtractor.rb +201 -0
  170. data/lib/rbs/test/errors.rb +24 -11
  171. data/lib/rbs/test/guaranteed.rb +30 -0
  172. data/lib/rbs/test/hook.rb +45 -40
  173. data/lib/rbs/test/setup.rb +1 -1
  174. data/lib/rbs/test/tester.rb +1 -1
  175. data/lib/rbs/test/type_check.rb +120 -23
  176. data/lib/rbs/test.rb +6 -3
  177. data/lib/rbs/type_alias_dependency.rb +13 -3
  178. data/lib/rbs/type_alias_regularity.rb +21 -14
  179. data/lib/rbs/type_name.rb +18 -13
  180. data/lib/rbs/types.rb +352 -18
  181. data/lib/rbs/unit_test/convertibles.rb +176 -0
  182. data/lib/rbs/unit_test/spy.rb +136 -0
  183. data/lib/rbs/unit_test/type_assertions.rb +341 -0
  184. data/lib/rbs/unit_test/with_aliases.rb +143 -0
  185. data/lib/rbs/unit_test.rb +6 -0
  186. data/lib/rbs/validator.rb +55 -30
  187. data/lib/rbs/variance_calculator.rb +26 -23
  188. data/lib/rbs/vendorer.rb +3 -3
  189. data/lib/rbs/version.rb +1 -1
  190. data/lib/rbs/writer.rb +69 -22
  191. data/lib/rbs.rb +7 -2
  192. data/lib/rdoc/discover.rb +1 -1
  193. data/lib/rdoc_plugin/parser.rb +5 -5
  194. data/rbs.gemspec +12 -2
  195. data/schema/decls.json +1 -1
  196. data/schema/members.json +15 -10
  197. data/sig/ancestor_builder.rbs +4 -0
  198. data/sig/ancestor_graph.rbs +22 -2
  199. data/sig/annotate/formatter.rbs +2 -2
  200. data/sig/annotate/rdoc_annotater.rbs +1 -1
  201. data/sig/cli/colored_io.rbs +15 -0
  202. data/sig/cli/diff.rbs +21 -0
  203. data/sig/cli/validate.rbs +43 -0
  204. data/sig/cli.rbs +4 -0
  205. data/sig/collection/config/lockfile.rbs +74 -0
  206. data/sig/collection/config/lockfile_generator.rbs +66 -0
  207. data/sig/collection/config.rbs +5 -48
  208. data/sig/collection/installer.rbs +1 -1
  209. data/sig/collection/sources.rbs +105 -33
  210. data/sig/constant.rbs +1 -1
  211. data/sig/declarations.rbs +42 -3
  212. data/sig/definition.rbs +26 -10
  213. data/sig/definition_builder.rbs +103 -81
  214. data/sig/diff.rbs +28 -0
  215. data/sig/directives.rbs +61 -0
  216. data/sig/environment.rbs +175 -29
  217. data/sig/environment_loader.rbs +20 -18
  218. data/sig/errors.rbs +123 -2
  219. data/sig/file_finder.rbs +28 -0
  220. data/sig/location.rbs +0 -3
  221. data/sig/locator.rbs +14 -2
  222. data/sig/manifest.yaml +0 -1
  223. data/sig/members.rbs +32 -9
  224. data/sig/method_types.rbs +10 -4
  225. data/sig/namespace.rbs +2 -3
  226. data/sig/parser.rbs +55 -16
  227. data/sig/prototype/helpers.rbs +4 -0
  228. data/sig/prototype/node_usage.rbs +20 -0
  229. data/sig/prototype/rb.rbs +10 -2
  230. data/sig/prototype/rbi.rbs +2 -0
  231. data/sig/prototype/runtime.rbs +182 -0
  232. data/sig/rbs.rbs +1 -1
  233. data/sig/rdoc/rbs.rbs +4 -0
  234. data/sig/repository.rbs +7 -5
  235. data/sig/resolver/constant_resolver.rbs +3 -4
  236. data/sig/resolver/context.rbs +1 -1
  237. data/sig/resolver/type_name_resolver.rbs +5 -1
  238. data/sig/shims/bundler.rbs +38 -0
  239. data/sig/shims/rubygems.rbs +19 -0
  240. data/sig/sorter.rbs +23 -5
  241. data/sig/substitution.rbs +6 -0
  242. data/sig/subtractor.rbs +37 -0
  243. data/sig/test/errors.rbs +52 -0
  244. data/sig/test/guranteed.rbs +9 -0
  245. data/sig/test/type_check.rbs +19 -0
  246. data/sig/test.rbs +82 -0
  247. data/sig/type_alias_dependency.rbs +31 -0
  248. data/sig/type_alias_regularity.rbs +12 -6
  249. data/sig/type_param.rbs +45 -9
  250. data/sig/typename.rbs +8 -5
  251. data/sig/types.rbs +119 -12
  252. data/sig/unit_test/convertibles.rbs +154 -0
  253. data/sig/unit_test/spy.rbs +28 -0
  254. data/sig/unit_test/type_assertions.rbs +194 -0
  255. data/sig/unit_test/with_aliases.rbs +136 -0
  256. data/sig/use_map.rbs +35 -0
  257. data/sig/validator.rbs +12 -5
  258. data/sig/variance_calculator.rbs +3 -1
  259. data/sig/vendorer.rbs +1 -1
  260. data/sig/visitor.rbs +47 -0
  261. data/sig/writer.rbs +6 -2
  262. data/src/constants.c +153 -0
  263. data/src/ruby_objs.c +793 -0
  264. data/stdlib/base64/0/base64.rbs +298 -45
  265. data/stdlib/benchmark/0/benchmark.rbs +12 -3
  266. data/stdlib/bigdecimal/0/big_decimal.rbs +62 -198
  267. data/stdlib/cgi/0/core.rbs +68 -15
  268. data/stdlib/cgi/0/manifest.yaml +1 -0
  269. data/stdlib/coverage/0/coverage.rbs +50 -11
  270. data/stdlib/csv/0/csv.rbs +90 -119
  271. data/stdlib/csv/0/manifest.yaml +1 -0
  272. data/stdlib/date/0/date.rbs +806 -735
  273. data/stdlib/date/0/date_time.rbs +70 -211
  274. data/stdlib/dbm/0/dbm.rbs +0 -2
  275. data/stdlib/delegate/0/delegator.rbs +184 -0
  276. data/stdlib/delegate/0/kernel.rbs +47 -0
  277. data/stdlib/delegate/0/simple_delegator.rbs +96 -0
  278. data/stdlib/did_you_mean/0/did_you_mean.rbs +3 -8
  279. data/stdlib/digest/0/digest.rbs +48 -35
  280. data/stdlib/erb/0/erb.rbs +15 -39
  281. data/stdlib/etc/0/etc.rbs +174 -54
  282. data/stdlib/fileutils/0/fileutils.rbs +1234 -385
  283. data/stdlib/forwardable/0/forwardable.rbs +4 -4
  284. data/stdlib/io-console/0/io-console.rbs +82 -17
  285. data/stdlib/ipaddr/0/ipaddr.rbs +11 -6
  286. data/stdlib/json/0/json.rbs +434 -151
  287. data/stdlib/kconv/0/kconv.rbs +166 -0
  288. data/stdlib/logger/0/formatter.rbs +0 -2
  289. data/stdlib/logger/0/log_device.rbs +1 -3
  290. data/stdlib/logger/0/logger.rbs +465 -328
  291. data/stdlib/minitest/0/kernel.rbs +2 -2
  292. data/stdlib/minitest/0/minitest/abstract_reporter.rbs +4 -1
  293. data/stdlib/minitest/0/minitest/assertion.rbs +1 -0
  294. data/stdlib/minitest/0/minitest/assertions.rbs +58 -13
  295. data/stdlib/minitest/0/minitest/backtrace_filter.rbs +7 -0
  296. data/stdlib/minitest/0/minitest/bench_spec.rbs +8 -8
  297. data/stdlib/minitest/0/minitest/benchmark.rbs +17 -16
  298. data/stdlib/minitest/0/minitest/compress.rbs +13 -0
  299. data/stdlib/minitest/0/minitest/error_on_warning.rbs +3 -0
  300. data/stdlib/minitest/0/minitest/mock.rbs +9 -5
  301. data/stdlib/minitest/0/minitest/parallel/executor.rbs +4 -0
  302. data/stdlib/minitest/0/minitest/parallel/test/class_methods.rbs +0 -1
  303. data/stdlib/minitest/0/minitest/pride_io.rbs +8 -0
  304. data/stdlib/minitest/0/minitest/pride_lol.rbs +2 -0
  305. data/stdlib/minitest/0/minitest/progress_reporter.rbs +1 -1
  306. data/stdlib/minitest/0/minitest/reportable.rbs +2 -0
  307. data/stdlib/minitest/0/minitest/runnable.rbs +33 -1
  308. data/stdlib/minitest/0/minitest/spec/dsl/instance_methods.rbs +1 -1
  309. data/stdlib/minitest/0/minitest/spec/dsl.rbs +10 -6
  310. data/stdlib/minitest/0/minitest/spec.rbs +1 -1
  311. data/stdlib/minitest/0/minitest/statistics_reporter.rbs +5 -0
  312. data/stdlib/minitest/0/minitest/summary_reporter.rbs +0 -7
  313. data/stdlib/minitest/0/minitest/test/lifecycle_hooks.rbs +7 -7
  314. data/stdlib/minitest/0/minitest/test.rbs +7 -14
  315. data/stdlib/minitest/0/minitest/unexpected_error.rbs +2 -0
  316. data/stdlib/minitest/0/minitest/unexpected_warning.rbs +6 -0
  317. data/stdlib/minitest/0/minitest/unit.rbs +1 -2
  318. data/stdlib/minitest/0/minitest.rbs +41 -892
  319. data/stdlib/monitor/0/monitor.rbs +91 -10
  320. data/stdlib/mutex_m/0/mutex_m.rbs +0 -2
  321. data/stdlib/net-http/0/manifest.yaml +1 -1
  322. data/stdlib/net-http/0/net-http.rbs +3858 -964
  323. data/stdlib/net-protocol/0/manifest.yaml +2 -0
  324. data/stdlib/net-protocol/0/net-protocol.rbs +56 -0
  325. data/stdlib/net-smtp/0/manifest.yaml +2 -0
  326. data/stdlib/net-smtp/0/net-smtp.rbs +55 -0
  327. data/stdlib/nkf/0/nkf.rbs +35 -5
  328. data/stdlib/objspace/0/objspace.rbs +40 -18
  329. data/stdlib/observable/0/observable.rbs +217 -0
  330. data/stdlib/open-uri/0/manifest.yaml +4 -0
  331. data/stdlib/open-uri/0/open-uri.rbs +393 -0
  332. data/stdlib/open3/0/open3.rbs +147 -0
  333. data/stdlib/openssl/0/manifest.yaml +1 -0
  334. data/stdlib/openssl/0/openssl.rbs +681 -316
  335. data/stdlib/optparse/0/optparse.rbs +100 -65
  336. data/stdlib/pathname/0/pathname.rbs +24 -15
  337. data/stdlib/pp/0/manifest.yaml +2 -0
  338. data/stdlib/pp/0/pp.rbs +300 -0
  339. data/stdlib/prettyprint/0/prettyprint.rbs +2 -6
  340. data/stdlib/pstore/0/pstore.rbs +370 -156
  341. data/stdlib/psych/0/core_ext.rbs +12 -0
  342. data/stdlib/{yaml → psych}/0/dbm.rbs +3 -3
  343. data/stdlib/psych/0/manifest.yaml +3 -0
  344. data/stdlib/psych/0/psych.rbs +402 -0
  345. data/stdlib/{yaml → psych}/0/store.rbs +2 -2
  346. data/stdlib/pty/0/pty.rbs +63 -11
  347. data/stdlib/rdoc/0/code_object.rbs +51 -0
  348. data/stdlib/rdoc/0/comment.rbs +59 -0
  349. data/stdlib/rdoc/0/context.rbs +153 -0
  350. data/stdlib/rdoc/0/markup.rbs +117 -0
  351. data/stdlib/rdoc/0/parser.rbs +56 -0
  352. data/stdlib/rdoc/0/rdoc.rbs +13 -380
  353. data/stdlib/rdoc/0/ri.rbs +17 -0
  354. data/stdlib/rdoc/0/store.rbs +48 -0
  355. data/stdlib/rdoc/0/top_level.rbs +97 -0
  356. data/stdlib/resolv/0/resolv.rbs +16 -79
  357. data/stdlib/ripper/0/ripper.rbs +1648 -0
  358. data/stdlib/securerandom/0/securerandom.rbs +7 -2
  359. data/stdlib/shellwords/0/shellwords.rbs +11 -12
  360. data/stdlib/singleton/0/singleton.rbs +0 -3
  361. data/stdlib/socket/0/addrinfo.rbs +13 -18
  362. data/stdlib/socket/0/basic_socket.rbs +5 -10
  363. data/stdlib/socket/0/ip_socket.rbs +0 -2
  364. data/stdlib/socket/0/socket.rbs +77 -46
  365. data/stdlib/socket/0/tcp_server.rbs +0 -5
  366. data/stdlib/socket/0/tcp_socket.rbs +36 -3
  367. data/stdlib/socket/0/udp_socket.rbs +4 -5
  368. data/stdlib/socket/0/unix_server.rbs +0 -5
  369. data/stdlib/socket/0/unix_socket.rbs +2 -4
  370. data/{core/string_io.rbs → stdlib/stringio/0/stringio.rbs} +188 -107
  371. data/stdlib/strscan/0/string_scanner.rbs +1269 -425
  372. data/stdlib/tempfile/0/tempfile.rbs +224 -61
  373. data/stdlib/time/0/time.rbs +48 -35
  374. data/stdlib/timeout/0/timeout.rbs +17 -8
  375. data/stdlib/tmpdir/0/tmpdir.rbs +10 -3
  376. data/stdlib/tsort/0/tsort.rbs +0 -4
  377. data/stdlib/uri/0/common.rbs +271 -144
  378. data/stdlib/uri/0/file.rbs +5 -0
  379. data/stdlib/uri/0/ftp.rbs +1 -1
  380. data/stdlib/uri/0/generic.rbs +26 -22
  381. data/stdlib/uri/0/http.rbs +4 -4
  382. data/stdlib/uri/0/ldap.rbs +1 -1
  383. data/stdlib/uri/0/mailto.rbs +84 -0
  384. data/stdlib/uri/0/rfc2396_parser.rbs +3 -0
  385. data/stdlib/yaml/0/manifest.yaml +1 -2
  386. data/stdlib/yaml/0/yaml.rbs +1 -199
  387. data/stdlib/zlib/0/buf_error.rbs +10 -0
  388. data/stdlib/zlib/0/data_error.rbs +10 -0
  389. data/stdlib/zlib/0/deflate.rbs +210 -0
  390. data/stdlib/zlib/0/error.rbs +20 -0
  391. data/stdlib/zlib/0/gzip_file/crc_error.rbs +12 -0
  392. data/stdlib/zlib/0/gzip_file/error.rbs +23 -0
  393. data/stdlib/zlib/0/gzip_file/length_error.rbs +12 -0
  394. data/stdlib/zlib/0/gzip_file/no_footer.rbs +11 -0
  395. data/stdlib/zlib/0/gzip_file.rbs +156 -0
  396. data/stdlib/zlib/0/gzip_reader.rbs +293 -0
  397. data/stdlib/zlib/0/gzip_writer.rbs +166 -0
  398. data/stdlib/zlib/0/inflate.rbs +180 -0
  399. data/stdlib/zlib/0/mem_error.rbs +10 -0
  400. data/stdlib/zlib/0/need_dict.rbs +13 -0
  401. data/stdlib/zlib/0/stream_end.rbs +11 -0
  402. data/stdlib/zlib/0/stream_error.rbs +11 -0
  403. data/stdlib/zlib/0/version_error.rbs +11 -0
  404. data/stdlib/zlib/0/zlib.rbs +1 -3
  405. data/stdlib/zlib/0/zstream.rbs +200 -0
  406. data/templates/include/rbs/constants.h.erb +20 -0
  407. data/templates/include/rbs/ruby_objs.h.erb +10 -0
  408. data/templates/src/constants.c.erb +36 -0
  409. data/templates/src/ruby_objs.c.erb +27 -0
  410. data/templates/template.rb +122 -0
  411. metadata +136 -36
  412. data/Gemfile +0 -33
  413. data/Gemfile.lock +0 -118
  414. data/core/deprecated.rbs +0 -9
  415. data/ext/rbs_extension/constants.c +0 -135
  416. data/ext/rbs_extension/ruby_objs.c +0 -525
  417. data/ext/rbs_extension/ruby_objs.h +0 -43
  418. data/lib/rbs/constant_table.rb +0 -167
  419. data/lib/rbs/parser_compat/lexer_error.rb +0 -6
  420. data/lib/rbs/parser_compat/located_value.rb +0 -7
  421. data/lib/rbs/parser_compat/semantics_error.rb +0 -6
  422. data/lib/rbs/parser_compat/syntax_error.rb +0 -6
  423. data/lib/rbs/test/spy.rb +0 -6
  424. data/lib/rbs/type_name_resolver.rb +0 -67
  425. data/sig/constant_table.rbs +0 -30
  426. data/sig/shims/abstract_syntax_tree.rbs +0 -25
  427. data/sig/shims/pp.rbs +0 -3
  428. data/sig/shims/ripper.rbs +0 -8
  429. data/sig/shims.rbs +0 -69
  430. data/sig/type_name_resolver.rbs +0 -26
  431. data/stdlib/minitest/0/manifest.yaml +0 -2
  432. data/stdlib/prime/0/integer-extension.rbs +0 -41
  433. data/stdlib/prime/0/manifest.yaml +0 -2
  434. data/stdlib/prime/0/prime.rbs +0 -372
data/core/time.rbs CHANGED
@@ -1,23 +1,91 @@
1
1
  # <!-- rdoc-file=timev.rb -->
2
- # Time is an abstraction of dates and times. Time is stored internally as the
3
- # number of seconds with subsecond since the *Epoch*, 1970-01-01 00:00:00 UTC.
2
+ # A `Time` object represents a date and time:
4
3
  #
5
- # The Time class treats GMT (Greenwich Mean Time) and UTC (Coordinated Universal
6
- # Time) as equivalent. GMT is the older way of referring to these baseline times
7
- # but persists in the names of calls on POSIX systems.
4
+ # Time.new(2000, 1, 1, 0, 0, 0) # => 2000-01-01 00:00:00 -0600
8
5
  #
9
- # Note: A Time object uses the resolution available on your system clock.
6
+ # Although its value can be expressed as a single numeric (see [Epoch
7
+ # Seconds](rdoc-ref:Time@Epoch+Seconds) below), it can be convenient to deal
8
+ # with the value by parts:
10
9
  #
11
- # All times may have subsecond. Be aware of this fact when comparing times with
12
- # each other -- times that are apparently equal when displayed may be different
13
- # when compared. (Since Ruby 2.7.0, Time#inspect shows subsecond but Time#to_s
14
- # still doesn't show subsecond.)
10
+ # t = Time.new(-2000, 1, 1, 0, 0, 0.0)
11
+ # # => -2000-01-01 00:00:00 -0600
12
+ # t.year # => -2000
13
+ # t.month # => 1
14
+ # t.mday # => 1
15
+ # t.hour # => 0
16
+ # t.min # => 0
17
+ # t.sec # => 0
18
+ # t.subsec # => 0
19
+ #
20
+ # t = Time.new(2000, 12, 31, 23, 59, 59.5)
21
+ # # => 2000-12-31 23:59:59.5 -0600
22
+ # t.year # => 2000
23
+ # t.month # => 12
24
+ # t.mday # => 31
25
+ # t.hour # => 23
26
+ # t.min # => 59
27
+ # t.sec # => 59
28
+ # t.subsec # => (1/2)
29
+ #
30
+ # ## Epoch Seconds
31
+ #
32
+ # *Epoch seconds* is the exact number of seconds (including fractional
33
+ # subseconds) since the Unix Epoch, January 1, 1970.
34
+ #
35
+ # You can retrieve that value exactly using method Time.to_r:
36
+ #
37
+ # Time.at(0).to_r # => (0/1)
38
+ # Time.at(0.999999).to_r # => (9007190247541737/9007199254740992)
39
+ #
40
+ # Other retrieval methods such as Time#to_i and Time#to_f may return a value
41
+ # that rounds or truncates subseconds.
42
+ #
43
+ # ## Time Resolution
44
+ #
45
+ # A `Time` object derived from the system clock (for example, by method
46
+ # Time.now) has the resolution supported by the system.
47
+ #
48
+ # ## Time Internal Representation
49
+ #
50
+ # Time implementation uses a signed 63 bit integer, Integer, or Rational. It is
51
+ # a number of nanoseconds since the *Epoch*. The signed 63 bit integer can
52
+ # represent 1823-11-12 to 2116-02-20. When Integer or Rational is used (before
53
+ # 1823, after 2116, under nanosecond), Time works slower than when the signed 63
54
+ # bit integer is used.
55
+ #
56
+ # Ruby uses the C function `localtime` and `gmtime` to map between the number
57
+ # and 6-tuple (year,month,day,hour,minute,second). `localtime` is used for local
58
+ # time and "gmtime" is used for UTC.
59
+ #
60
+ # Integer and Rational has no range limit, but the localtime and gmtime has
61
+ # range limits due to the C types `time_t` and `struct tm`. If that limit is
62
+ # exceeded, Ruby extrapolates the localtime function.
63
+ #
64
+ # The Time class always uses the Gregorian calendar. I.e. the proleptic
65
+ # Gregorian calendar is used. Other calendars, such as Julian calendar, are not
66
+ # supported.
67
+ #
68
+ # `time_t` can represent 1901-12-14 to 2038-01-19 if it is 32 bit signed
69
+ # integer, -292277022657-01-27 to 292277026596-12-05 if it is 64 bit signed
70
+ # integer. However `localtime` on some platforms doesn't supports negative
71
+ # `time_t` (before 1970).
72
+ #
73
+ # `struct tm` has *tm_year* member to represent years. (`tm_year = 0` means the
74
+ # year 1900.) It is defined as `int` in the C standard. *tm_year* can represent
75
+ # between -2147481748 to 2147485547 if `int` is 32 bit.
76
+ #
77
+ # Ruby supports leap seconds as far as if the C function `localtime` and
78
+ # `gmtime` supports it. They use the tz database in most Unix systems. The tz
79
+ # database has timezones which supports leap seconds. For example, "Asia/Tokyo"
80
+ # doesn't support leap seconds but "right/Asia/Tokyo" supports leap seconds. So,
81
+ # Ruby supports leap seconds if the TZ environment variable is set to
82
+ # "right/Asia/Tokyo" in most Unix systems.
15
83
  #
16
84
  # ## Examples
17
85
  #
18
86
  # All of these examples were done using the EST timezone which is GMT-5.
19
87
  #
20
- # ### Creating a New Time Instance
88
+ # ### Creating a New `Time` Instance
21
89
  #
22
90
  # You can create a new instance of Time with Time.new. This will use the current
23
91
  # system time. Time.now is an alias for this. You can also pass parts of the
@@ -34,7 +102,7 @@
34
102
  #
35
103
  # Time.new(2002, 10, 31, 2, 2, 2, "+02:00") #=> 2002-10-31 02:02:02 +0200
36
104
  #
37
- # Or a timezone object:
105
+ # Or [a timezone object](rdoc-ref:Time@Timezone+Objects):
38
106
  #
39
107
  # zone = timezone("Europe/Athens") # Eastern European Time, UTC+2
40
108
  # Time.new(2002, 10, 31, 2, 2, 2, zone) #=> 2002-10-31 02:02:02 +0200
@@ -48,7 +116,7 @@
48
116
  #
49
117
  # Time.at(628232400) #=> 1989-11-28 00:00:00 -0500
50
118
  #
51
- # ### Working with an Instance of Time
119
+ # ### Working with an Instance of `Time`
52
120
  #
53
121
  # Once you have an instance of Time there is a multitude of things you can do
54
122
  # with it. Below are some examples. For all of the following examples, we will
@@ -90,23 +158,19 @@
90
158
  #
91
159
  # ## What's Here
92
160
  #
93
- # First, what's elsewhere. Class Time:
94
- #
95
- # * Inherits from [class
96
- # Object](Object.html#class-Object-label-What-27s+Here).
97
- # * Includes [module
98
- # Comparable](Comparable.html#module-Comparable-label-What-27s+Here).
161
+ # First, what's elsewhere. Class `Time`:
99
162
  #
163
+ # * Inherits from [class Object](rdoc-ref:Object@What-27s+Here).
164
+ # * Includes [module Comparable](rdoc-ref:Comparable@What-27s+Here).
100
165
  #
101
- # Here, class Time provides methods that are useful for:
102
- #
103
- # * [Creating \Time objects](#class-Time-label-Methods+for+Creating).
104
- # * [Fetching \Time values](#class-Time-label-Methods+for+Fetching).
105
- # * [Querying a \Time object](#class-Time-label-Methods+for+Querying).
106
- # * [Comparing \Time objects](#class-Time-label-Methods+for+Comparing).
107
- # * [Converting a \Time object](#class-Time-label-Methods+for+Converting).
108
- # * [Rounding a \Time](#class-Time-label-Methods+for+Rounding).
166
+ # Here, class `Time` provides methods that are useful for:
109
167
  #
168
+ # * [Creating Time objects](rdoc-ref:Time@Methods+for+Creating).
169
+ # * [Fetching Time values](rdoc-ref:Time@Methods+for+Fetching).
170
+ # * [Querying a Time object](rdoc-ref:Time@Methods+for+Querying).
171
+ # * [Comparing Time objects](rdoc-ref:Time@Methods+for+Comparing).
172
+ # * [Converting a Time object](rdoc-ref:Time@Methods+for+Converting).
173
+ # * [Rounding a Time](rdoc-ref:Time@Methods+for+Rounding).
110
174
  #
111
175
  # ### Methods for Creating
112
176
  #
@@ -118,9 +182,7 @@
118
182
  # * ::at: Returns a new time based on seconds since epoch.
119
183
  # * ::now: Returns a new time based on the current system time.
120
184
  # * #+ (plus): Returns a new time increased by the given number of seconds.
121
- # * [-](#method-i-2D) (minus): Returns a new time
122
- # decreased by the given number of seconds.
123
- #
185
+ # * #- (minus): Returns a new time decreased by the given number of seconds.
124
186
  #
125
187
  # ### Methods for Fetching
126
188
  #
@@ -146,7 +208,6 @@
146
208
  # * #to_r: Returns the Rational number of seconds since epoch for the time.
147
209
  # * #zone: Returns a string representation of the timezone of the time.
148
210
  #
149
- #
150
211
  # ### Methods for Querying
151
212
  #
152
213
  # * #utc? (aliased as #gmt?): Returns whether the time is UTC.
@@ -160,13 +221,11 @@
160
221
  # * #friday?: Returns whether time is a Friday.
161
222
  # * #saturday?: Returns whether the time is a Saturday.
162
223
  #
163
- #
164
224
  # ### Methods for Comparing
165
225
  #
166
- # * [#<=>](#method-i-3C-3D-3E): Compares `self` to another time.
226
+ # * #<=>: Compares `self` to another time.
167
227
  # * #eql?: Returns whether the time is equal to another time.
168
228
  #
169
- #
170
229
  # ### Methods for Converting
171
230
  #
172
231
  # * #asctime (aliased as #ctime): Returns the time as a string.
@@ -178,7 +237,8 @@
178
237
  # * #getlocal: Returns a new time converted to local time.
179
238
  # * #utc (aliased as #gmtime): Converts time to UTC in place.
180
239
  # * #localtime: Converts time to local time in place.
181
- #
240
+ # * #deconstruct_keys: Returns a hash of time components used in
241
+ # pattern-matching.
182
242
  #
183
243
  # ### Methods for Rounding
184
244
  #
@@ -186,95 +246,273 @@
186
246
  # * #ceil: Returns a new time with subseconds raised to a ceiling.
187
247
  # * #floor: Returns a new time with subseconds lowered to a floor.
188
248
  #
249
+ # For the forms of argument `zone`, see [Timezone
250
+ # Specifiers](rdoc-ref:Time@Timezone+Specifiers).
251
+ #
252
+ # ## Timezone Specifiers
253
+ #
254
+ # Certain `Time` methods accept arguments that specify timezones:
255
+ #
256
+ # * Time.at: keyword argument `in:`.
257
+ # * Time.new: positional argument `zone` or keyword argument `in:`.
258
+ # * Time.now: keyword argument `in:`.
259
+ # * Time#getlocal: positional argument `zone`.
260
+ # * Time#localtime: positional argument `zone`.
261
+ #
262
+ # The value given with any of these must be one of the following (each detailed
263
+ # below):
264
+ #
265
+ # * [Hours/minutes offset](rdoc-ref:Time@Hours-2FMinutes+Offsets).
266
+ # * [Single-letter offset](rdoc-ref:Time@Single-Letter+Offsets).
267
+ # * [Integer offset](rdoc-ref:Time@Integer+Offsets).
268
+ # * [Timezone object](rdoc-ref:Time@Timezone+Objects).
269
+ # * [Timezone name](rdoc-ref:Time@Timezone+Names).
270
+ #
271
+ # ### Hours/Minutes Offsets
272
+ #
273
+ # The zone value may be a string offset from UTC in the form `'+HH:MM'` or
274
+ # `'-HH:MM'`, where:
275
+ #
276
+ # * `HH` is the 2-digit hour in the range `0..23`.
277
+ # * `MM` is the 2-digit minute in the range `0..59`.
278
+ #
279
+ # Examples:
280
+ #
281
+ # t = Time.utc(2000, 1, 1, 20, 15, 1) # => 2000-01-01 20:15:01 UTC
282
+ # Time.at(t, in: '-23:59') # => 1999-12-31 20:16:01 -2359
283
+ # Time.at(t, in: '+23:59') # => 2000-01-02 20:14:01 +2359
284
+ #
285
+ # ### Single-Letter Offsets
286
+ #
287
+ # The zone value may be a letter in the range `'A'..'I'` or `'K'..'Z'`; see
288
+ # [List of military time
289
+ # zones](https://en.wikipedia.org/wiki/List_of_military_time_zones):
290
+ #
291
+ # t = Time.utc(2000, 1, 1, 20, 15, 1) # => 2000-01-01 20:15:01 UTC
292
+ # Time.at(t, in: 'A') # => 2000-01-01 21:15:01 +0100
293
+ # Time.at(t, in: 'I') # => 2000-01-02 05:15:01 +0900
294
+ # Time.at(t, in: 'K') # => 2000-01-02 06:15:01 +1000
295
+ # Time.at(t, in: 'Y') # => 2000-01-01 08:15:01 -1200
296
+ # Time.at(t, in: 'Z') # => 2000-01-01 20:15:01 UTC
297
+ #
298
+ # ### Integer Offsets
299
+ #
300
+ # The zone value may be an integer number of seconds in the range
301
+ # `-86399..86399`:
302
+ #
303
+ # t = Time.utc(2000, 1, 1, 20, 15, 1) # => 2000-01-01 20:15:01 UTC
304
+ # Time.at(t, in: -86399) # => 1999-12-31 20:15:02 -235959
305
+ # Time.at(t, in: 86399) # => 2000-01-02 20:15:00 +235959
306
+ #
307
+ # ### Timezone Objects
308
+ #
309
+ # The zone value may be an object responding to certain timezone methods, an
310
+ # instance of [Timezone](https://github.com/panthomakos/timezone) and
311
+ # [TZInfo](https://tzinfo.github.io) for example.
312
+ #
313
+ # The timezone methods are:
314
+ #
315
+ # * `local_to_utc`:
316
+ #
317
+ # Called when Time.new is invoked with `tz` as the value of positional
318
+ # argument `zone` or keyword argument `in:`.
319
+ #
320
+ # Argument
321
+ # : a [Time-like object](rdoc-ref:Time@Time-Like+Objects).
322
+ #
323
+ # Returns
324
+ # : a [Time-like object](rdoc-ref:Time@Time-Like+Objects) in the UTC
325
+ # timezone.
326
+ #
327
+ #
328
+ # * `utc_to_local`:
329
+ #
330
+ # Called when Time.at or Time.now is invoked with `tz` as the value for
331
+ # keyword argument `in:`, and when Time#getlocal or Time#localtime is called
332
+ # with `tz` as the value for positional argument `zone`.
333
+ #
334
+ # The UTC offset will be calculated as the difference between the original
335
+ # time and the returned object as an `Integer`. If the object is in fixed
336
+ # offset, its `utc_offset` is also counted.
337
+ #
338
+ # Argument
339
+ # : a [Time-like object](rdoc-ref:Time@Time-Like+Objects).
340
+ #
341
+ # Returns
342
+ # : a [Time-like object](rdoc-ref:Time@Time-Like+Objects) in the local
343
+ # timezone.
344
+ #
345
+ #
346
+ # A custom timezone class may have these instance methods, which will be called
347
+ # if defined:
348
+ #
349
+ # * `abbr`:
350
+ #
351
+ # Called when Time#strftime is invoked with a format involving `%Z`.
352
+ #
353
+ # Argument
354
+ # : a [Time-like object](rdoc-ref:Time@Time-Like+Objects).
355
+ #
356
+ # Returns
357
+ # : a string abbreviation for the timezone name.
358
+ #
359
+ #
360
+ # * `dst?`:
361
+ #
362
+ # Called when Time.at or Time.now is invoked with `tz` as the value for
363
+ # keyword argument `in:`, and when Time#getlocal or Time#localtime is called
364
+ # with `tz` as the value for positional argument `zone`.
365
+ #
366
+ # Argument
367
+ # : a [Time-like object](rdoc-ref:Time@Time-Like+Objects).
368
+ #
369
+ # Returns
370
+ # : whether the time is daylight saving time.
371
+ #
372
+ #
373
+ # * `name`:
189
374
  #
190
- # ## Timezone Argument
375
+ # Called when `Marshal.dump(t)` is invoked
191
376
  #
192
- # A timezone argument must have `local_to_utc` and `utc_to_local` methods, and
193
- # may have `name`, `abbr`, and `dst?` methods.
377
+ # Argument
378
+ # : none.
194
379
  #
195
- # The `local_to_utc` method should convert a Time-like object from the timezone
196
- # to UTC, and `utc_to_local` is the opposite. The result also should be a Time
197
- # or Time-like object (not necessary to be the same class). The #zone of the
198
- # result is just ignored. Time-like argument to these methods is similar to a
199
- # Time object in UTC without subsecond; it has attribute readers for the parts,
200
- # e.g. #year, #month, and so on, and epoch time readers, #to_i. The subsecond
201
- # attributes are fixed as 0, and #utc_offset, #zone, #isdst, and their aliases
202
- # are same as a Time object in UTC. Also #to_time, #+, and #- methods are
203
- # defined.
380
+ # Returns
381
+ # : the string name of the timezone.
204
382
  #
205
- # The `name` method is used for marshaling. If this method is not defined on a
206
- # timezone object, Time objects using that timezone object can not be dumped by
207
- # Marshal.
208
383
  #
209
- # The `abbr` method is used by '%Z' in #strftime.
384
+ # #### `Time`-Like Objects
210
385
  #
211
- # The `dst?` method is called with a `Time` value and should return whether the
212
- # `Time` value is in daylight savings time in the zone.
386
+ # A `Time`-like object is a container object capable of interfacing with
387
+ # timezone libraries for timezone conversion.
213
388
  #
214
- # ### Auto Conversion to Timezone
389
+ # The argument to the timezone conversion methods above will have attributes
390
+ # similar to Time, except that timezone related attributes are meaningless.
215
391
  #
216
- # At loading marshaled data, a timezone name will be converted to a timezone
217
- # object by `find_timezone` class method, if the method is defined.
392
+ # The objects returned by `local_to_utc` and `utc_to_local` methods of the
393
+ # timezone object may be of the same class as their arguments, of arbitrary
394
+ # object classes, or of class Integer.
218
395
  #
219
- # Similarly, that class method will be called when a timezone argument does not
220
- # have the necessary methods mentioned above.
396
+ # For a returned class other than `Integer`, the class must have the following
397
+ # methods:
398
+ #
399
+ # * `year`
400
+ # * `mon`
401
+ # * `mday`
402
+ # * `hour`
403
+ # * `min`
404
+ # * `sec`
405
+ # * `isdst`
406
+ # * `to_i`
407
+ #
408
+ # For a returned `Integer`, its components, decomposed in UTC, are interpreted
409
+ # as times in the specified timezone.
410
+ #
411
+ # ### Timezone Names
412
+ #
413
+ # If the class (the receiver of class methods, or the class of the receiver of
414
+ # instance methods) has `find_timezone` singleton method, this method is called
415
+ # to achieve the corresponding timezone object from a timezone name.
416
+ #
417
+ # For example, using [Timezone](https://github.com/panthomakos/timezone):
418
+ # class TimeWithTimezone < Time
419
+ # require 'timezone'
420
+ # def self.find_timezone(z) = Timezone[z]
421
+ # end
422
+ #
423
+ # TimeWithTimezone.now(in: "America/New_York") #=> 2023-12-25 00:00:00 -0500
424
+ # TimeWithTimezone.new("2023-12-25 America/New_York") #=> 2023-12-25 00:00:00 -0500
425
+ #
426
+ # Or, using [TZInfo](https://tzinfo.github.io):
427
+ # class TimeWithTZInfo < Time
428
+ # require 'tzinfo'
429
+ # def self.find_timezone(z) = TZInfo::Timezone.get(z)
430
+ # end
431
+ #
432
+ # TimeWithTZInfo.now(in: "America/New_York") #=> 2023-12-25 00:00:00 -0500
433
+ # TimeWithTZInfo.new("2023-12-25 America/New_York") #=> 2023-12-25 00:00:00 -0500
434
+ #
435
+ # You can define this method per subclasses, or on the toplevel Time class.
221
436
  #
222
437
  class Time < Object
438
+ # A type that's used for timeouts.
439
+ #
440
+ # All numeric types implement this, but custom classes can also implement it if desired.
441
+ #
442
+ # Usage of `Time::_Timeout` is fairly common throughout the stdlib, such as in `Kernel#sleep`,
443
+ # `IO#timeout=`, and `TCPSocket#new`'s `connet_timeout` field.
444
+ interface _Timeout
445
+ # Returns `[seconds, nanoseconds]`.
446
+ #
447
+ # The `seconds` should be a whole number of seconds, whereas the `nanoseconds` should be smaller
448
+ # than one. For example, `3.125.divmod(1)` would yield `[3, 0.125]`
449
+ def divmod: (1) -> [int, _TimeoutNSecs]
450
+ end
451
+
452
+ # The nanoseconds part of `Time::_Timeout`'s return value. See it for details
453
+ interface _TimeoutNSecs
454
+ # Convert `self` into a whole number of seconds.
455
+ def *: (1_000_000_000) -> int
456
+ end
457
+
223
458
  include Comparable
224
459
 
225
460
  # <!--
226
461
  # rdoc-file=timev.rb
227
462
  # - at(time, subsec = false, unit = :microsecond, in: nil)
228
463
  # -->
229
- # *Time*
230
- #
231
- # This form accepts a Time object `time` and optional keyword argument `in`:
232
- #
233
- # Time.at(Time.new) # => 2021-04-26 08:52:31.6023486 -0500
234
- # Time.at(Time.new, in: '+09:00') # => 2021-04-26 22:52:31.6023486 +0900
235
- #
236
- # *Seconds*
237
- #
238
- # This form accepts a numeric number of seconds `sec` and optional keyword
239
- # argument `in`:
240
- #
241
- # Time.at(946702800) # => 1999-12-31 23:00:00 -0600
242
- # Time.at(946702800, in: '+09:00') # => 2000-01-01 14:00:00 +0900
243
- #
244
- # *Seconds with Subseconds and Units*
245
- #
246
- # This form accepts an integer number of seconds `sec_i`, a numeric number of
247
- # milliseconds `msec`, a symbol argument for the subsecond unit type (defaulting
248
- # to :usec), and an optional keyword argument `in`:
249
- #
250
- # Time.at(946702800, 500, :millisecond) # => 1999-12-31 23:00:00.5 -0600
251
- # Time.at(946702800, 500, :millisecond, in: '+09:00') # => 2000-01-01 14:00:00.5 +0900
252
- # Time.at(946702800, 500000) # => 1999-12-31 23:00:00.5 -0600
253
- # Time.at(946702800, 500000, :usec) # => 1999-12-31 23:00:00.5 -0600
254
- # Time.at(946702800, 500000, :microsecond) # => 1999-12-31 23:00:00.5 -0600
255
- # Time.at(946702800, 500000, in: '+09:00') # => 2000-01-01 14:00:00.5 +0900
256
- # Time.at(946702800, 500000, :usec, in: '+09:00') # => 2000-01-01 14:00:00.5 +0900
257
- # Time.at(946702800, 500000, :microsecond, in: '+09:00') # => 2000-01-01 14:00:00.5 +0900
258
- # Time.at(946702800, 500000000, :nsec) # => 1999-12-31 23:00:00.5 -0600
259
- # Time.at(946702800, 500000000, :nanosecond) # => 1999-12-31 23:00:00.5 -0600
260
- # Time.at(946702800, 500000000, :nsec, in: '+09:00') # => 2000-01-01 14:00:00.5 +0900
261
- # Time.at(946702800, 500000000, :nanosecond, in: '+09:00') # => 2000-01-01 14:00:00.5 +0900
262
- #
263
- # Parameters:
264
- # * `isec_i` is the integer number of seconds in the range `0..60`.
265
- # * `msec` is the number of milliseconds (Integer, Float, or Rational) in the
266
- # range `0..1000`.
267
- # * `usec` is the number of microseconds (Integer, Float, or Rational) in the
268
- # range `0..1000000`.
269
- # * `nsec` is the number of nanoseconds (Integer, Float, or Rational) in the
270
- # range `0..1000000000`.
271
- # * `in: zone`: a timezone *zone*, which may be:
272
- # * A string offset from UTC.
273
- # * A single letter offset from UTC, in the range `'A'..'Z'`, `'J'` (the
274
- # so-called military timezone) excluded.
275
- # * An integer number of seconds.
276
- # * A timezone object; see [Timezone
277
- # Argument](#class-Time-label-Timezone+Argument) for details.
464
+ # Returns a new `Time` object based on the given arguments.
465
+ #
466
+ # Required argument `time` may be either of:
467
+ #
468
+ # * A `Time` object, whose value is the basis for the returned time; also
469
+ # influenced by optional keyword argument `in:` (see below).
470
+ # * A numeric number of [Epoch seconds](rdoc-ref:Time@Epoch+Seconds) for the
471
+ # returned time.
472
+ #
473
+ # Examples:
474
+ #
475
+ # t = Time.new(2000, 12, 31, 23, 59, 59) # => 2000-12-31 23:59:59 -0600
476
+ # secs = t.to_i # => 978328799
477
+ # Time.at(secs) # => 2000-12-31 23:59:59 -0600
478
+ # Time.at(secs + 0.5) # => 2000-12-31 23:59:59.5 -0600
479
+ # Time.at(1000000000) # => 2001-09-08 20:46:40 -0500
480
+ # Time.at(0) # => 1969-12-31 18:00:00 -0600
481
+ # Time.at(-1000000000) # => 1938-04-24 17:13:20 -0500
482
+ #
483
+ # Optional numeric argument `subsec` and optional symbol argument `units` work
484
+ # together to specify subseconds for the returned time; argument `units`
485
+ # specifies the units for `subsec`:
486
+ #
487
+ # * `:millisecond`: `subsec` in milliseconds:
488
+ #
489
+ # Time.at(secs, 0, :millisecond) # => 2000-12-31 23:59:59 -0600
490
+ # Time.at(secs, 500, :millisecond) # => 2000-12-31 23:59:59.5 -0600
491
+ # Time.at(secs, 1000, :millisecond) # => 2001-01-01 00:00:00 -0600
492
+ # Time.at(secs, -1000, :millisecond) # => 2000-12-31 23:59:58 -0600
493
+ #
494
+ # * `:microsecond` or `:usec`: `subsec` in microseconds:
495
+ #
496
+ # Time.at(secs, 0, :microsecond) # => 2000-12-31 23:59:59 -0600
497
+ # Time.at(secs, 500000, :microsecond) # => 2000-12-31 23:59:59.5 -0600
498
+ # Time.at(secs, 1000000, :microsecond) # => 2001-01-01 00:00:00 -0600
499
+ # Time.at(secs, -1000000, :microsecond) # => 2000-12-31 23:59:58 -0600
500
+ #
501
+ # * `:nanosecond` or `:nsec`: `subsec` in nanoseconds:
502
+ #
503
+ # Time.at(secs, 0, :nanosecond) # => 2000-12-31 23:59:59 -0600
504
+ # Time.at(secs, 500000000, :nanosecond) # => 2000-12-31 23:59:59.5 -0600
505
+ # Time.at(secs, 1000000000, :nanosecond) # => 2001-01-01 00:00:00 -0600
506
+ # Time.at(secs, -1000000000, :nanosecond) # => 2000-12-31 23:59:58 -0600
507
+ #
508
+ # Optional keyword argument `in: zone` specifies the timezone for the returned
509
+ # time:
510
+ #
511
+ # Time.at(secs, in: '+12:00') # => 2001-01-01 17:59:59 +1200
512
+ # Time.at(secs, in: '-12:00') # => 2000-12-31 17:59:59 -1200
513
+ #
514
+ # For the forms of argument `zone`, see [Timezone
515
+ # Specifiers](rdoc-ref:Time@Timezone+Specifiers).
278
516
  #
279
517
  def self.at: (Time, ?in: String | Integer | nil) -> Time
280
518
  | (Numeric, ?in: String | Integer | nil) -> Time
@@ -282,60 +520,114 @@ class Time < Object
282
520
 
283
521
  type subsec_unit = :msec | :millisecond | :usec | :microsecond | :nsec | :nanosecond
284
522
 
285
- # Creates a Time object based on given values, interpreted as UTC (GMT). The
286
- # year must be specified. Other values default to the minimum value for that
287
- # field (and may be `nil` or omitted). Months may be specified by numbers from 1
288
- # to 12, or by the three-letter English month names. Hours are specified on a
289
- # 24-hour clock (0..23). Raises an ArgumentError if any values are out of range.
290
- # Will also accept ten arguments in the order output by Time#to_a.
523
+ # <!-- rdoc-file=time.c -->
524
+ # Returns a new `Time` object based the on given arguments, in the UTC timezone.
291
525
  #
292
- # `sec_with_frac` and `usec_with_frac` can have a fractional part.
526
+ # With one to seven arguments given, the arguments are interpreted as in the
527
+ # first calling sequence above:
293
528
  #
294
- # Time.utc(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 UTC
295
- # Time.gm(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 UTC
529
+ # Time.utc(year, month = 1, mday = 1, hour = 0, min = 0, sec = 0, usec = 0)
296
530
  #
297
- def self.gm: (Integer year, ?Integer | String month, ?Integer day, ?Integer hour, ?Integer min, ?Numeric sec, ?Numeric usec_with_frac) -> Time
298
-
299
- # <!--
300
- # rdoc-file=time.c
301
- # - Time.local(year, month=1, day=1, hour=0, min=0, sec_i=0, usec=0) -> new_time
302
- # - Time.local(sec, min, hour, day, month, year, dummy, dummy, dummy, dummy) -> new_time
303
- # -->
304
- # Returns a new Time object based the on given arguments; its timezone is the
305
- # local timezone.
531
+ # Examples:
306
532
  #
307
- # In the first form (up to seven arguments), argument `year` is required.
533
+ # Time.utc(2000) # => 2000-01-01 00:00:00 UTC
534
+ # Time.utc(-2000) # => -2000-01-01 00:00:00 UTC
308
535
  #
309
- # Time.local(2000) # => 2000-01-01 00:00:00 -0600
310
- # Time.local(0, 1, 2, 3, 4, 5, 6.5) # => 0000-01-02 03:04:05.0000065 -0600
536
+ # There are no minimum and maximum values for the required argument `year`.
311
537
  #
312
- # In the second form, all ten arguments are required, though the last four are
313
- # ignored. This form is useful for creating a time from a 10-element array such
314
- # as those returned by #to_a.
538
+ # For the optional arguments:
315
539
  #
316
- # array = Time.now.to_a
317
- # p array # => [57, 26, 13, 24, 4, 2021, 6, 114, true, "Central Daylight Time"]
318
- # array[5] = 2000
319
- # Time.local(*array) # => 2000-04-24 13:26:57 -0500
540
+ # * `month`: Month in range (1..12), or case-insensitive 3-letter month name:
320
541
  #
321
- # Parameters:
322
- # * `year`: an integer year.
323
- # * `month`: a month value, which may be:
324
- # * An integer month in the range `1..12`.
325
- # * A 3-character string that matches regular expression
326
- # `/jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec/i`.
542
+ # Time.utc(2000, 1) # => 2000-01-01 00:00:00 UTC
543
+ # Time.utc(2000, 12) # => 2000-12-01 00:00:00 UTC
544
+ # Time.utc(2000, 'jan') # => 2000-01-01 00:00:00 UTC
545
+ # Time.utc(2000, 'JAN') # => 2000-01-01 00:00:00 UTC
327
546
  #
328
- # * `day`: an integer day in the range `1..31` (less than 31 for some months).
329
- # * `hour`: an integer hour in the range `0..23`.
330
- # * `min`: an integer minute in the range `0..59`.
331
- # * `isec_i` is the integer number of seconds in the range `0..60`.
332
- # * `usec` is the number of microseconds (Integer, Float, or Rational) in the
333
- # range `0..1000000`.
547
+ # * `mday`: Month day in range(1..31):
334
548
  #
549
+ # Time.utc(2000, 1, 1) # => 2000-01-01 00:00:00 UTC
550
+ # Time.utc(2000, 1, 31) # => 2000-01-31 00:00:00 UTC
335
551
  #
336
- # Alias: Time.mktime.
552
+ # * `hour`: Hour in range (0..23), or 24 if `min`, `sec`, and `usec` are zero:
337
553
  #
338
- # Related: Time.utc.
554
+ # Time.utc(2000, 1, 1, 0) # => 2000-01-01 00:00:00 UTC
555
+ # Time.utc(2000, 1, 1, 23) # => 2000-01-01 23:00:00 UTC
556
+ # Time.utc(2000, 1, 1, 24) # => 2000-01-02 00:00:00 UTC
557
+ #
558
+ # * `min`: Minute in range (0..59):
559
+ #
560
+ # Time.utc(2000, 1, 1, 0, 0) # => 2000-01-01 00:00:00 UTC
561
+ # Time.utc(2000, 1, 1, 0, 59) # => 2000-01-01 00:59:00 UTC
562
+ #
563
+ # * `sec`: Second in range (0..59), or 60 if `usec` is zero:
564
+ #
565
+ # Time.utc(2000, 1, 1, 0, 0, 0) # => 2000-01-01 00:00:00 UTC
566
+ # Time.utc(2000, 1, 1, 0, 0, 59) # => 2000-01-01 00:00:59 UTC
567
+ # Time.utc(2000, 1, 1, 0, 0, 60) # => 2000-01-01 00:01:00 UTC
568
+ #
569
+ # * `usec`: Microsecond in range (0..999999):
570
+ #
571
+ # Time.utc(2000, 1, 1, 0, 0, 0, 0) # => 2000-01-01 00:00:00 UTC
572
+ # Time.utc(2000, 1, 1, 0, 0, 0, 999999) # => 2000-01-01 00:00:00.999999 UTC
573
+ #
574
+ # The values may be:
575
+ #
576
+ # * Integers, as above.
577
+ # * Numerics convertible to integers:
578
+ #
579
+ # Time.utc(Float(0.0), Rational(1, 1), 1.0, 0.0, 0.0, 0.0, 0.0)
580
+ # # => 0000-01-01 00:00:00 UTC
581
+ #
582
+ # * String integers:
583
+ #
584
+ # a = %w[0 1 1 0 0 0 0 0]
585
+ # # => ["0", "1", "1", "0", "0", "0", "0", "0"]
586
+ # Time.utc(*a) # => 0000-01-01 00:00:00 UTC
587
+ #
588
+ # When exactly ten arguments are given, the arguments are interpreted as in the
589
+ # second calling sequence above:
590
+ #
591
+ # Time.utc(sec, min, hour, mday, month, year, dummy, dummy, dummy, dummy)
592
+ #
593
+ # where the `dummy` arguments are ignored:
594
+ #
595
+ # a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
596
+ # # => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
597
+ # Time.utc(*a) # => 0005-04-03 02:01:00 UTC
598
+ #
599
+ # This form is useful for creating a `Time` object from a 10-element array
600
+ # returned by Time.to_a:
601
+ #
602
+ # t = Time.new(2000, 1, 2, 3, 4, 5, 6) # => 2000-01-02 03:04:05 +000006
603
+ # a = t.to_a # => [5, 4, 3, 2, 1, 2000, 0, 2, false, nil]
604
+ # Time.utc(*a) # => 2000-01-02 03:04:05 UTC
605
+ #
606
+ # The two forms have their first six arguments in common, though in different
607
+ # orders; the ranges of these common arguments are the same for both forms; see
608
+ # above.
609
+ #
610
+ # Raises an exception if the number of arguments is eight, nine, or greater than
611
+ # ten.
612
+ #
613
+ # Related: Time.local.
614
+ #
615
+ def self.gm: (Integer year, ?Integer | String month, ?Integer day, ?Integer hour, ?Integer min, ?Numeric sec, ?Numeric usec_with_frac) -> Time
616
+
617
+ # <!--
618
+ # rdoc-file=time.c
619
+ # - Time.local(year, month = 1, mday = 1, hour = 0, min = 0, sec = 0, usec = 0) -> new_time
620
+ # - Time.local(sec, min, hour, mday, month, year, dummy, dummy, dummy, dummy) -> new_time
621
+ # -->
622
+ # Like Time.utc, except that the returned `Time` object has the local timezone,
623
+ # not the UTC timezone:
624
+ #
625
+ # # With seven arguments.
626
+ # Time.local(0, 1, 2, 3, 4, 5, 6)
627
+ # # => 0000-01-02 03:04:05.000006 -0600
628
+ # # With exactly ten arguments.
629
+ # Time.local(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
630
+ # # => 0005-04-03 02:01:00 -0600
339
631
  #
340
632
  def self.local: (Integer year, ?Integer | String month, ?Integer day, ?Integer hour, ?Integer min, ?Numeric sec, ?Numeric usec_with_frac) -> Time
341
633
 
@@ -343,60 +635,110 @@ class Time < Object
343
635
  # rdoc-file=timev.rb
344
636
  # - now(in: nil)
345
637
  # -->
346
- # Creates a new Time object from the current system time. This is the same as
638
+ # Creates a new `Time` object from the current system time. This is the same as
347
639
  # Time.new without arguments.
348
640
  #
349
641
  # Time.now # => 2009-06-24 12:39:54 +0900
350
642
  # Time.now(in: '+04:00') # => 2009-06-24 07:39:54 +0400
351
643
  #
352
- # Parameter:
353
- # * `in: zone`: a timezone *zone*, which may be:
354
- # * A string offset from UTC.
355
- # * A single letter offset from UTC, in the range `'A'..'Z'`, `'J'` (the
356
- # so-called military timezone) excluded.
357
- # * An integer number of seconds.
358
- # * A timezone object; see [Timezone
359
- # Argument](#class-Time-label-Timezone+Argument) for details.
644
+ # For forms of argument `zone`, see [Timezone
645
+ # Specifiers](rdoc-ref:Time@Timezone+Specifiers).
360
646
  #
361
647
  def self.now: (?in: String | Integer | nil) -> Time
362
648
 
363
649
  # <!--
364
650
  # rdoc-file=time.c
365
- # - Time.utc(year, month=1, day=1, hour=0, min=0, sec_i=0, usec=0) -> new_time
366
- # - Time.utc(sec_i, min, hour, day, month, year, dummy, dummy, dummy, dummy) -> new_time
651
+ # - Time.utc(year, month = 1, mday = 1, hour = 0, min = 0, sec = 0, usec = 0) -> new_time
652
+ # - Time.utc(sec, min, hour, mday, month, year, dummy, dummy, dummy, dummy) -> new_time
367
653
  # -->
368
- # Returns a new Time object based the on given arguments; its timezone is UTC.
654
+ # Returns a new `Time` object based the on given arguments, in the UTC timezone.
655
+ #
656
+ # With one to seven arguments given, the arguments are interpreted as in the
657
+ # first calling sequence above:
658
+ #
659
+ # Time.utc(year, month = 1, mday = 1, hour = 0, min = 0, sec = 0, usec = 0)
369
660
  #
370
- # In the first form (up to seven arguments), argument `year` is required.
661
+ # Examples:
662
+ #
663
+ # Time.utc(2000) # => 2000-01-01 00:00:00 UTC
664
+ # Time.utc(-2000) # => -2000-01-01 00:00:00 UTC
665
+ #
666
+ # There are no minimum and maximum values for the required argument `year`.
667
+ #
668
+ # For the optional arguments:
669
+ #
670
+ # * `month`: Month in range (1..12), or case-insensitive 3-letter month name:
671
+ #
672
+ # Time.utc(2000, 1) # => 2000-01-01 00:00:00 UTC
673
+ # Time.utc(2000, 12) # => 2000-12-01 00:00:00 UTC
674
+ # Time.utc(2000, 'jan') # => 2000-01-01 00:00:00 UTC
675
+ # Time.utc(2000, 'JAN') # => 2000-01-01 00:00:00 UTC
676
+ #
677
+ # * `mday`: Month day in range(1..31):
678
+ #
679
+ # Time.utc(2000, 1, 1) # => 2000-01-01 00:00:00 UTC
680
+ # Time.utc(2000, 1, 31) # => 2000-01-31 00:00:00 UTC
681
+ #
682
+ # * `hour`: Hour in range (0..23), or 24 if `min`, `sec`, and `usec` are zero:
683
+ #
684
+ # Time.utc(2000, 1, 1, 0) # => 2000-01-01 00:00:00 UTC
685
+ # Time.utc(2000, 1, 1, 23) # => 2000-01-01 23:00:00 UTC
686
+ # Time.utc(2000, 1, 1, 24) # => 2000-01-02 00:00:00 UTC
687
+ #
688
+ # * `min`: Minute in range (0..59):
689
+ #
690
+ # Time.utc(2000, 1, 1, 0, 0) # => 2000-01-01 00:00:00 UTC
691
+ # Time.utc(2000, 1, 1, 0, 59) # => 2000-01-01 00:59:00 UTC
692
+ #
693
+ # * `sec`: Second in range (0..59), or 60 if `usec` is zero:
694
+ #
695
+ # Time.utc(2000, 1, 1, 0, 0, 0) # => 2000-01-01 00:00:00 UTC
696
+ # Time.utc(2000, 1, 1, 0, 0, 59) # => 2000-01-01 00:00:59 UTC
697
+ # Time.utc(2000, 1, 1, 0, 0, 60) # => 2000-01-01 00:01:00 UTC
698
+ #
699
+ # * `usec`: Microsecond in range (0..999999):
700
+ #
701
+ # Time.utc(2000, 1, 1, 0, 0, 0, 0) # => 2000-01-01 00:00:00 UTC
702
+ # Time.utc(2000, 1, 1, 0, 0, 0, 999999) # => 2000-01-01 00:00:00.999999 UTC
703
+ #
704
+ # The values may be:
371
705
  #
372
- # Time.utc(2000) # => 2000-01-01 00:00:00 UTC
373
- # Time.utc(0, 1, 2, 3, 4, 5, 6.5) # => 0000-01-02 03:04:05.0000065 UTC
706
+ # * Integers, as above.
707
+ # * Numerics convertible to integers:
374
708
  #
375
- # In the second form, all ten arguments are required, though the last four are
376
- # ignored. This form is useful for creating a time from a 10-element array such
377
- # as is returned by #to_a.
709
+ # Time.utc(Float(0.0), Rational(1, 1), 1.0, 0.0, 0.0, 0.0, 0.0)
710
+ # # => 0000-01-01 00:00:00 UTC
378
711
  #
379
- # array = Time.now.to_a
380
- # p array # => [57, 26, 13, 24, 4, 2021, 6, 114, true, "Central Daylight Time"]
381
- # array[5] = 2000
382
- # Time.utc(*array) # => 2000-04-24 13:26:57 UTC
712
+ # * String integers:
383
713
  #
384
- # Parameters:
385
- # * `year`: an integer year.
386
- # * `month`: a month value, which may be:
387
- # * An integer month in the range `1..12`.
388
- # * A 3-character string that matches regular expression
389
- # `/jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec/i`.
714
+ # a = %w[0 1 1 0 0 0 0 0]
715
+ # # => ["0", "1", "1", "0", "0", "0", "0", "0"]
716
+ # Time.utc(*a) # => 0000-01-01 00:00:00 UTC
390
717
  #
391
- # * `day`: an integer day in the range `1..31` (less than 31 for some months).
392
- # * `hour`: an integer hour in the range `0..23`.
393
- # * `min`: an integer minute in the range `0..59`.
394
- # * `isec_i` is the integer number of seconds in the range `0..60`.
395
- # * `usec` is the number of microseconds (Integer, Float, or Rational) in the
396
- # range `0..1000000`.
718
+ # When exactly ten arguments are given, the arguments are interpreted as in the
719
+ # second calling sequence above:
397
720
  #
721
+ # Time.utc(sec, min, hour, mday, month, year, dummy, dummy, dummy, dummy)
398
722
  #
399
- # Alias: Time.gm.
723
+ # where the `dummy` arguments are ignored:
724
+ #
725
+ # a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
726
+ # # => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
727
+ # Time.utc(*a) # => 0005-04-03 02:01:00 UTC
728
+ #
729
+ # This form is useful for creating a `Time` object from a 10-element array
730
+ # returned by Time.to_a:
731
+ #
732
+ # t = Time.new(2000, 1, 2, 3, 4, 5, 6) # => 2000-01-02 03:04:05 +000006
733
+ # a = t.to_a # => [5, 4, 3, 2, 1, 2000, 0, 2, false, nil]
734
+ # Time.utc(*a) # => 2000-01-02 03:04:05 UTC
735
+ #
736
+ # The two forms have their first six arguments in common, though in different
737
+ # orders; the ranges of these common arguments are the same for both forms; see
738
+ # above.
739
+ #
740
+ # Raises an exception if the number of arguments is eight, nine, or greater than
741
+ # ten.
400
742
  #
401
743
  # Related: Time.local.
402
744
  #
@@ -404,28 +746,37 @@ class Time < Object
404
746
 
405
747
  # <!--
406
748
  # rdoc-file=time.c
407
- # - time + numeric -> time
749
+ # - self + numeric -> new_time
408
750
  # -->
409
- # Adds some number of seconds (possibly including subsecond) to *time* and
410
- # returns that value as a new Time object.
751
+ # Returns a new `Time` object whose value is the sum of the numeric value of
752
+ # `self` and the given `numeric`:
753
+ #
754
+ # t = Time.new(2000) # => 2000-01-01 00:00:00 -0600
755
+ # t + (60 * 60 * 24) # => 2000-01-02 00:00:00 -0600
756
+ # t + 0.5 # => 2000-01-01 00:00:00.5 -0600
411
757
  #
412
- # t = Time.now #=> 2020-07-20 22:14:43.170490982 +0900
413
- # t + (60 * 60 * 24) #=> 2020-07-21 22:14:43.170490982 +0900
758
+ # Related: Time#-.
414
759
  #
415
760
  def +: (Numeric arg0) -> Time
416
761
 
417
762
  # <!--
418
763
  # rdoc-file=time.c
419
- # - time - other_time -> float
420
- # - time - numeric -> time
764
+ # - self - numeric -> new_time
765
+ # - self - other_time -> float
421
766
  # -->
422
- # Returns a difference in seconds as a Float between *time* and `other_time`, or
423
- # subtracts the given number of seconds in `numeric` from *time*.
767
+ # When `numeric` is given, returns a new `Time` object whose value is the
768
+ # difference of the numeric value of `self` and `numeric`:
769
+ #
770
+ # t = Time.new(2000) # => 2000-01-01 00:00:00 -0600
771
+ # t - (60 * 60 * 24) # => 1999-12-31 00:00:00 -0600
772
+ # t - 0.5 # => 1999-12-31 23:59:59.5 -0600
773
+ #
774
+ # When `other_time` is given, returns a Float whose value is the difference of
775
+ # the numeric values of `self` and `other_time` in seconds:
424
776
  #
425
- # t = Time.now #=> 2020-07-20 22:15:49.302766336 +0900
426
- # t2 = t + 2592000 #=> 2020-08-19 22:15:49.302766336 +0900
427
- # t2 - t #=> 2592000.0
428
- # t2 - 2592000 #=> 2020-07-20 22:15:49.302766336 +0900
777
+ # t - t # => 0.0
778
+ #
779
+ # Related: Time#+.
429
780
  #
430
781
  def -: (Time arg0) -> Float
431
782
  | (Numeric arg0) -> Time
@@ -436,27 +787,29 @@ class Time < Object
436
787
 
437
788
  # <!--
438
789
  # rdoc-file=time.c
439
- # - time <=> other_time -> -1, 0, +1, or nil
790
+ # - self <=> other_time -> -1, 0, +1, or nil
440
791
  # -->
441
- # Compares `time` with `other_time`.
792
+ # Compares `self` with `other_time`; returns:
442
793
  #
443
- # -1, 0, +1 or nil depending on whether `time` is less than, equal to, or
444
- # greater than `other_time`.
794
+ # * `-1`, if `self` is less than `other_time`.
795
+ # * `0`, if `self` is equal to `other_time`.
796
+ # * `1`, if `self` is greater then `other_time`.
797
+ # * `nil`, if `self` and `other_time` are incomparable.
445
798
  #
446
- # `nil` is returned if the two values are incomparable.
799
+ # Examples:
447
800
  #
448
- # t = Time.now #=> 2007-11-19 08:12:12 -0600
449
- # t2 = t + 2592000 #=> 2007-12-19 08:12:12 -0600
450
- # t <=> t2 #=> -1
451
- # t2 <=> t #=> 1
801
+ # t = Time.now # => 2007-11-19 08:12:12 -0600
802
+ # t2 = t + 2592000 # => 2007-12-19 08:12:12 -0600
803
+ # t <=> t2 # => -1
804
+ # t2 <=> t # => 1
452
805
  #
453
- # t = Time.now #=> 2007-11-19 08:13:38 -0600
454
- # t2 = t + 0.1 #=> 2007-11-19 08:13:38 -0600
455
- # t.nsec #=> 98222999
456
- # t2.nsec #=> 198222999
457
- # t <=> t2 #=> -1
458
- # t2 <=> t #=> 1
459
- # t <=> t #=> 0
806
+ # t = Time.now # => 2007-11-19 08:13:38 -0600
807
+ # t2 = t + 0.1 # => 2007-11-19 08:13:38 -0600
808
+ # t.nsec # => 98222999
809
+ # t2.nsec # => 198222999
810
+ # t <=> t2 # => -1
811
+ # t2 <=> t # => 1
812
+ # t <=> t # => 0
460
813
  #
461
814
  def <=>: (Time other) -> Integer
462
815
  | (untyped other) -> Integer?
@@ -466,895 +819,840 @@ class Time < Object
466
819
  def >=: (Time arg0) -> bool
467
820
 
468
821
  # <!-- rdoc-file=time.c -->
469
- # Returns a canonical string representation of *time*.
822
+ # Returns a string representation of `self`, formatted by `strftime('%a %b %e %T
823
+ # %Y')` or its shorthand version `strftime('%c')`; see [Formats for Dates and
824
+ # Times](rdoc-ref:strftime_formatting.rdoc):
825
+ #
826
+ # t = Time.new(2000, 12, 31, 23, 59, 59, 0.5)
827
+ # t.ctime # => "Sun Dec 31 23:59:59 2000"
828
+ # t.strftime('%a %b %e %T %Y') # => "Sun Dec 31 23:59:59 2000"
829
+ # t.strftime('%c') # => "Sun Dec 31 23:59:59 2000"
830
+ #
831
+ # Related: Time#to_s, Time#inspect:
470
832
  #
471
- # Time.now.asctime #=> "Wed Apr 9 08:56:03 2003"
472
- # Time.now.ctime #=> "Wed Apr 9 08:56:03 2003"
833
+ # t.inspect # => "2000-12-31 23:59:59.5 +000001"
834
+ # t.to_s # => "2000-12-31 23:59:59 +0000"
473
835
  #
474
836
  def asctime: () -> String
475
837
 
476
838
  # <!--
477
839
  # rdoc-file=time.c
478
- # - time.asctime -> string
479
- # - time.ctime -> string
840
+ # - ctime -> string
480
841
  # -->
481
- # Returns a canonical string representation of *time*.
842
+ # Returns a string representation of `self`, formatted by `strftime('%a %b %e %T
843
+ # %Y')` or its shorthand version `strftime('%c')`; see [Formats for Dates and
844
+ # Times](rdoc-ref:strftime_formatting.rdoc):
482
845
  #
483
- # Time.now.asctime #=> "Wed Apr 9 08:56:03 2003"
484
- # Time.now.ctime #=> "Wed Apr 9 08:56:03 2003"
846
+ # t = Time.new(2000, 12, 31, 23, 59, 59, 0.5)
847
+ # t.ctime # => "Sun Dec 31 23:59:59 2000"
848
+ # t.strftime('%a %b %e %T %Y') # => "Sun Dec 31 23:59:59 2000"
849
+ # t.strftime('%c') # => "Sun Dec 31 23:59:59 2000"
850
+ #
851
+ # Related: Time#to_s, Time#inspect:
852
+ #
853
+ # t.inspect # => "2000-12-31 23:59:59.5 +000001"
854
+ # t.to_s # => "2000-12-31 23:59:59 +0000"
485
855
  #
486
856
  def ctime: () -> String
487
857
 
488
858
  # <!-- rdoc-file=time.c -->
489
- # Returns the day of the month (1..31) for *time*.
859
+ # Returns the integer day of the month for `self`, in range (1..31):
490
860
  #
491
- # t = Time.now #=> 2007-11-19 08:27:03 -0600
492
- # t.day #=> 19
493
- # t.mday #=> 19
861
+ # t = Time.new(2000, 1, 2, 3, 4, 5, 6)
862
+ # # => 2000-01-02 03:04:05 +000006
863
+ # t.mday # => 2
864
+ #
865
+ # Related: Time#year, Time#hour, Time#min.
494
866
  #
495
867
  def day: () -> Integer
496
868
 
869
+ # <!--
870
+ # rdoc-file=time.c
871
+ # - deconstruct_keys(array_of_names_or_nil) -> hash
872
+ # -->
873
+ # Returns a hash of the name/value pairs, to use in pattern matching. Possible
874
+ # keys are: `:year`, `:month`, `:day`, `:yday`, `:wday`, `:hour`, `:min`,
875
+ # `:sec`, `:subsec`, `:dst`, `:zone`.
876
+ #
877
+ # Possible usages:
878
+ #
879
+ # t = Time.utc(2022, 10, 5, 21, 25, 30)
880
+ #
881
+ # if t in wday: 3, day: ..7 # uses deconstruct_keys underneath
882
+ # puts "first Wednesday of the month"
883
+ # end
884
+ # #=> prints "first Wednesday of the month"
885
+ #
886
+ # case t
887
+ # in year: ...2022
888
+ # puts "too old"
889
+ # in month: ..9
890
+ # puts "quarter 1-3"
891
+ # in wday: 1..5, month:
892
+ # puts "working day in month #{month}"
893
+ # end
894
+ # #=> prints "working day in month 10"
895
+ #
896
+ # Note that deconstruction by pattern can also be combined with class check:
897
+ #
898
+ # if t in Time(wday: 3, day: ..7)
899
+ # puts "first Wednesday of the month"
900
+ # end
901
+ #
902
+ def deconstruct_keys: (Array[Symbol]?) -> Hash[Symbol, Integer]
903
+
497
904
  # <!-- rdoc-file=time.c -->
498
- # Returns `true` if *time* occurs during Daylight Saving Time in its time zone.
499
- #
500
- # # CST6CDT:
501
- # Time.local(2000, 1, 1).zone #=> "CST"
502
- # Time.local(2000, 1, 1).isdst #=> false
503
- # Time.local(2000, 1, 1).dst? #=> false
504
- # Time.local(2000, 7, 1).zone #=> "CDT"
505
- # Time.local(2000, 7, 1).isdst #=> true
506
- # Time.local(2000, 7, 1).dst? #=> true
507
- #
508
- # # Asia/Tokyo:
509
- # Time.local(2000, 1, 1).zone #=> "JST"
510
- # Time.local(2000, 1, 1).isdst #=> false
511
- # Time.local(2000, 1, 1).dst? #=> false
512
- # Time.local(2000, 7, 1).zone #=> "JST"
513
- # Time.local(2000, 7, 1).isdst #=> false
514
- # Time.local(2000, 7, 1).dst? #=> false
905
+ # Returns `true` if `self` is in daylight saving time, `false` otherwise:
906
+ #
907
+ # t = Time.local(2000, 1, 1) # => 2000-01-01 00:00:00 -0600
908
+ # t.zone # => "Central Standard Time"
909
+ # t.dst? # => false
910
+ # t = Time.local(2000, 7, 1) # => 2000-07-01 00:00:00 -0500
911
+ # t.zone # => "Central Daylight Time"
912
+ # t.dst? # => true
515
913
  #
516
914
  def dst?: () -> bool
517
915
 
518
916
  # <!--
519
917
  # rdoc-file=time.c
520
- # - time.eql?(other_time)
918
+ # - eql?(other_time)
521
919
  # -->
522
- # Returns `true` if *time* and `other_time` are both Time objects with the same
523
- # seconds (including subsecond) from the Epoch.
920
+ # Returns `true` if `self` and `other_time` are both `Time` objects with the
921
+ # exact same time value.
524
922
  #
525
923
  def eql?: (untyped arg0) -> bool
526
924
 
527
925
  # <!--
528
926
  # rdoc-file=time.c
529
- # - time.friday? -> true or false
927
+ # - friday? -> true or false
530
928
  # -->
531
- # Returns `true` if *time* represents Friday.
929
+ # Returns `true` if `self` represents a Friday, `false` otherwise:
930
+ #
931
+ # t = Time.utc(2000, 1, 7) # => 2000-01-07 00:00:00 UTC
932
+ # t.friday? # => true
532
933
  #
533
- # t = Time.local(1987, 12, 18) #=> 1987-12-18 00:00:00 -0600
534
- # t.friday? #=> true
934
+ # Related: Time#saturday?, Time#sunday?, Time#monday?.
535
935
  #
536
936
  def friday?: () -> bool
537
937
 
538
938
  # <!--
539
939
  # rdoc-file=time.c
540
- # - time.getgm -> new_time
541
- # - time.getutc -> new_time
940
+ # - getutc -> new_time
542
941
  # -->
543
- # Returns a new Time object representing *time* in UTC.
942
+ # Returns a new `Time` object representing the value of `self` converted to the
943
+ # UTC timezone:
544
944
  #
545
- # t = Time.local(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 -0600
546
- # t.gmt? #=> false
547
- # y = t.getgm #=> 2000-01-02 02:15:01 UTC
548
- # y.gmt? #=> true
549
- # t == y #=> true
945
+ # local = Time.local(2000) # => 2000-01-01 00:00:00 -0600
946
+ # local.utc? # => false
947
+ # utc = local.getutc # => 2000-01-01 06:00:00 UTC
948
+ # utc.utc? # => true
949
+ # utc == local # => true
550
950
  #
551
951
  def getgm: () -> Time
552
952
 
553
953
  # <!--
554
954
  # rdoc-file=time.c
555
- # - time.getlocal -> new_time
556
- # - time.getlocal(utc_offset) -> new_time
557
- # - time.getlocal(timezone) -> new_time
955
+ # - getlocal(zone = nil) -> new_time
558
956
  # -->
559
- # Returns a new Time object representing *time* in local time (using the local
560
- # time zone in effect for this process).
957
+ # Returns a new `Time` object representing the value of `self` converted to a
958
+ # given timezone; if `zone` is `nil`, the local timezone is used:
561
959
  #
562
- # If `utc_offset` is given, it is used instead of the local time. `utc_offset`
563
- # can be given as a human-readable string (eg. `"+09:00"`) or as a number of
564
- # seconds (eg. `32400`).
960
+ # t = Time.utc(2000) # => 2000-01-01 00:00:00 UTC
961
+ # t.getlocal # => 1999-12-31 18:00:00 -0600
962
+ # t.getlocal('+12:00') # => 2000-01-01 12:00:00 +1200
565
963
  #
566
- # t = Time.utc(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 UTC
567
- # t.utc? #=> true
568
- #
569
- # l = t.getlocal #=> 2000-01-01 14:15:01 -0600
570
- # l.utc? #=> false
571
- # t == l #=> true
572
- #
573
- # j = t.getlocal("+09:00") #=> 2000-01-02 05:15:01 +0900
574
- # j.utc? #=> false
575
- # t == j #=> true
576
- #
577
- # k = t.getlocal(9*60*60) #=> 2000-01-02 05:15:01 +0900
578
- # k.utc? #=> false
579
- # t == k #=> true
964
+ # For forms of argument `zone`, see [Timezone
965
+ # Specifiers](rdoc-ref:Time@Timezone+Specifiers).
580
966
  #
581
967
  def getlocal: (?Integer utc_offset) -> Time
582
968
 
583
969
  # <!-- rdoc-file=time.c -->
584
- # Returns a new Time object representing *time* in UTC.
970
+ # Returns a new `Time` object representing the value of `self` converted to the
971
+ # UTC timezone:
585
972
  #
586
- # t = Time.local(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 -0600
587
- # t.gmt? #=> false
588
- # y = t.getgm #=> 2000-01-02 02:15:01 UTC
589
- # y.gmt? #=> true
590
- # t == y #=> true
973
+ # local = Time.local(2000) # => 2000-01-01 00:00:00 -0600
974
+ # local.utc? # => false
975
+ # utc = local.getutc # => 2000-01-01 06:00:00 UTC
976
+ # utc.utc? # => true
977
+ # utc == local # => true
591
978
  #
592
979
  def getutc: () -> Time
593
980
 
594
981
  # <!-- rdoc-file=time.c -->
595
- # Returns `true` if *time* represents a time in UTC (GMT).
982
+ # Returns `true` if `self` represents a time in UTC (GMT):
596
983
  #
597
- # t = Time.now #=> 2007-11-19 08:15:23 -0600
598
- # t.utc? #=> false
599
- # t = Time.gm(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 UTC
600
- # t.utc? #=> true
984
+ # now = Time.now
985
+ # # => 2022-08-18 10:24:13.5398485 -0500
986
+ # now.utc? # => false
987
+ # utc = Time.utc(2000, 1, 1, 20, 15, 1)
988
+ # # => 2000-01-01 20:15:01 UTC
989
+ # utc.utc? # => true
601
990
  #
602
- # t = Time.now #=> 2007-11-19 08:16:03 -0600
603
- # t.gmt? #=> false
604
- # t = Time.gm(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 UTC
605
- # t.gmt? #=> true
991
+ # Related: Time.utc.
606
992
  #
607
993
  def gmt?: () -> bool
608
994
 
609
995
  # <!-- rdoc-file=time.c -->
610
- # Returns the offset in seconds between the timezone of *time* and UTC.
996
+ # Returns the offset in seconds between the timezones of UTC and `self`:
611
997
  #
612
- # t = Time.gm(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 UTC
613
- # t.gmt_offset #=> 0
614
- # l = t.getlocal #=> 2000-01-01 14:15:01 -0600
615
- # l.gmt_offset #=> -21600
998
+ # Time.utc(2000, 1, 1).utc_offset # => 0
999
+ # Time.local(2000, 1, 1).utc_offset # => -21600 # -6*3600, or minus six hours.
616
1000
  #
617
1001
  def gmt_offset: () -> Integer
618
1002
 
619
1003
  # <!--
620
1004
  # rdoc-file=time.c
621
- # - time.gmtime -> time
622
- # - time.utc -> time
1005
+ # - utc -> self
623
1006
  # -->
624
- # Converts *time* to UTC (GMT), modifying the receiver.
1007
+ # Returns `self`, converted to the UTC timezone:
625
1008
  #
626
- # t = Time.now #=> 2007-11-19 08:18:31 -0600
627
- # t.gmt? #=> false
628
- # t.gmtime #=> 2007-11-19 14:18:31 UTC
629
- # t.gmt? #=> true
1009
+ # t = Time.new(2000) # => 2000-01-01 00:00:00 -0600
1010
+ # t.utc? # => false
1011
+ # t.utc # => 2000-01-01 06:00:00 UTC
1012
+ # t.utc? # => true
630
1013
  #
631
- # t = Time.now #=> 2007-11-19 08:18:51 -0600
632
- # t.utc? #=> false
633
- # t.utc #=> 2007-11-19 14:18:51 UTC
634
- # t.utc? #=> true
1014
+ # Related: Time#getutc (returns a new converted `Time` object).
635
1015
  #
636
1016
  def gmtime: () -> Time
637
1017
 
638
1018
  # <!--
639
1019
  # rdoc-file=time.c
640
- # - time.hash -> integer
1020
+ # - hash -> integer
641
1021
  # -->
642
- # Returns a hash code for this Time object.
1022
+ # Returns the integer hash code for `self`.
643
1023
  #
644
- # See also Object#hash.
1024
+ # Related: Object#hash.
645
1025
  #
646
1026
  def hash: () -> Integer
647
1027
 
648
1028
  # <!--
649
1029
  # rdoc-file=time.c
650
- # - time.hour -> integer
1030
+ # - hour -> integer
651
1031
  # -->
652
- # Returns the hour of the day (0..23) for *time*.
1032
+ # Returns the integer hour of the day for `self`, in range (0..23):
653
1033
  #
654
- # t = Time.now #=> 2007-11-19 08:26:20 -0600
655
- # t.hour #=> 8
1034
+ # t = Time.new(2000, 1, 2, 3, 4, 5, 6)
1035
+ # # => 2000-01-02 03:04:05 +000006
1036
+ # t.hour # => 3
1037
+ #
1038
+ # Related: Time#year, Time#mon, Time#min.
656
1039
  #
657
1040
  def hour: () -> Integer
658
1041
 
659
1042
  # <!--
660
1043
  # rdoc-file=timev.rb
661
- # - new(year = (now = true), mon = nil, mday = nil, hour = nil, min = nil, sec = nil, zone = nil, in: nil)
1044
+ # - Time.new(year = nil, mon = nil, mday = nil, hour = nil, min = nil, sec = nil, zone = nil, in: nil, precision: 9)
662
1045
  # -->
663
- # Returns a new Time object based on the given arguments.
1046
+ # Returns a new `Time` object based on the given arguments, by default in the
1047
+ # local timezone.
664
1048
  #
665
1049
  # With no positional arguments, returns the value of Time.now:
666
1050
  #
667
- # Time.new # => 2021-04-24 17:27:46.0512465 -0500
1051
+ # Time.new # => 2021-04-24 17:27:46.0512465 -0500
1052
+ #
1053
+ # With one string argument that represents a time, returns a new `Time` object
1054
+ # based on the given argument, in the local timezone.
1055
+ #
1056
+ # Time.new('2000-12-31 23:59:59.5') # => 2000-12-31 23:59:59.5 -0600
1057
+ # Time.new('2000-12-31 23:59:59.5 +0900') # => 2000-12-31 23:59:59.5 +0900
1058
+ # Time.new('2000-12-31 23:59:59.5', in: '+0900') # => 2000-12-31 23:59:59.5 +0900
1059
+ # Time.new('2000-12-31 23:59:59.5') # => 2000-12-31 23:59:59.5 -0600
1060
+ # Time.new('2000-12-31 23:59:59.56789', precision: 3) # => 2000-12-31 23:59:59.567 -0600
1061
+ #
1062
+ # With one to six arguments, returns a new `Time` object based on the given
1063
+ # arguments, in the local timezone.
1064
+ #
1065
+ # Time.new(2000, 1, 2, 3, 4, 5) # => 2000-01-02 03:04:05 -0600
1066
+ #
1067
+ # For the positional arguments (other than `zone`):
1068
+ #
1069
+ # * `year`: Year, with no range limits:
1070
+ #
1071
+ # Time.new(999999999) # => 999999999-01-01 00:00:00 -0600
1072
+ # Time.new(-999999999) # => -999999999-01-01 00:00:00 -0600
1073
+ #
1074
+ # * `month`: Month in range (1..12), or case-insensitive 3-letter month name:
1075
+ #
1076
+ # Time.new(2000, 1) # => 2000-01-01 00:00:00 -0600
1077
+ # Time.new(2000, 12) # => 2000-12-01 00:00:00 -0600
1078
+ # Time.new(2000, 'jan') # => 2000-01-01 00:00:00 -0600
1079
+ # Time.new(2000, 'JAN') # => 2000-01-01 00:00:00 -0600
1080
+ #
1081
+ # * `mday`: Month day in range(1..31):
1082
+ #
1083
+ # Time.new(2000, 1, 1) # => 2000-01-01 00:00:00 -0600
1084
+ # Time.new(2000, 1, 31) # => 2000-01-31 00:00:00 -0600
1085
+ #
1086
+ # * `hour`: Hour in range (0..23), or 24 if `min`, `sec`, and `usec` are zero:
1087
+ #
1088
+ # Time.new(2000, 1, 1, 0) # => 2000-01-01 00:00:00 -0600
1089
+ # Time.new(2000, 1, 1, 23) # => 2000-01-01 23:00:00 -0600
1090
+ # Time.new(2000, 1, 1, 24) # => 2000-01-02 00:00:00 -0600
1091
+ #
1092
+ # * `min`: Minute in range (0..59):
668
1093
  #
669
- # Otherwise, returns a new Time object based on the given parameters:
1094
+ # Time.new(2000, 1, 1, 0, 0) # => 2000-01-01 00:00:00 -0600
1095
+ # Time.new(2000, 1, 1, 0, 59) # => 2000-01-01 00:59:00 -0600
670
1096
  #
671
- # Time.new(2000) # => 2000-01-01 00:00:00 -0600
672
- # Time.new(2000, 12, 31, 23, 59, 59.5) # => 2000-12-31 23:59:59.5 -0600
673
- # Time.new(2000, 12, 31, 23, 59, 59.5, '+09:00') # => 2000-12-31 23:59:59.5 +0900
1097
+ # * `sec`: Second in range (0...61):
674
1098
  #
675
- # Parameters:
1099
+ # Time.new(2000, 1, 1, 0, 0, 0) # => 2000-01-01 00:00:00 -0600
1100
+ # Time.new(2000, 1, 1, 0, 0, 59) # => 2000-01-01 00:00:59 -0600
1101
+ # Time.new(2000, 1, 1, 0, 0, 60) # => 2000-01-01 00:01:00 -0600
676
1102
  #
677
- # * `year`: an integer year.
678
- # * `month`: a month value, which may be:
679
- # * An integer month in the range `1..12`.
680
- # * A 3-character string that matches regular expression
681
- # `/jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec/i`.
1103
+ # `sec` may be Float or Rational.
682
1104
  #
683
- # * `day`: an integer day in the range `1..31` (less than 31 for some months).
684
- # * `hour`: an integer hour in the range `0..23`.
685
- # * `min`: an integer minute in the range `0..59`.
686
- # * `sec` is the number of seconds (Integer, Float, or Rational) in the range
687
- # `0..60`.
688
- # * `zone`: a timezone, which may be:
689
- # * A string offset from UTC.
690
- # * A single letter offset from UTC, in the range `'A'..'Z'`, `'J'` (the
691
- # so-called military timezone) excluded.
692
- # * An integer number of seconds.
693
- # * A timezone object; see [Timezone
694
- # Argument](#class-Time-label-Timezone+Argument) for details.
1105
+ # Time.new(2000, 1, 1, 0, 0, 59.5) # => 2000-12-31 23:59:59.5 +0900
1106
+ # Time.new(2000, 1, 1, 0, 0, 59.7r) # => 2000-12-31 23:59:59.7 +0900
695
1107
  #
696
- # * `in: zone`: a timezone *zone*, which may be as above.
1108
+ # These values may be:
697
1109
  #
698
- def initialize: (?Integer? year, ?Integer? month, ?Integer? day, ?Integer? hour, ?Integer? min, ?Numeric? sec, ?String | Integer | nil) -> void
699
- | (?Integer? year, ?Integer? month, ?Integer? day, ?Integer? hour, ?Integer? min, ?Numeric? sec, in: String | Integer | nil) -> void
1110
+ # * Integers, as above.
1111
+ # * Numerics convertible to integers:
1112
+ #
1113
+ # Time.new(Float(0.0), Rational(1, 1), 1.0, 0.0, 0.0, 0.0)
1114
+ # # => 0000-01-01 00:00:00 -0600
1115
+ #
1116
+ # * String integers:
1117
+ #
1118
+ # a = %w[0 1 1 0 0 0]
1119
+ # # => ["0", "1", "1", "0", "0", "0"]
1120
+ # Time.new(*a) # => 0000-01-01 00:00:00 -0600
1121
+ #
1122
+ # When positional argument `zone` or keyword argument `in:` is given, the new
1123
+ # `Time` object is in the specified timezone. For the forms of argument `zone`,
1124
+ # see [Timezone Specifiers](rdoc-ref:Time@Timezone+Specifiers):
1125
+ #
1126
+ # Time.new(2000, 1, 1, 0, 0, 0, '+12:00')
1127
+ # # => 2000-01-01 00:00:00 +1200
1128
+ # Time.new(2000, 1, 1, 0, 0, 0, in: '-12:00')
1129
+ # # => 2000-01-01 00:00:00 -1200
1130
+ # Time.new(in: '-12:00')
1131
+ # # => 2022-08-23 08:49:26.1941467 -1200
1132
+ #
1133
+ # Since `in:` keyword argument just provides the default, so if the first
1134
+ # argument in single string form contains time zone information, this keyword
1135
+ # argument will be silently ignored.
1136
+ #
1137
+ # Time.new('2000-01-01 00:00:00 +0100', in: '-0500').utc_offset # => 3600
1138
+ #
1139
+ # * `precision`: maximum effective digits in sub-second part, default is 9.
1140
+ # More digits will be truncated, as other operations of `Time`. Ignored
1141
+ # unless the first argument is a string.
1142
+ #
1143
+ def initialize: (?Integer year, ?Integer? month, ?Integer? day, ?Integer? hour, ?Integer? min, ?Numeric? sec, ?String | Integer | nil) -> void
1144
+ | (?Integer year, ?Integer? month, ?Integer? day, ?Integer? hour, ?Integer? min, ?Numeric? sec, in: String | Integer | nil) -> void
1145
+ | (String, ?in: string | int | nil, ?precision: int) -> void
700
1146
 
701
1147
  # <!--
702
1148
  # rdoc-file=time.c
703
- # - time.inspect -> string
1149
+ # - inspect -> string
704
1150
  # -->
705
- # Returns a detailed string representing *time*. Unlike to_s, preserves
706
- # subsecond in the representation for easier debugging.
1151
+ # Returns a string representation of `self` with subseconds:
707
1152
  #
708
- # t = Time.now
709
- # t.inspect #=> "2012-11-10 18:16:12.261257655 +0100"
710
- # t.strftime "%Y-%m-%d %H:%M:%S.%N %z" #=> "2012-11-10 18:16:12.261257655 +0100"
1153
+ # t = Time.new(2000, 12, 31, 23, 59, 59, 0.5)
1154
+ # t.inspect # => "2000-12-31 23:59:59.5 +000001"
711
1155
  #
712
- # t.utc.inspect #=> "2012-11-10 17:16:12.261257655 UTC"
713
- # t.strftime "%Y-%m-%d %H:%M:%S.%N UTC" #=> "2012-11-10 17:16:12.261257655 UTC"
1156
+ # Related: Time#ctime, Time#to_s:
1157
+ #
1158
+ # t.ctime # => "Sun Dec 31 23:59:59 2000"
1159
+ # t.to_s # => "2000-12-31 23:59:59 +0000"
714
1160
  #
715
1161
  def inspect: () -> String
716
1162
 
717
1163
  # <!--
718
1164
  # rdoc-file=time.c
719
- # - time.isdst -> true or false
720
- # - time.dst? -> true or false
1165
+ # - dst? -> true or false
721
1166
  # -->
722
- # Returns `true` if *time* occurs during Daylight Saving Time in its time zone.
723
- #
724
- # # CST6CDT:
725
- # Time.local(2000, 1, 1).zone #=> "CST"
726
- # Time.local(2000, 1, 1).isdst #=> false
727
- # Time.local(2000, 1, 1).dst? #=> false
728
- # Time.local(2000, 7, 1).zone #=> "CDT"
729
- # Time.local(2000, 7, 1).isdst #=> true
730
- # Time.local(2000, 7, 1).dst? #=> true
731
- #
732
- # # Asia/Tokyo:
733
- # Time.local(2000, 1, 1).zone #=> "JST"
734
- # Time.local(2000, 1, 1).isdst #=> false
735
- # Time.local(2000, 1, 1).dst? #=> false
736
- # Time.local(2000, 7, 1).zone #=> "JST"
737
- # Time.local(2000, 7, 1).isdst #=> false
738
- # Time.local(2000, 7, 1).dst? #=> false
1167
+ # Returns `true` if `self` is in daylight saving time, `false` otherwise:
1168
+ #
1169
+ # t = Time.local(2000, 1, 1) # => 2000-01-01 00:00:00 -0600
1170
+ # t.zone # => "Central Standard Time"
1171
+ # t.dst? # => false
1172
+ # t = Time.local(2000, 7, 1) # => 2000-07-01 00:00:00 -0500
1173
+ # t.zone # => "Central Daylight Time"
1174
+ # t.dst? # => true
739
1175
  #
740
1176
  def isdst: () -> bool
741
1177
 
1178
+ # <!-- rdoc-file=lib/time.rb -->
1179
+ # Parses `time` as a dateTime defined by the XML Schema and converts it to a
1180
+ # Time object. The format is a restricted version of the format defined by ISO
1181
+ # 8601.
1182
+ #
1183
+ # ArgumentError is raised if `time` is not compliant with the format or if the
1184
+ # Time class cannot represent the specified time.
1185
+ #
1186
+ # See #xmlschema for more information on this format.
1187
+ #
1188
+ # require 'time'
1189
+ #
1190
+ # Time.xmlschema("2011-10-05T22:26:12-04:00")
1191
+ # #=> 2011-10-05 22:26:12-04:00
1192
+ #
1193
+ # You must require 'time' to use this method.
1194
+ #
1195
+ alias iso8601 xmlschema
1196
+
742
1197
  # <!--
743
1198
  # rdoc-file=time.c
744
- # - time.localtime -> time
745
- # - time.localtime(utc_offset) -> time
1199
+ # - localtime -> self or new_time
1200
+ # - localtime(zone) -> new_time
746
1201
  # -->
747
- # Converts *time* to local time (using the local time zone in effect at the
748
- # creation time of *time*) modifying the receiver.
1202
+ # With no argument given:
749
1203
  #
750
- # If `utc_offset` is given, it is used instead of the local time.
1204
+ # * Returns `self` if `self` is a local time.
1205
+ # * Otherwise returns a new `Time` in the user's local timezone:
751
1206
  #
752
- # t = Time.utc(2000, "jan", 1, 20, 15, 1) #=> 2000-01-01 20:15:01 UTC
753
- # t.utc? #=> true
1207
+ # t = Time.utc(2000, 1, 1, 20, 15, 1) # => 2000-01-01 20:15:01 UTC
1208
+ # t.localtime # => 2000-01-01 14:15:01 -0600
754
1209
  #
755
- # t.localtime #=> 2000-01-01 14:15:01 -0600
756
- # t.utc? #=> false
1210
+ # With argument `zone` given, returns the new `Time` object created by
1211
+ # converting `self` to the given time zone:
757
1212
  #
758
- # t.localtime("+09:00") #=> 2000-01-02 05:15:01 +0900
759
- # t.utc? #=> false
1213
+ # t = Time.utc(2000, 1, 1, 20, 15, 1) # => 2000-01-01 20:15:01 UTC
1214
+ # t.localtime("-09:00") # => 2000-01-01 11:15:01 -0900
760
1215
  #
761
- # If `utc_offset` is not given and *time* is local time, just returns the
762
- # receiver.
1216
+ # For forms of argument `zone`, see [Timezone
1217
+ # Specifiers](rdoc-ref:Time@Timezone+Specifiers).
763
1218
  #
764
1219
  def localtime: (?String utc_offset) -> Time
765
1220
 
766
1221
  # <!--
767
1222
  # rdoc-file=time.c
768
- # - time.day -> integer
769
- # - time.mday -> integer
1223
+ # - mday -> integer
770
1224
  # -->
771
- # Returns the day of the month (1..31) for *time*.
1225
+ # Returns the integer day of the month for `self`, in range (1..31):
1226
+ #
1227
+ # t = Time.new(2000, 1, 2, 3, 4, 5, 6)
1228
+ # # => 2000-01-02 03:04:05 +000006
1229
+ # t.mday # => 2
772
1230
  #
773
- # t = Time.now #=> 2007-11-19 08:27:03 -0600
774
- # t.day #=> 19
775
- # t.mday #=> 19
1231
+ # Related: Time#year, Time#hour, Time#min.
776
1232
  #
777
1233
  def mday: () -> Integer
778
1234
 
779
1235
  # <!--
780
1236
  # rdoc-file=time.c
781
- # - time.min -> integer
1237
+ # - min -> integer
782
1238
  # -->
783
- # Returns the minute of the hour (0..59) for *time*.
1239
+ # Returns the integer minute of the hour for `self`, in range (0..59):
784
1240
  #
785
- # t = Time.now #=> 2007-11-19 08:25:51 -0600
786
- # t.min #=> 25
1241
+ # t = Time.new(2000, 1, 2, 3, 4, 5, 6)
1242
+ # # => 2000-01-02 03:04:05 +000006
1243
+ # t.min # => 4
1244
+ #
1245
+ # Related: Time#year, Time#mon, Time#sec.
787
1246
  #
788
1247
  def min: () -> Integer
789
1248
 
790
1249
  # <!--
791
1250
  # rdoc-file=time.c
792
- # - time.mon -> integer
793
- # - time.month -> integer
1251
+ # - mon -> integer
794
1252
  # -->
795
- # Returns the month of the year (1..12) for *time*.
1253
+ # Returns the integer month of the year for `self`, in range (1..12):
1254
+ #
1255
+ # t = Time.new(2000, 1, 2, 3, 4, 5, 6)
1256
+ # # => 2000-01-02 03:04:05 +000006
1257
+ # t.mon # => 1
796
1258
  #
797
- # t = Time.now #=> 2007-11-19 08:27:30 -0600
798
- # t.mon #=> 11
799
- # t.month #=> 11
1259
+ # Related: Time#year, Time#hour, Time#min.
800
1260
  #
801
1261
  def mon: () -> Integer
802
1262
 
803
1263
  # <!--
804
1264
  # rdoc-file=time.c
805
- # - time.monday? -> true or false
1265
+ # - monday? -> true or false
806
1266
  # -->
807
- # Returns `true` if *time* represents Monday.
1267
+ # Returns `true` if `self` represents a Monday, `false` otherwise:
808
1268
  #
809
- # t = Time.local(2003, 8, 4) #=> 2003-08-04 00:00:00 -0500
810
- # t.monday? #=> true
1269
+ # t = Time.utc(2000, 1, 3) # => 2000-01-03 00:00:00 UTC
1270
+ # t.monday? # => true
1271
+ #
1272
+ # Related: Time#tuesday?, Time#wednesday?, Time#thursday?.
811
1273
  #
812
1274
  def monday?: () -> bool
813
1275
 
814
1276
  # <!-- rdoc-file=time.c -->
815
- # Returns the number of nanoseconds for the subsecond part of *time*. The result
816
- # is a non-negative integer less than 10**9.
817
- #
818
- # t = Time.now #=> 2020-07-20 22:07:10.963933942 +0900
819
- # t.nsec #=> 963933942
1277
+ # Returns the number of nanoseconds in the subseconds part of `self` in the
1278
+ # range (0..999_999_999); lower-order digits are truncated, not rounded:
820
1279
  #
821
- # If *time* has fraction of nanosecond (such as picoseconds), it is truncated.
1280
+ # t = Time.now # => 2022-07-11 15:04:53.3219637 -0500
1281
+ # t.nsec # => 321963700
822
1282
  #
823
- # t = Time.new(2000,1,1,0,0,0.666_777_888_999r)
824
- # t.nsec #=> 666777888
825
- #
826
- # Time#subsec can be used to obtain the subsecond part exactly.
1283
+ # Related: Time#subsec (returns exact subseconds).
827
1284
  #
828
1285
  def nsec: () -> Integer
829
1286
 
830
1287
  # <!--
831
1288
  # rdoc-file=time.c
832
- # - time.round([ndigits]) -> new_time
1289
+ # - round(ndigits = 0) -> new_time
833
1290
  # -->
834
- # Rounds subsecond to a given precision in decimal digits (0 digits by default).
835
- # It returns a new Time object. `ndigits` should be zero or a positive integer.
836
- #
837
- # t = Time.utc(2010,3,30, 5,43,25.123456789r)
838
- # t #=> 2010-03-30 05:43:25.123456789 UTC
839
- # t.round #=> 2010-03-30 05:43:25 UTC
840
- # t.round(0) #=> 2010-03-30 05:43:25 UTC
841
- # t.round(1) #=> 2010-03-30 05:43:25.1 UTC
842
- # t.round(2) #=> 2010-03-30 05:43:25.12 UTC
843
- # t.round(3) #=> 2010-03-30 05:43:25.123 UTC
844
- # t.round(4) #=> 2010-03-30 05:43:25.1235 UTC
845
- #
846
- # t = Time.utc(1999,12,31, 23,59,59)
847
- # (t + 0.4).round #=> 1999-12-31 23:59:59 UTC
848
- # (t + 0.49).round #=> 1999-12-31 23:59:59 UTC
849
- # (t + 0.5).round #=> 2000-01-01 00:00:00 UTC
850
- # (t + 1.4).round #=> 2000-01-01 00:00:00 UTC
851
- # (t + 1.49).round #=> 2000-01-01 00:00:00 UTC
852
- # (t + 1.5).round #=> 2000-01-01 00:00:01 UTC
853
- #
854
- # t = Time.utc(1999,12,31, 23,59,59) #=> 1999-12-31 23:59:59 UTC
855
- # (t + 0.123456789).round(4).iso8601(6) #=> 1999-12-31 23:59:59.1235 UTC
856
- #
857
- def round: (?Integer arg0) -> Time
1291
+ # Returns a new `Time` object whose numeric value is that of `self`, with its
1292
+ # seconds value rounded to precision `ndigits`:
1293
+ #
1294
+ # t = Time.utc(2010, 3, 30, 5, 43, 25.123456789r)
1295
+ # t # => 2010-03-30 05:43:25.123456789 UTC
1296
+ # t.round # => 2010-03-30 05:43:25 UTC
1297
+ # t.round(0) # => 2010-03-30 05:43:25 UTC
1298
+ # t.round(1) # => 2010-03-30 05:43:25.1 UTC
1299
+ # t.round(2) # => 2010-03-30 05:43:25.12 UTC
1300
+ # t.round(3) # => 2010-03-30 05:43:25.123 UTC
1301
+ # t.round(4) # => 2010-03-30 05:43:25.1235 UTC
1302
+ #
1303
+ # t = Time.utc(1999, 12,31, 23, 59, 59)
1304
+ # t # => 1999-12-31 23:59:59 UTC
1305
+ # (t + 0.4).round # => 1999-12-31 23:59:59 UTC
1306
+ # (t + 0.49).round # => 1999-12-31 23:59:59 UTC
1307
+ # (t + 0.5).round # => 2000-01-01 00:00:00 UTC
1308
+ # (t + 1.4).round # => 2000-01-01 00:00:00 UTC
1309
+ # (t + 1.49).round # => 2000-01-01 00:00:00 UTC
1310
+ # (t + 1.5).round # => 2000-01-01 00:00:01 UTC
1311
+ #
1312
+ # Related: Time#ceil, Time#floor.
1313
+ #
1314
+ def round: (?int ndigits) -> Time
858
1315
 
859
1316
  # <!--
860
1317
  # rdoc-file=time.c
861
- # - time.saturday? -> true or false
1318
+ # - saturday? -> true or false
862
1319
  # -->
863
- # Returns `true` if *time* represents Saturday.
1320
+ # Returns `true` if `self` represents a Saturday, `false` otherwise:
1321
+ #
1322
+ # t = Time.utc(2000, 1, 1) # => 2000-01-01 00:00:00 UTC
1323
+ # t.saturday? # => true
864
1324
  #
865
- # t = Time.local(2006, 6, 10) #=> 2006-06-10 00:00:00 -0500
866
- # t.saturday? #=> true
1325
+ # Related: Time#sunday?, Time#monday?, Time#tuesday?.
867
1326
  #
868
1327
  def saturday?: () -> bool
869
1328
 
870
1329
  # <!--
871
1330
  # rdoc-file=time.c
872
- # - time.sec -> integer
1331
+ # - sec -> integer
873
1332
  # -->
874
- # Returns the second of the minute (0..60) for *time*.
1333
+ # Returns the integer second of the minute for `self`, in range (0..60):
875
1334
  #
876
- # **Note:** Seconds range from zero to 60 to allow the system to inject leap
877
- # seconds. See https://en.wikipedia.org/wiki/Leap_second for further details.
1335
+ # t = Time.new(2000, 1, 2, 3, 4, 5, 6)
1336
+ # # => 2000-01-02 03:04:05 +000006
1337
+ # t.sec # => 5
878
1338
  #
879
- # t = Time.now #=> 2007-11-19 08:25:02 -0600
880
- # t.sec #=> 2
1339
+ # Note: the second value may be 60 when there is a [leap
1340
+ # second](https://en.wikipedia.org/wiki/Leap_second).
1341
+ #
1342
+ # Related: Time#year, Time#mon, Time#min.
881
1343
  #
882
1344
  def sec: () -> Integer
883
1345
 
884
1346
  # <!--
885
1347
  # rdoc-file=time.c
886
- # - time.strftime( string ) -> string
1348
+ # - strftime(format_string) -> string
887
1349
  # -->
888
- # Formats *time* according to the directives in the given format string.
889
- #
890
- # The directives begin with a percent (%) character. Any text not listed as a
891
- # directive will be passed through to the output string.
892
- #
893
- # The directive consists of a percent (%) character, zero or more flags,
894
- # optional minimum field width, optional modifier and a conversion specifier as
895
- # follows:
896
- #
897
- # %<flags><width><modifier><conversion>
898
- #
899
- # Flags:
900
- # - don't pad a numerical output
901
- # _ use spaces for padding
902
- # 0 use zeros for padding
903
- # ^ upcase the result string
904
- # # change case
905
- # : use colons for %z
906
- #
907
- # The minimum field width specifies the minimum width.
908
- #
909
- # The modifiers are "E" and "O". They are ignored.
910
- #
911
- # Format directives:
912
- #
913
- # Date (Year, Month, Day):
914
- # %Y - Year with century if provided, will pad result at least 4 digits.
915
- # -0001, 0000, 1995, 2009, 14292, etc.
916
- # %C - year / 100 (rounded down such as 20 in 2009)
917
- # %y - year % 100 (00..99)
918
- #
919
- # %m - Month of the year, zero-padded (01..12)
920
- # %_m blank-padded ( 1..12)
921
- # %-m no-padded (1..12)
922
- # %B - The full month name (``January'')
923
- # %^B uppercased (``JANUARY'')
924
- # %b - The abbreviated month name (``Jan'')
925
- # %^b uppercased (``JAN'')
926
- # %h - Equivalent to %b
927
- #
928
- # %d - Day of the month, zero-padded (01..31)
929
- # %-d no-padded (1..31)
930
- # %e - Day of the month, blank-padded ( 1..31)
931
- #
932
- # %j - Day of the year (001..366)
933
- #
934
- # Time (Hour, Minute, Second, Subsecond):
935
- # %H - Hour of the day, 24-hour clock, zero-padded (00..23)
936
- # %k - Hour of the day, 24-hour clock, blank-padded ( 0..23)
937
- # %I - Hour of the day, 12-hour clock, zero-padded (01..12)
938
- # %l - Hour of the day, 12-hour clock, blank-padded ( 1..12)
939
- # %P - Meridian indicator, lowercase (``am'' or ``pm'')
940
- # %p - Meridian indicator, uppercase (``AM'' or ``PM'')
941
- #
942
- # %M - Minute of the hour (00..59)
943
- #
944
- # %S - Second of the minute (00..60)
945
- #
946
- # %L - Millisecond of the second (000..999)
947
- # The digits under millisecond are truncated to not produce 1000.
948
- # %N - Fractional seconds digits, default is 9 digits (nanosecond)
949
- # %3N millisecond (3 digits)
950
- # %6N microsecond (6 digits)
951
- # %9N nanosecond (9 digits)
952
- # %12N picosecond (12 digits)
953
- # %15N femtosecond (15 digits)
954
- # %18N attosecond (18 digits)
955
- # %21N zeptosecond (21 digits)
956
- # %24N yoctosecond (24 digits)
957
- # The digits under the specified length are truncated to avoid
958
- # carry up.
959
- #
960
- # Time zone:
961
- # %z - Time zone as hour and minute offset from UTC (e.g. +0900)
962
- # %:z - hour and minute offset from UTC with a colon (e.g. +09:00)
963
- # %::z - hour, minute and second offset from UTC (e.g. +09:00:00)
964
- # %Z - Abbreviated time zone name or similar information. (OS dependent)
965
- #
966
- # Weekday:
967
- # %A - The full weekday name (``Sunday'')
968
- # %^A uppercased (``SUNDAY'')
969
- # %a - The abbreviated name (``Sun'')
970
- # %^a uppercased (``SUN'')
971
- # %u - Day of the week (Monday is 1, 1..7)
972
- # %w - Day of the week (Sunday is 0, 0..6)
973
- #
974
- # ISO 8601 week-based year and week number:
975
- # The first week of YYYY starts with a Monday and includes YYYY-01-04.
976
- # The days in the year before the first week are in the last week of
977
- # the previous year.
978
- # %G - The week-based year
979
- # %g - The last 2 digits of the week-based year (00..99)
980
- # %V - Week number of the week-based year (01..53)
981
- #
982
- # Week number:
983
- # The first week of YYYY that starts with a Sunday or Monday (according to %U
984
- # or %W). The days in the year before the first week are in week 0.
985
- # %U - Week number of the year. The week starts with Sunday. (00..53)
986
- # %W - Week number of the year. The week starts with Monday. (00..53)
987
- #
988
- # Seconds since the Epoch:
989
- # %s - Number of seconds since 1970-01-01 00:00:00 UTC.
990
- #
991
- # Literal string:
992
- # %n - Newline character (\n)
993
- # %t - Tab character (\t)
994
- # %% - Literal ``%'' character
995
- #
996
- # Combination:
997
- # %c - date and time (%a %b %e %T %Y)
998
- # %D - Date (%m/%d/%y)
999
- # %F - The ISO 8601 date format (%Y-%m-%d)
1000
- # %v - VMS date (%e-%^b-%4Y)
1001
- # %x - Same as %D
1002
- # %X - Same as %T
1003
- # %r - 12-hour time (%I:%M:%S %p)
1004
- # %R - 24-hour time (%H:%M)
1005
- # %T - 24-hour time (%H:%M:%S)
1006
- #
1007
- # This method is similar to strftime() function defined in ISO C and POSIX.
1008
- #
1009
- # While all directives are locale independent since Ruby 1.9, %Z is platform
1010
- # dependent. So, the result may differ even if the same format string is used in
1011
- # other systems such as C.
1012
- #
1013
- # %z is recommended over %Z. %Z doesn't identify the timezone. For example,
1014
- # "CST" is used at America/Chicago (-06:00), America/Havana (-05:00),
1015
- # Asia/Harbin (+08:00), Australia/Darwin (+09:30) and Australia/Adelaide
1016
- # (+10:30). Also, %Z is highly dependent on the operating system. For example,
1017
- # it may generate a non ASCII string on Japanese Windows, i.e. the result can be
1018
- # different to "JST". So the numeric time zone offset, %z, is recommended.
1019
- #
1020
- # Examples:
1021
- #
1022
- # t = Time.new(2007,11,19,8,37,48,"-06:00") #=> 2007-11-19 08:37:48 -0600
1023
- # t.strftime("Printed on %m/%d/%Y") #=> "Printed on 11/19/2007"
1024
- # t.strftime("at %I:%M %p") #=> "at 08:37 AM"
1025
- #
1026
- # Various ISO 8601 formats:
1027
- # %Y%m%d => 20071119 Calendar date (basic)
1028
- # %F => 2007-11-19 Calendar date (extended)
1029
- # %Y-%m => 2007-11 Calendar date, reduced accuracy, specific month
1030
- # %Y => 2007 Calendar date, reduced accuracy, specific year
1031
- # %C => 20 Calendar date, reduced accuracy, specific century
1032
- # %Y%j => 2007323 Ordinal date (basic)
1033
- # %Y-%j => 2007-323 Ordinal date (extended)
1034
- # %GW%V%u => 2007W471 Week date (basic)
1035
- # %G-W%V-%u => 2007-W47-1 Week date (extended)
1036
- # %GW%V => 2007W47 Week date, reduced accuracy, specific week (basic)
1037
- # %G-W%V => 2007-W47 Week date, reduced accuracy, specific week (extended)
1038
- # %H%M%S => 083748 Local time (basic)
1039
- # %T => 08:37:48 Local time (extended)
1040
- # %H%M => 0837 Local time, reduced accuracy, specific minute (basic)
1041
- # %H:%M => 08:37 Local time, reduced accuracy, specific minute (extended)
1042
- # %H => 08 Local time, reduced accuracy, specific hour
1043
- # %H%M%S,%L => 083748,000 Local time with decimal fraction, comma as decimal sign (basic)
1044
- # %T,%L => 08:37:48,000 Local time with decimal fraction, comma as decimal sign (extended)
1045
- # %H%M%S.%L => 083748.000 Local time with decimal fraction, full stop as decimal sign (basic)
1046
- # %T.%L => 08:37:48.000 Local time with decimal fraction, full stop as decimal sign (extended)
1047
- # %H%M%S%z => 083748-0600 Local time and the difference from UTC (basic)
1048
- # %T%:z => 08:37:48-06:00 Local time and the difference from UTC (extended)
1049
- # %Y%m%dT%H%M%S%z => 20071119T083748-0600 Date and time of day for calendar date (basic)
1050
- # %FT%T%:z => 2007-11-19T08:37:48-06:00 Date and time of day for calendar date (extended)
1051
- # %Y%jT%H%M%S%z => 2007323T083748-0600 Date and time of day for ordinal date (basic)
1052
- # %Y-%jT%T%:z => 2007-323T08:37:48-06:00 Date and time of day for ordinal date (extended)
1053
- # %GW%V%uT%H%M%S%z => 2007W471T083748-0600 Date and time of day for week date (basic)
1054
- # %G-W%V-%uT%T%:z => 2007-W47-1T08:37:48-06:00 Date and time of day for week date (extended)
1055
- # %Y%m%dT%H%M => 20071119T0837 Calendar date and local time (basic)
1056
- # %FT%R => 2007-11-19T08:37 Calendar date and local time (extended)
1057
- # %Y%jT%H%MZ => 2007323T0837Z Ordinal date and UTC of day (basic)
1058
- # %Y-%jT%RZ => 2007-323T08:37Z Ordinal date and UTC of day (extended)
1059
- # %GW%V%uT%H%M%z => 2007W471T0837-0600 Week date and local time and difference from UTC (basic)
1060
- # %G-W%V-%uT%R%:z => 2007-W47-1T08:37-06:00 Week date and local time and difference from UTC (extended)
1350
+ # Returns a string representation of `self`, formatted according to the given
1351
+ # string `format`. See [Formats for Dates and
1352
+ # Times](rdoc-ref:strftime_formatting.rdoc).
1061
1353
  #
1062
1354
  def strftime: (String arg0) -> String
1063
1355
 
1064
1356
  # <!--
1065
1357
  # rdoc-file=time.c
1066
- # - time.subsec -> number
1358
+ # - subsec -> numeric
1067
1359
  # -->
1068
- # Returns the subsecond for *time*.
1069
- #
1070
- # The return value can be a rational number.
1071
- #
1072
- # t = Time.now #=> 2020-07-20 15:40:26.867462289 +0900
1073
- # t.subsec #=> (867462289/1000000000)
1360
+ # Returns the exact subseconds for `self` as a Numeric (Integer or Rational):
1074
1361
  #
1075
- # t = Time.now #=> 2020-07-20 15:40:50.313828595 +0900
1076
- # t.subsec #=> (62765719/200000000)
1362
+ # t = Time.now # => 2022-07-11 15:11:36.8490302 -0500
1363
+ # t.subsec # => (4245151/5000000)
1077
1364
  #
1078
- # t = Time.new(2000,1,1,2,3,4) #=> 2000-01-01 02:03:04 +0900
1079
- # t.subsec #=> 0
1365
+ # If the subseconds is zero, returns integer zero:
1080
1366
  #
1081
- # Time.new(2000,1,1,0,0,1/3r,"UTC").subsec #=> (1/3)
1367
+ # t = Time.new(2000, 1, 1, 2, 3, 4) # => 2000-01-01 02:03:04 -0600
1368
+ # t.subsec # => 0
1082
1369
  #
1083
1370
  def subsec: () -> (0 | Rational)
1084
1371
 
1085
1372
  # <!--
1086
1373
  # rdoc-file=time.c
1087
- # - time.sunday? -> true or false
1374
+ # - sunday? -> true or false
1088
1375
  # -->
1089
- # Returns `true` if *time* represents Sunday.
1376
+ # Returns `true` if `self` represents a Sunday, `false` otherwise:
1090
1377
  #
1091
- # t = Time.local(1990, 4, 1) #=> 1990-04-01 00:00:00 -0600
1092
- # t.sunday? #=> true
1378
+ # t = Time.utc(2000, 1, 2) # => 2000-01-02 00:00:00 UTC
1379
+ # t.sunday? # => true
1380
+ #
1381
+ # Related: Time#monday?, Time#tuesday?, Time#wednesday?.
1093
1382
  #
1094
1383
  def sunday?: () -> bool
1095
1384
 
1096
1385
  # <!--
1097
1386
  # rdoc-file=time.c
1098
- # - time.thursday? -> true or false
1387
+ # - thursday? -> true or false
1099
1388
  # -->
1100
- # Returns `true` if *time* represents Thursday.
1389
+ # Returns `true` if `self` represents a Thursday, `false` otherwise:
1390
+ #
1391
+ # t = Time.utc(2000, 1, 6) # => 2000-01-06 00:00:00 UTC
1392
+ # t.thursday? # => true
1101
1393
  #
1102
- # t = Time.local(1995, 12, 21) #=> 1995-12-21 00:00:00 -0600
1103
- # t.thursday? #=> true
1394
+ # Related: Time#friday?, Time#saturday?, Time#sunday?.
1104
1395
  #
1105
1396
  def thursday?: () -> bool
1106
1397
 
1107
1398
  # <!--
1108
1399
  # rdoc-file=time.c
1109
- # - time.to_a -> array
1400
+ # - to_a -> array
1110
1401
  # -->
1111
- # Returns a ten-element *array* of values for *time*:
1402
+ # Returns a 10-element array of values representing `self`:
1112
1403
  #
1113
- # [sec, min, hour, day, month, year, wday, yday, isdst, zone]
1404
+ # Time.utc(2000, 1, 1).to_a
1405
+ # # => [0, 0, 0, 1, 1, 2000, 6, 1, false, "UTC"]
1406
+ # # [sec, min, hour, day, mon, year, wday, yday, dst?, zone]
1114
1407
  #
1115
- # See the individual methods for an explanation of the valid ranges of each
1116
- # value. The ten elements can be passed directly to Time.utc or Time.local to
1117
- # create a new Time object.
1408
+ # The returned array is suitable for use as an argument to Time.utc or
1409
+ # Time.local to create a new `Time` object.
1118
1410
  #
1119
- # t = Time.now #=> 2007-11-19 08:36:01 -0600
1120
- # now = t.to_a #=> [1, 36, 8, 19, 11, 2007, 1, 323, false, "CST"]
1121
- #
1122
- def to_a: () -> [ Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, bool, String ]
1411
+ def to_a: () -> [ Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, bool, String? ]
1123
1412
 
1124
1413
  # <!--
1125
1414
  # rdoc-file=time.c
1126
- # - time.to_f -> float
1415
+ # - to_f -> float
1127
1416
  # -->
1128
- # Returns the value of *time* as a floating point number of seconds since the
1129
- # Epoch. The return value approximate the exact value in the Time object because
1130
- # floating point numbers cannot represent all rational numbers exactly.
1417
+ # Returns the value of `self` as a Float number [Epoch
1418
+ # seconds](rdoc-ref:Time@Epoch+Seconds); subseconds are included.
1419
+ #
1420
+ # The stored value of `self` is a [Rational](rdoc-ref:Rational@#method-i-to_f),
1421
+ # which means that the returned value may be approximate:
1131
1422
  #
1132
- # t = Time.now #=> 2020-07-20 22:00:29.38740268 +0900
1133
- # t.to_f #=> 1595250029.3874028
1134
- # t.to_i #=> 1595250029
1423
+ # Time.utc(1970, 1, 1, 0, 0, 0).to_f # => 0.0
1424
+ # Time.utc(1970, 1, 1, 0, 0, 0, 999999).to_f # => 0.999999
1425
+ # Time.utc(1950, 1, 1, 0, 0, 0).to_f # => -631152000.0
1426
+ # Time.utc(1990, 1, 1, 0, 0, 0).to_f # => 631152000.0
1135
1427
  #
1136
- # Note that IEEE 754 double is not accurate enough to represent the exact number
1137
- # of nanoseconds since the Epoch. (IEEE 754 double has 53bit mantissa. So it can
1138
- # represent exact number of nanoseconds only in `2 ** 53 / 1_000_000_000 / 60 /
1139
- # 60 / 24 = 104.2` days.) When Ruby uses a nanosecond-resolution clock function,
1140
- # such as `clock_gettime` of POSIX, to obtain the current time, Time#to_f can
1141
- # lose information of a Time object created with `Time.now`.
1428
+ # Related: Time#to_i, Time#to_r.
1142
1429
  #
1143
1430
  def to_f: () -> Float
1144
1431
 
1145
1432
  # <!--
1146
1433
  # rdoc-file=time.c
1147
- # - time.to_i -> int
1148
- # - time.tv_sec -> int
1434
+ # - to_i -> integer
1149
1435
  # -->
1150
- # Returns the value of *time* as an integer number of seconds since the Epoch.
1436
+ # Returns the value of `self` as integer [Epoch
1437
+ # seconds](rdoc-ref:Time@Epoch+Seconds); subseconds are truncated (not rounded):
1151
1438
  #
1152
- # If *time* contains subsecond, they are truncated.
1439
+ # Time.utc(1970, 1, 1, 0, 0, 0).to_i # => 0
1440
+ # Time.utc(1970, 1, 1, 0, 0, 0, 999999).to_i # => 0
1441
+ # Time.utc(1950, 1, 1, 0, 0, 0).to_i # => -631152000
1442
+ # Time.utc(1990, 1, 1, 0, 0, 0).to_i # => 631152000
1153
1443
  #
1154
- # t = Time.now #=> 2020-07-21 01:41:29.746012609 +0900
1155
- # t.to_i #=> 1595263289
1444
+ # Related: Time#to_f Time#to_r.
1156
1445
  #
1157
1446
  def to_i: () -> Integer
1158
1447
 
1159
1448
  # <!--
1160
1449
  # rdoc-file=time.c
1161
- # - time.to_r -> a_rational
1450
+ # - to_r -> rational
1162
1451
  # -->
1163
- # Returns the value of *time* as a rational number of seconds since the Epoch.
1452
+ # Returns the value of `self` as a Rational exact number of [Epoch
1453
+ # seconds](rdoc-ref:Time@Epoch+Seconds);
1164
1454
  #
1165
- # t = Time.now #=> 2020-07-20 22:03:45.212167333 +0900
1166
- # t.to_r #=> (1595250225212167333/1000000000)
1455
+ # Time.now.to_r # => (16571402750320203/10000000)
1167
1456
  #
1168
- # This method is intended to be used to get an accurate value representing the
1169
- # seconds (including subsecond) since the Epoch.
1457
+ # Related: Time#to_f, Time#to_i.
1170
1458
  #
1171
1459
  def to_r: () -> Rational
1172
1460
 
1173
1461
  # <!--
1174
1462
  # rdoc-file=time.c
1175
- # - time.to_s -> string
1463
+ # - to_s -> string
1176
1464
  # -->
1177
- # Returns a string representing *time*. Equivalent to calling #strftime with the
1178
- # appropriate format string.
1465
+ # Returns a string representation of `self`, without subseconds:
1179
1466
  #
1180
- # t = Time.now
1181
- # t.to_s #=> "2012-11-10 18:16:12 +0100"
1182
- # t.strftime "%Y-%m-%d %H:%M:%S %z" #=> "2012-11-10 18:16:12 +0100"
1467
+ # t = Time.new(2000, 12, 31, 23, 59, 59, 0.5)
1468
+ # t.to_s # => "2000-12-31 23:59:59 +0000"
1469
+ #
1470
+ # Related: Time#ctime, Time#inspect:
1183
1471
  #
1184
- # t.utc.to_s #=> "2012-11-10 17:16:12 UTC"
1185
- # t.strftime "%Y-%m-%d %H:%M:%S UTC" #=> "2012-11-10 17:16:12 UTC"
1472
+ # t.ctime # => "Sun Dec 31 23:59:59 2000"
1473
+ # t.inspect # => "2000-12-31 23:59:59.5 +000001"
1186
1474
  #
1187
1475
  def to_s: () -> String
1188
1476
 
1189
1477
  # <!--
1190
1478
  # rdoc-file=time.c
1191
- # - time.tuesday? -> true or false
1479
+ # - tuesday? -> true or false
1192
1480
  # -->
1193
- # Returns `true` if *time* represents Tuesday.
1481
+ # Returns `true` if `self` represents a Tuesday, `false` otherwise:
1194
1482
  #
1195
- # t = Time.local(1991, 2, 19) #=> 1991-02-19 00:00:00 -0600
1196
- # t.tuesday? #=> true
1483
+ # t = Time.utc(2000, 1, 4) # => 2000-01-04 00:00:00 UTC
1484
+ # t.tuesday? # => true
1485
+ #
1486
+ # Related: Time#wednesday?, Time#thursday?, Time#friday?.
1197
1487
  #
1198
1488
  def tuesday?: () -> bool
1199
1489
 
1200
1490
  # <!--
1201
1491
  # rdoc-file=time.c
1202
- # - time.nsec -> int
1203
- # - time.tv_nsec -> int
1492
+ # - nsec -> integer
1204
1493
  # -->
1205
- # Returns the number of nanoseconds for the subsecond part of *time*. The result
1206
- # is a non-negative integer less than 10**9.
1207
- #
1208
- # t = Time.now #=> 2020-07-20 22:07:10.963933942 +0900
1209
- # t.nsec #=> 963933942
1494
+ # Returns the number of nanoseconds in the subseconds part of `self` in the
1495
+ # range (0..999_999_999); lower-order digits are truncated, not rounded:
1210
1496
  #
1211
- # If *time* has fraction of nanosecond (such as picoseconds), it is truncated.
1497
+ # t = Time.now # => 2022-07-11 15:04:53.3219637 -0500
1498
+ # t.nsec # => 321963700
1212
1499
  #
1213
- # t = Time.new(2000,1,1,0,0,0.666_777_888_999r)
1214
- # t.nsec #=> 666777888
1215
- #
1216
- # Time#subsec can be used to obtain the subsecond part exactly.
1500
+ # Related: Time#subsec (returns exact subseconds).
1217
1501
  #
1218
1502
  def tv_nsec: () -> Integer
1219
1503
 
1220
1504
  # <!-- rdoc-file=time.c -->
1221
- # Returns the value of *time* as an integer number of seconds since the Epoch.
1505
+ # Returns the value of `self` as integer [Epoch
1506
+ # seconds](rdoc-ref:Time@Epoch+Seconds); subseconds are truncated (not rounded):
1222
1507
  #
1223
- # If *time* contains subsecond, they are truncated.
1508
+ # Time.utc(1970, 1, 1, 0, 0, 0).to_i # => 0
1509
+ # Time.utc(1970, 1, 1, 0, 0, 0, 999999).to_i # => 0
1510
+ # Time.utc(1950, 1, 1, 0, 0, 0).to_i # => -631152000
1511
+ # Time.utc(1990, 1, 1, 0, 0, 0).to_i # => 631152000
1224
1512
  #
1225
- # t = Time.now #=> 2020-07-21 01:41:29.746012609 +0900
1226
- # t.to_i #=> 1595263289
1513
+ # Related: Time#to_f Time#to_r.
1227
1514
  #
1228
1515
  def tv_sec: () -> Integer
1229
1516
 
1230
1517
  # <!--
1231
1518
  # rdoc-file=time.c
1232
- # - time.usec -> int
1233
- # - time.tv_usec -> int
1519
+ # - usec -> integer
1234
1520
  # -->
1235
- # Returns the number of microseconds for the subsecond part of *time*. The
1236
- # result is a non-negative integer less than 10**6.
1237
- #
1238
- # t = Time.now #=> 2020-07-20 22:05:58.459785953 +0900
1239
- # t.usec #=> 459785
1521
+ # Returns the number of microseconds in the subseconds part of `self` in the
1522
+ # range (0..999_999); lower-order digits are truncated, not rounded:
1240
1523
  #
1241
- # If *time* has fraction of microsecond (such as nanoseconds), it is truncated.
1524
+ # t = Time.now # => 2022-07-11 14:59:47.5484697 -0500
1525
+ # t.usec # => 548469
1242
1526
  #
1243
- # t = Time.new(2000,1,1,0,0,0.666_777_888_999r)
1244
- # t.usec #=> 666777
1245
- #
1246
- # Time#subsec can be used to obtain the subsecond part exactly.
1527
+ # Related: Time#subsec (returns exact subseconds).
1247
1528
  #
1248
1529
  def tv_usec: () -> Integer
1249
1530
 
1250
1531
  # <!-- rdoc-file=time.c -->
1251
- # Returns the number of microseconds for the subsecond part of *time*. The
1252
- # result is a non-negative integer less than 10**6.
1253
- #
1254
- # t = Time.now #=> 2020-07-20 22:05:58.459785953 +0900
1255
- # t.usec #=> 459785
1532
+ # Returns the number of microseconds in the subseconds part of `self` in the
1533
+ # range (0..999_999); lower-order digits are truncated, not rounded:
1256
1534
  #
1257
- # If *time* has fraction of microsecond (such as nanoseconds), it is truncated.
1535
+ # t = Time.now # => 2022-07-11 14:59:47.5484697 -0500
1536
+ # t.usec # => 548469
1258
1537
  #
1259
- # t = Time.new(2000,1,1,0,0,0.666_777_888_999r)
1260
- # t.usec #=> 666777
1261
- #
1262
- # Time#subsec can be used to obtain the subsecond part exactly.
1538
+ # Related: Time#subsec (returns exact subseconds).
1263
1539
  #
1264
1540
  def usec: () -> Integer
1265
1541
 
1266
1542
  # <!-- rdoc-file=time.c -->
1267
- # Converts *time* to UTC (GMT), modifying the receiver.
1543
+ # Returns `self`, converted to the UTC timezone:
1268
1544
  #
1269
- # t = Time.now #=> 2007-11-19 08:18:31 -0600
1270
- # t.gmt? #=> false
1271
- # t.gmtime #=> 2007-11-19 14:18:31 UTC
1272
- # t.gmt? #=> true
1545
+ # t = Time.new(2000) # => 2000-01-01 00:00:00 -0600
1546
+ # t.utc? # => false
1547
+ # t.utc # => 2000-01-01 06:00:00 UTC
1548
+ # t.utc? # => true
1273
1549
  #
1274
- # t = Time.now #=> 2007-11-19 08:18:51 -0600
1275
- # t.utc? #=> false
1276
- # t.utc #=> 2007-11-19 14:18:51 UTC
1277
- # t.utc? #=> true
1550
+ # Related: Time#getutc (returns a new converted `Time` object).
1278
1551
  #
1279
1552
  def utc: () -> Time
1280
1553
 
1281
1554
  # <!--
1282
1555
  # rdoc-file=time.c
1283
- # - time.utc? -> true or false
1284
- # - time.gmt? -> true or false
1556
+ # - utc? -> true or false
1285
1557
  # -->
1286
- # Returns `true` if *time* represents a time in UTC (GMT).
1558
+ # Returns `true` if `self` represents a time in UTC (GMT):
1287
1559
  #
1288
- # t = Time.now #=> 2007-11-19 08:15:23 -0600
1289
- # t.utc? #=> false
1290
- # t = Time.gm(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 UTC
1291
- # t.utc? #=> true
1560
+ # now = Time.now
1561
+ # # => 2022-08-18 10:24:13.5398485 -0500
1562
+ # now.utc? # => false
1563
+ # utc = Time.utc(2000, 1, 1, 20, 15, 1)
1564
+ # # => 2000-01-01 20:15:01 UTC
1565
+ # utc.utc? # => true
1292
1566
  #
1293
- # t = Time.now #=> 2007-11-19 08:16:03 -0600
1294
- # t.gmt? #=> false
1295
- # t = Time.gm(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 UTC
1296
- # t.gmt? #=> true
1567
+ # Related: Time.utc.
1297
1568
  #
1298
1569
  def utc?: () -> bool
1299
1570
 
1300
1571
  # <!-- rdoc-file=time.c -->
1301
- # Returns the offset in seconds between the timezone of *time* and UTC.
1572
+ # Returns the offset in seconds between the timezones of UTC and `self`:
1302
1573
  #
1303
- # t = Time.gm(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 UTC
1304
- # t.gmt_offset #=> 0
1305
- # l = t.getlocal #=> 2000-01-01 14:15:01 -0600
1306
- # l.gmt_offset #=> -21600
1574
+ # Time.utc(2000, 1, 1).utc_offset # => 0
1575
+ # Time.local(2000, 1, 1).utc_offset # => -21600 # -6*3600, or minus six hours.
1307
1576
  #
1308
1577
  def utc_offset: () -> Integer
1309
1578
 
1310
1579
  # <!--
1311
1580
  # rdoc-file=time.c
1312
- # - time.wday -> integer
1581
+ # - wday -> integer
1313
1582
  # -->
1314
- # Returns an integer representing the day of the week, 0..6, with Sunday == 0.
1315
- #
1316
- # t = Time.now #=> 2007-11-20 02:35:35 -0600
1317
- # t.wday #=> 2
1318
- # t.sunday? #=> false
1319
- # t.monday? #=> false
1320
- # t.tuesday? #=> true
1321
- # t.wednesday? #=> false
1322
- # t.thursday? #=> false
1323
- # t.friday? #=> false
1324
- # t.saturday? #=> false
1583
+ # Returns the integer day of the week for `self`, in range (0..6), with Sunday
1584
+ # as zero.
1585
+ #
1586
+ # t = Time.new(2000, 1, 2, 3, 4, 5, 6)
1587
+ # # => 2000-01-02 03:04:05 +000006
1588
+ # t.wday # => 0
1589
+ # t.sunday? # => true
1590
+ #
1591
+ # Related: Time#year, Time#hour, Time#min.
1325
1592
  #
1326
1593
  def wday: () -> Integer
1327
1594
 
1328
1595
  # <!--
1329
1596
  # rdoc-file=time.c
1330
- # - time.wednesday? -> true or false
1597
+ # - wednesday? -> true or false
1331
1598
  # -->
1332
- # Returns `true` if *time* represents Wednesday.
1599
+ # Returns `true` if `self` represents a Wednesday, `false` otherwise:
1333
1600
  #
1334
- # t = Time.local(1993, 2, 24) #=> 1993-02-24 00:00:00 -0600
1335
- # t.wednesday? #=> true
1601
+ # t = Time.utc(2000, 1, 5) # => 2000-01-05 00:00:00 UTC
1602
+ # t.wednesday? # => true
1603
+ #
1604
+ # Related: Time#thursday?, Time#friday?, Time#saturday?.
1336
1605
  #
1337
1606
  def wednesday?: () -> bool
1338
1607
 
1608
+ # <!--
1609
+ # rdoc-file=lib/time.rb
1610
+ # - xmlschema(fraction_digits=0)
1611
+ # -->
1612
+ # Returns a string which represents the time as a dateTime defined by XML
1613
+ # Schema:
1614
+ #
1615
+ # CCYY-MM-DDThh:mm:ssTZD
1616
+ # CCYY-MM-DDThh:mm:ss.sssTZD
1617
+ #
1618
+ # where TZD is Z or [+-]hh:mm.
1619
+ #
1620
+ # If self is a UTC time, Z is used as TZD. [+-]hh:mm is used otherwise.
1621
+ #
1622
+ # `fraction_digits` specifies a number of digits to use for fractional seconds.
1623
+ # Its default value is 0.
1624
+ #
1625
+ # require 'time'
1626
+ #
1627
+ # t = Time.now
1628
+ # t.iso8601 # => "2011-10-05T22:26:12-04:00"
1629
+ #
1630
+ # You must require 'time' to use this method.
1631
+ #
1632
+ def xmlschema: (?Integer fraction_digits) -> String
1633
+
1339
1634
  # <!--
1340
1635
  # rdoc-file=time.c
1341
- # - time.yday -> integer
1636
+ # - yday -> integer
1342
1637
  # -->
1343
- # Returns an integer representing the day of the year, 1..366.
1638
+ # Returns the integer day of the year of `self`, in range (1..366).
1344
1639
  #
1345
- # t = Time.now #=> 2007-11-19 08:32:31 -0600
1346
- # t.yday #=> 323
1640
+ # Time.new(2000, 1, 1).yday # => 1
1641
+ # Time.new(2000, 12, 31).yday # => 366
1347
1642
  #
1348
1643
  def yday: () -> Integer
1349
1644
 
1350
1645
  # <!--
1351
1646
  # rdoc-file=time.c
1352
- # - time.year -> integer
1647
+ # - year -> integer
1353
1648
  # -->
1354
- # Returns the year for *time* (including the century).
1649
+ # Returns the integer year for `self`:
1650
+ #
1651
+ # t = Time.new(2000, 1, 2, 3, 4, 5, 6)
1652
+ # # => 2000-01-02 03:04:05 +000006
1653
+ # t.year # => 2000
1355
1654
  #
1356
- # t = Time.now #=> 2007-11-19 08:27:51 -0600
1357
- # t.year #=> 2007
1655
+ # Related: Time#mon, Time#hour, Time#min.
1358
1656
  #
1359
1657
  def year: () -> Integer
1360
1658
 
@@ -1362,99 +1660,101 @@ class Time < Object
1362
1660
  # rdoc-file=time.c
1363
1661
  # - time.zone -> string or timezone
1364
1662
  # -->
1365
- # Returns the name of the time zone used for *time*. As of Ruby 1.8, returns
1366
- # ``UTC'' rather than ``GMT'' for UTC times.
1663
+ # Returns the string name of the time zone for `self`:
1367
1664
  #
1368
- # t = Time.gm(2000, "jan", 1, 20, 15, 1)
1369
- # t.zone #=> "UTC"
1370
- # t = Time.local(2000, "jan", 1, 20, 15, 1)
1371
- # t.zone #=> "CST"
1665
+ # Time.utc(2000, 1, 1).zone # => "UTC"
1666
+ # Time.new(2000, 1, 1).zone # => "Central Standard Time"
1372
1667
  #
1373
- def zone: () -> String
1668
+ def zone: () -> String?
1374
1669
 
1375
- # Same as Time::gm, but interprets the values in the local time zone.
1670
+ # <!-- rdoc-file=time.c -->
1671
+ # Like Time.utc, except that the returned `Time` object has the local timezone,
1672
+ # not the UTC timezone:
1376
1673
  #
1377
- # Time.local(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 -0600
1674
+ # # With seven arguments.
1675
+ # Time.local(0, 1, 2, 3, 4, 5, 6)
1676
+ # # => 0000-01-02 03:04:05.000006 -0600
1677
+ # # With exactly ten arguments.
1678
+ # Time.local(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
1679
+ # # => 0005-04-03 02:01:00 -0600
1378
1680
  #
1379
1681
  def self.mktime: (Integer year, ?Integer | String month, ?Integer day, ?Integer hour, ?Integer min, ?Numeric sec, ?Numeric usec_with_frac) -> Time
1380
1682
 
1381
1683
  # <!--
1382
1684
  # rdoc-file=time.c
1383
- # - time.gmt_offset -> integer
1384
- # - time.gmtoff -> integer
1385
- # - time.utc_offset -> integer
1685
+ # - utc_offset -> integer
1386
1686
  # -->
1387
- # Returns the offset in seconds between the timezone of *time* and UTC.
1687
+ # Returns the offset in seconds between the timezones of UTC and `self`:
1388
1688
  #
1389
- # t = Time.gm(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 UTC
1390
- # t.gmt_offset #=> 0
1391
- # l = t.getlocal #=> 2000-01-01 14:15:01 -0600
1392
- # l.gmt_offset #=> -21600
1689
+ # Time.utc(2000, 1, 1).utc_offset # => 0
1690
+ # Time.local(2000, 1, 1).utc_offset # => -21600 # -6*3600, or minus six hours.
1393
1691
  #
1394
1692
  def gmtoff: () -> Integer
1395
1693
 
1396
1694
  # <!-- rdoc-file=time.c -->
1397
- # Returns the month of the year (1..12) for *time*.
1695
+ # Returns the integer month of the year for `self`, in range (1..12):
1696
+ #
1697
+ # t = Time.new(2000, 1, 2, 3, 4, 5, 6)
1698
+ # # => 2000-01-02 03:04:05 +000006
1699
+ # t.mon # => 1
1398
1700
  #
1399
- # t = Time.now #=> 2007-11-19 08:27:30 -0600
1400
- # t.mon #=> 11
1401
- # t.month #=> 11
1701
+ # Related: Time#year, Time#hour, Time#min.
1402
1702
  #
1403
1703
  def month: () -> Integer
1404
1704
 
1405
1705
  # <!--
1406
1706
  # rdoc-file=time.c
1407
- # - time.floor([ndigits]) -> new_time
1707
+ # - floor(ndigits = 0) -> new_time
1408
1708
  # -->
1409
- # Floors subsecond to a given precision in decimal digits (0 digits by default).
1410
- # It returns a new Time object. `ndigits` should be zero or a positive integer.
1709
+ # Returns a new `Time` object whose numerical value is less than or equal to
1710
+ # `self` with its seconds truncated to precision `ndigits`:
1411
1711
  #
1412
- # t = Time.utc(2010,3,30, 5,43,25.123456789r)
1413
- # t #=> 2010-03-30 05:43:25.123456789 UTC
1414
- # t.floor #=> 2010-03-30 05:43:25 UTC
1415
- # t.floor(0) #=> 2010-03-30 05:43:25 UTC
1416
- # t.floor(1) #=> 2010-03-30 05:43:25.1 UTC
1417
- # t.floor(2) #=> 2010-03-30 05:43:25.12 UTC
1418
- # t.floor(3) #=> 2010-03-30 05:43:25.123 UTC
1419
- # t.floor(4) #=> 2010-03-30 05:43:25.1234 UTC
1712
+ # t = Time.utc(2010, 3, 30, 5, 43, 25.123456789r)
1713
+ # t # => 2010-03-30 05:43:25.123456789 UTC
1714
+ # t.floor # => 2010-03-30 05:43:25 UTC
1715
+ # t.floor(2) # => 2010-03-30 05:43:25.12 UTC
1716
+ # t.floor(4) # => 2010-03-30 05:43:25.1234 UTC
1717
+ # t.floor(6) # => 2010-03-30 05:43:25.123456 UTC
1718
+ # t.floor(8) # => 2010-03-30 05:43:25.12345678 UTC
1719
+ # t.floor(10) # => 2010-03-30 05:43:25.123456789 UTC
1420
1720
  #
1421
- # t = Time.utc(1999,12,31, 23,59,59)
1422
- # (t + 0.4).floor #=> 1999-12-31 23:59:59 UTC
1423
- # (t + 0.9).floor #=> 1999-12-31 23:59:59 UTC
1424
- # (t + 1.4).floor #=> 2000-01-01 00:00:00 UTC
1425
- # (t + 1.9).floor #=> 2000-01-01 00:00:00 UTC
1721
+ # t = Time.utc(1999, 12, 31, 23, 59, 59)
1722
+ # t # => 1999-12-31 23:59:59 UTC
1723
+ # (t + 0.4).floor # => 1999-12-31 23:59:59 UTC
1724
+ # (t + 0.9).floor # => 1999-12-31 23:59:59 UTC
1725
+ # (t + 1.4).floor # => 2000-01-01 00:00:00 UTC
1726
+ # (t + 1.9).floor # => 2000-01-01 00:00:00 UTC
1426
1727
  #
1427
- # t = Time.utc(1999,12,31, 23,59,59)
1428
- # (t + 0.123456789).floor(4) #=> 1999-12-31 23:59:59.1234 UTC
1728
+ # Related: Time#ceil, Time#round.
1429
1729
  #
1430
- def floor: (?Integer ndigits) -> Time
1730
+ def floor: (?int ndigits) -> Time
1431
1731
 
1432
1732
  # <!--
1433
1733
  # rdoc-file=time.c
1434
- # - time.ceil([ndigits]) -> new_time
1734
+ # - ceil(ndigits = 0) -> new_time
1435
1735
  # -->
1436
- # Ceils subsecond to a given precision in decimal digits (0 digits by default).
1437
- # It returns a new Time object. `ndigits` should be zero or a positive integer.
1438
- #
1439
- # t = Time.utc(2010,3,30, 5,43,25.0123456789r)
1440
- # t #=> 2010-03-30 05:43:25 123456789/10000000000 UTC
1441
- # t.ceil #=> 2010-03-30 05:43:26 UTC
1442
- # t.ceil(0) #=> 2010-03-30 05:43:26 UTC
1443
- # t.ceil(1) #=> 2010-03-30 05:43:25.1 UTC
1444
- # t.ceil(2) #=> 2010-03-30 05:43:25.02 UTC
1445
- # t.ceil(3) #=> 2010-03-30 05:43:25.013 UTC
1446
- # t.ceil(4) #=> 2010-03-30 05:43:25.0124 UTC
1447
- #
1448
- # t = Time.utc(1999,12,31, 23,59,59)
1449
- # (t + 0.4).ceil #=> 2000-01-01 00:00:00 UTC
1450
- # (t + 0.9).ceil #=> 2000-01-01 00:00:00 UTC
1451
- # (t + 1.4).ceil #=> 2000-01-01 00:00:01 UTC
1452
- # (t + 1.9).ceil #=> 2000-01-01 00:00:01 UTC
1453
- #
1454
- # t = Time.utc(1999,12,31, 23,59,59)
1455
- # (t + 0.123456789).ceil(4) #=> 1999-12-31 23:59:59.1235 UTC
1456
- #
1457
- def ceil: (?Integer ndigits) -> Time
1736
+ # Returns a new `Time` object whose numerical value is greater than or equal to
1737
+ # `self` with its seconds truncated to precision `ndigits`:
1738
+ #
1739
+ # t = Time.utc(2010, 3, 30, 5, 43, 25.123456789r)
1740
+ # t # => 2010-03-30 05:43:25.123456789 UTC
1741
+ # t.ceil # => 2010-03-30 05:43:26 UTC
1742
+ # t.ceil(2) # => 2010-03-30 05:43:25.13 UTC
1743
+ # t.ceil(4) # => 2010-03-30 05:43:25.1235 UTC
1744
+ # t.ceil(6) # => 2010-03-30 05:43:25.123457 UTC
1745
+ # t.ceil(8) # => 2010-03-30 05:43:25.12345679 UTC
1746
+ # t.ceil(10) # => 2010-03-30 05:43:25.123456789 UTC
1747
+ #
1748
+ # t = Time.utc(1999, 12, 31, 23, 59, 59)
1749
+ # t # => 1999-12-31 23:59:59 UTC
1750
+ # (t + 0.4).ceil # => 2000-01-01 00:00:00 UTC
1751
+ # (t + 0.9).ceil # => 2000-01-01 00:00:00 UTC
1752
+ # (t + 1.4).ceil # => 2000-01-01 00:00:01 UTC
1753
+ # (t + 1.9).ceil # => 2000-01-01 00:00:01 UTC
1754
+ #
1755
+ # Related: Time#floor, Time#round.
1756
+ #
1757
+ def ceil: (?int ndigits) -> Time
1458
1758
  end
1459
1759
 
1460
1760
  Time::RFC2822_DAY_NAME: Array[String]