aboutsummaryrefslogtreecommitdiffstats
path: root/timev.rb
diff options
context:
space:
mode:
authorBurdette Lamar <BurdetteLamar@Yahoo.com>2022-08-28 16:49:51 -0500
committerGitHub <noreply@github.com>2022-08-28 16:49:51 -0500
commitaecc3b12528e1b02d24bcd5df746e93aa04ba211 (patch)
tree75c26fef5a0d92431520889656c9649acf29be91 /timev.rb
parent5fcce23ae2a9064e9dd6db6afe9a83f6f3ffcb30 (diff)
downloadruby-aecc3b12528e1b02d24bcd5df746e93aa04ba211.tar.gz
[DOC] Enhanced RDoc for Time (#6294)
Diffstat (limited to 'timev.rb')
-rw-r--r--timev.rb62
1 files changed, 47 insertions, 15 deletions
diff --git a/timev.rb b/timev.rb
index ad97d63b55..48aabdc798 100644
--- a/timev.rb
+++ b/timev.rb
@@ -1,19 +1,49 @@
-# Time is an abstraction of dates and times. Time is stored internally as
-# the number of seconds with subsecond since the _Epoch_,
-# 1970-01-01 00:00:00 UTC.
+# A \Time object represents a date and time:
#
-# The Time class treats GMT
-# (Greenwich Mean Time) and UTC (Coordinated Universal Time) as equivalent.
-# GMT is the older way of referring to these baseline times but persists in
-# the names of calls on POSIX systems.
+# Time.new(2000, 1, 1, 0, 0, 0) # => 2000-01-01 00:00:00 -0600
#
-# Note: A \Time object uses the resolution available on your system clock.
+# Although its value can be expressed as a single numeric
+# (see {Epoch Seconds}[rdoc-ref:Time@Epoch+Seconds] below),
+# it can be convenient to deal with the value by parts:
#
-# All times may have subsecond. Be aware of this fact when comparing times
-# with each other -- times that are apparently equal when displayed may be
-# different when compared.
-# (Since Ruby 2.7.0, Time#inspect shows subsecond but
-# Time#to_s still doesn't show subsecond.)
+# t = Time.new(-2000, 1, 1, 0, 0, 0.0)
+# # => -2000-01-01 00:00:00 -0600
+# t.year # => -2000
+# t.month # => 1
+# t.mday # => 1
+# t.hour # => 0
+# t.min # => 0
+# t.sec # => 0
+# t.subsec # => 0
+#
+# t = Time.new(2000, 12, 31, 23, 59, 59.5)
+# # => 2000-12-31 23:59:59.5 -0600
+# t.year # => 2000
+# t.month # => 12
+# t.mday # => 31
+# t.hour # => 23
+# t.min # => 59
+# t.sec # => 59
+# t.subsec # => (1/2)
+#
+# == Epoch Seconds
+#
+<i>Epoch seconds</i> is the exact number of seconds
+(including fractional subseconds) since the Unix Epoch, January 1, 1970.
+#
+# You can retrieve that value exactly using method Time.to_r:
+#
+# Time.at(0).to_r # => (0/1)
+# Time.at(0.999999).to_r # => (9007190247541737/9007199254740992)
+#
+# Other retrieval methods such as Time#to_i and Time#to_f
+# may return a value that rounds or truncates subseconds.
+#
+# == \Time Resolution
+#
+# A \Time object derived from the system clock
+# (for example, by method Time.now)
+# has the resolution supported by the system.
#
# == Examples
#
@@ -229,7 +259,9 @@ class Time
#
# - A \Time object, whose value is the basis for the returned time;
# also influenced by optional keyword argument +in:+ (see below).
- # - A numeric number of seconds (since the epoch) for the returned time.
+ # - A numeric number of
+ # {Epoch seconds}[rdoc-ref:Time@Epoch+Seconds]
+ # for the returned time.
#
# Examples:
#
@@ -259,7 +291,7 @@ class Time
# Time.at(secs, 1000000, :microsecond) # => 2001-01-01 00:00:00 -0600
# Time.at(secs, -1000000, :microsecond) # => 2000-12-31 23:59:58 -0600
#
- # - +:nsec+ or +:nanosecond+: +subsec+ in nanoseconds:
+ # - +:nanosecond+ or +:nsec+: +subsec+ in nanoseconds:
#
# Time.at(secs, 0, :nanosecond) # => 2000-12-31 23:59:59 -0600
# Time.at(secs, 500000000, :nanosecond) # => 2000-12-31 23:59:59.5 -0600