2021-06-05 23:08:54 -04:00
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# Note: A \Time object uses the resolution available on your system clock.
|
|
|
|
#
|
|
|
|
# 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.)
|
|
|
|
#
|
|
|
|
# == Examples
|
|
|
|
#
|
|
|
|
# All of these examples were done using the EST timezone which is GMT-5.
|
|
|
|
#
|
|
|
|
# === Creating a New \Time Instance
|
|
|
|
#
|
|
|
|
# You can create a new instance of Time with Time.new. This will use the
|
|
|
|
# current system time. Time.now is an alias for this. You can also
|
|
|
|
# pass parts of the time to Time.new such as year, month, minute, etc. When
|
|
|
|
# you want to construct a time this way you must pass at least a year. If you
|
|
|
|
# pass the year with nothing else time will default to January 1 of that year
|
|
|
|
# at 00:00:00 with the current system timezone. Here are some examples:
|
|
|
|
#
|
|
|
|
# Time.new(2002) #=> 2002-01-01 00:00:00 -0500
|
|
|
|
# Time.new(2002, 10) #=> 2002-10-01 00:00:00 -0500
|
|
|
|
# Time.new(2002, 10, 31) #=> 2002-10-31 00:00:00 -0500
|
|
|
|
#
|
|
|
|
# You can pass a UTC offset:
|
|
|
|
#
|
|
|
|
# Time.new(2002, 10, 31, 2, 2, 2, "+02:00") #=> 2002-10-31 02:02:02 +0200
|
|
|
|
#
|
|
|
|
# Or a timezone object:
|
|
|
|
#
|
|
|
|
# zone = timezone("Europe/Athens") # Eastern European Time, UTC+2
|
|
|
|
# Time.new(2002, 10, 31, 2, 2, 2, zone) #=> 2002-10-31 02:02:02 +0200
|
|
|
|
#
|
|
|
|
# You can also use Time.local and Time.utc to infer
|
|
|
|
# local and UTC timezones instead of using the current system
|
|
|
|
# setting.
|
|
|
|
#
|
|
|
|
# You can also create a new time using Time.at which takes the number of
|
|
|
|
# seconds (with subsecond) since the {Unix
|
|
|
|
# Epoch}[https://en.wikipedia.org/wiki/Unix_time].
|
|
|
|
#
|
|
|
|
# Time.at(628232400) #=> 1989-11-28 00:00:00 -0500
|
|
|
|
#
|
|
|
|
# === Working with an Instance of \Time
|
|
|
|
#
|
|
|
|
# Once you have an instance of Time there is a multitude of things you can
|
|
|
|
# do with it. Below are some examples. For all of the following examples, we
|
|
|
|
# will work on the assumption that you have done the following:
|
|
|
|
#
|
|
|
|
# t = Time.new(1993, 02, 24, 12, 0, 0, "+09:00")
|
|
|
|
#
|
|
|
|
# Was that a monday?
|
|
|
|
#
|
|
|
|
# t.monday? #=> false
|
|
|
|
#
|
|
|
|
# What year was that again?
|
|
|
|
#
|
|
|
|
# t.year #=> 1993
|
|
|
|
#
|
|
|
|
# Was it daylight savings at the time?
|
|
|
|
#
|
|
|
|
# t.dst? #=> false
|
|
|
|
#
|
|
|
|
# What's the day a year later?
|
|
|
|
#
|
|
|
|
# t + (60*60*24*365) #=> 1994-02-24 12:00:00 +0900
|
|
|
|
#
|
|
|
|
# How many seconds was that since the Unix Epoch?
|
|
|
|
#
|
|
|
|
# t.to_i #=> 730522800
|
|
|
|
#
|
|
|
|
# You can also do standard functions like compare two times.
|
|
|
|
#
|
|
|
|
# t1 = Time.new(2010)
|
|
|
|
# t2 = Time.new(2011)
|
|
|
|
#
|
|
|
|
# t1 == t2 #=> false
|
|
|
|
# t1 == t1 #=> true
|
|
|
|
# t1 < t2 #=> true
|
|
|
|
# t1 > t2 #=> false
|
|
|
|
#
|
|
|
|
# Time.new(2010,10,31).between?(t1, t2) #=> true
|
|
|
|
#
|
|
|
|
# == What's Here
|
|
|
|
#
|
2021-09-13 11:37:15 -04:00
|
|
|
# First, what's elsewhere. \Class \Time:
|
|
|
|
#
|
2022-02-19 01:14:01 -05:00
|
|
|
# - Inherits from {class Object}[rdoc-ref:Object@What-27s+Here].
|
|
|
|
# - Includes {module Comparable}[rdoc-ref:Comparable@What-27s+Here].
|
2021-09-13 11:37:15 -04:00
|
|
|
#
|
|
|
|
# Here, class \Time provides methods that are useful for:
|
2021-06-05 23:08:54 -04:00
|
|
|
#
|
2022-02-19 01:14:01 -05:00
|
|
|
# - {Creating \Time objects}[rdoc-ref:Time@Methods+for+Creating].
|
|
|
|
# - {Fetching \Time values}[rdoc-ref:Time@Methods+for+Fetching].
|
|
|
|
# - {Querying a \Time object}[rdoc-ref:Time@Methods+for+Querying].
|
|
|
|
# - {Comparing \Time objects}[rdoc-ref:Time@Methods+for+Comparing].
|
|
|
|
# - {Converting a \Time object}[rdoc-ref:Time@Methods+for+Converting].
|
|
|
|
# - {Rounding a \Time}[rdoc-ref:Time@Methods+for+Rounding].
|
2021-06-05 23:08:54 -04:00
|
|
|
#
|
|
|
|
# === Methods for Creating
|
|
|
|
#
|
|
|
|
# - ::new: Returns a new time from specified arguments (year, month, etc.),
|
|
|
|
# including an optional timezone value.
|
|
|
|
# - ::local (aliased as ::mktime): Same as ::new, except the
|
|
|
|
# timezone is the local timezone.
|
|
|
|
# - ::utc (aliased as ::gm): Same as ::new, except the timezone is UTC.
|
|
|
|
# - ::at: Returns a new time based on seconds since epoch.
|
|
|
|
# - ::now: Returns a new time based on the current system time.
|
|
|
|
# - #+ (plus): Returns a new time increased by the given number of seconds.
|
2022-02-10 20:30:28 -05:00
|
|
|
# - #- (minus): Returns a new time decreased by the given number of seconds.
|
2021-06-05 23:08:54 -04:00
|
|
|
#
|
|
|
|
# === Methods for Fetching
|
|
|
|
#
|
|
|
|
# - #year: Returns the year of the time.
|
|
|
|
# - #month (aliased as #mon): Returns the month of the time.
|
|
|
|
# - #mday (aliased as #day): Returns the day of the month.
|
|
|
|
# - #hour: Returns the hours value for the time.
|
|
|
|
# - #min: Returns the minutes value for the time.
|
|
|
|
# - #sec: Returns the seconds value for the time.
|
|
|
|
# - #usec (aliased as #tv_usec): Returns the number of microseconds
|
|
|
|
# in the subseconds value of the time.
|
|
|
|
# - #nsec (aliased as #tv_nsec: Returns the number of nanoseconds
|
|
|
|
# in the subsecond part of the time.
|
|
|
|
# - #subsec: Returns the subseconds value for the time.
|
|
|
|
# - #wday: Returns the integer weekday value of the time (0 == Sunday).
|
|
|
|
# - #yday: Returns the integer yearday value of the time (1 == January 1).
|
|
|
|
# - #hash: Returns the integer hash value for the time.
|
|
|
|
# - #utc_offset (aliased as #gmt_offset and #gmtoff): Returns the offset
|
|
|
|
# in seconds between time and UTC.
|
|
|
|
# - #to_f: Returns the float number of seconds since epoch for the time.
|
|
|
|
# - #to_i (aliased as #tv_sec): Returns the integer number of seconds since epoch
|
|
|
|
# for the time.
|
|
|
|
# - #to_r: Returns the Rational number of seconds since epoch for the time.
|
|
|
|
# - #zone: Returns a string representation of the timezone of the time.
|
|
|
|
#
|
|
|
|
# === Methods for Querying
|
|
|
|
#
|
|
|
|
# - #utc? (aliased as #gmt?): Returns whether the time is UTC.
|
|
|
|
# - #dst? (aliased as #isdst): Returns whether the time is DST (daylight saving time).
|
|
|
|
# - #sunday?: Returns whether the time is a Sunday.
|
|
|
|
# - #monday?: Returns whether the time is a Monday.
|
|
|
|
# - #tuesday?: Returns whether the time is a Tuesday.
|
|
|
|
# - #wednesday?: Returns whether the time is a Wednesday.
|
|
|
|
# - #thursday?: Returns whether the time is a Thursday.
|
|
|
|
# - #friday?: Returns whether time is a Friday.
|
|
|
|
# - #saturday?: Returns whether the time is a Saturday.
|
|
|
|
#
|
|
|
|
# === Methods for Comparing
|
|
|
|
#
|
2022-02-10 20:30:28 -05:00
|
|
|
# - #<=>: Compares +self+ to another time.
|
2021-06-05 23:08:54 -04:00
|
|
|
# - #eql?: Returns whether the time is equal to another time.
|
|
|
|
#
|
|
|
|
# === Methods for Converting
|
|
|
|
#
|
|
|
|
# - #asctime (aliased as #ctime): Returns the time as a string.
|
|
|
|
# - #inspect: Returns the time in detail as a string.
|
|
|
|
# - #strftime: Returns the time as a string, according to a given format.
|
|
|
|
# - #to_a: Returns a 10-element array of values from the time.
|
|
|
|
# - #to_s: Returns a string representation of the time.
|
|
|
|
# - #getutc (aliased as #getgm): Returns a new time converted to UTC.
|
|
|
|
# - #getlocal: Returns a new time converted to local time.
|
|
|
|
# - #utc (aliased as #gmtime): Converts time to UTC in place.
|
|
|
|
# - #localtime: Converts time to local time in place.
|
|
|
|
#
|
|
|
|
# === Methods for Rounding
|
|
|
|
#
|
|
|
|
# - #round:Returns a new time with subseconds rounded.
|
|
|
|
# - #ceil: Returns a new time with subseconds raised to a ceiling.
|
|
|
|
# - #floor: Returns a new time with subseconds lowered to a floor.
|
|
|
|
#
|
|
|
|
# == Timezone Argument
|
|
|
|
#
|
|
|
|
# A timezone argument must have +local_to_utc+ and +utc_to_local+
|
|
|
|
# methods, and may have +name+, +abbr+, and +dst?+ methods.
|
|
|
|
#
|
|
|
|
# The +local_to_utc+ method should convert a Time-like object from
|
|
|
|
# the timezone to UTC, and +utc_to_local+ is the opposite. The
|
|
|
|
# result also should be a Time or Time-like object (not necessary to
|
|
|
|
# be the same class). The #zone of the result is just ignored.
|
|
|
|
# Time-like argument to these methods is similar to a Time object in
|
|
|
|
# UTC without subsecond; it has attribute readers for the parts,
|
|
|
|
# e.g. #year, #month, and so on, and epoch time readers, #to_i. The
|
|
|
|
# subsecond attributes are fixed as 0, and #utc_offset, #zone,
|
|
|
|
# #isdst, and their aliases are same as a Time object in UTC.
|
|
|
|
# Also #to_time, #+, and #- methods are defined.
|
|
|
|
#
|
|
|
|
# The +name+ method is used for marshaling. If this method is not
|
|
|
|
# defined on a timezone object, Time objects using that timezone
|
|
|
|
# object can not be dumped by Marshal.
|
|
|
|
#
|
|
|
|
# The +abbr+ method is used by '%Z' in #strftime.
|
|
|
|
#
|
|
|
|
# The +dst?+ method is called with a +Time+ value and should return whether
|
|
|
|
# the +Time+ value is in daylight savings time in the zone.
|
|
|
|
#
|
|
|
|
# === Auto Conversion to Timezone
|
|
|
|
#
|
|
|
|
# At loading marshaled data, a timezone name will be converted to a timezone
|
|
|
|
# object by +find_timezone+ class method, if the method is defined.
|
|
|
|
#
|
|
|
|
# Similarly, that class method will be called when a timezone argument does
|
|
|
|
# not have the necessary methods mentioned above.
|
2021-05-07 22:40:20 -04:00
|
|
|
class Time
|
|
|
|
# Creates a new \Time object from the current system time.
|
|
|
|
# This is the same as Time.new without arguments.
|
|
|
|
#
|
|
|
|
# Time.now # => 2009-06-24 12:39:54 +0900
|
2021-08-23 01:12:21 -04:00
|
|
|
# Time.now(in: '+04:00') # => 2009-06-24 07:39:54 +0400
|
2021-05-07 22:40:20 -04:00
|
|
|
#
|
2022-08-21 12:36:36 -04:00
|
|
|
# For forms of argument +zone+, see
|
2022-08-22 10:14:29 -04:00
|
|
|
# {Timezone Specifiers}[rdoc-ref:timezone_specifiers.rdoc].
|
2021-05-07 22:40:20 -04:00
|
|
|
def self.now(in: nil)
|
2022-01-11 12:10:23 -05:00
|
|
|
Primitive.time_s_now(Primitive.arg!(:in))
|
2021-05-07 22:40:20 -04:00
|
|
|
end
|
2020-12-29 11:55:51 -05:00
|
|
|
|
2022-08-25 14:02:18 -04:00
|
|
|
# Returns a new \Time object based on the given arguments.
|
|
|
|
#
|
|
|
|
# Required argument +time+ may be either of:
|
|
|
|
#
|
|
|
|
# - 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.
|
|
|
|
#
|
|
|
|
# Examples:
|
|
|
|
#
|
|
|
|
# t = Time.new(2000, 12, 31, 23, 59, 59) # => 2000-12-31 23:59:59 -0600
|
|
|
|
# secs = t.to_i # => 978328799
|
|
|
|
# Time.at(secs) # => 2000-12-31 23:59:59 -0600
|
|
|
|
# Time.at(secs + 0.5) # => 2000-12-31 23:59:59.5 -0600
|
|
|
|
# Time.at(1000000000) # => 2001-09-08 20:46:40 -0500
|
|
|
|
# Time.at(0) # => 1969-12-31 18:00:00 -0600
|
|
|
|
# Time.at(-1000000000) # => 1938-04-24 17:13:20 -0500
|
|
|
|
#
|
|
|
|
# Optional numeric argument +subsec+ and optional symbol argument +units+
|
|
|
|
# work together to specify subseconds for the returned time;
|
|
|
|
# argument +units+ specifies the units for +subsec+:
|
|
|
|
#
|
|
|
|
# - +:millisecond+: +subsec+ in milliseconds:
|
2021-05-07 22:40:20 -04:00
|
|
|
#
|
2022-08-25 14:02:18 -04:00
|
|
|
# Time.at(secs, 0, :millisecond) # => 2000-12-31 23:59:59 -0600
|
|
|
|
# Time.at(secs, 500, :millisecond) # => 2000-12-31 23:59:59.5 -0600
|
|
|
|
# Time.at(secs, 1000, :millisecond) # => 2001-01-01 00:00:00 -0600
|
|
|
|
# Time.at(secs, -1000, :millisecond) # => 2000-12-31 23:59:58 -0600
|
2021-05-07 22:40:20 -04:00
|
|
|
#
|
2022-08-25 14:02:18 -04:00
|
|
|
# - +:microsecond+ or +:usec+: +subsec+ in microseconds:
|
2021-05-07 22:40:20 -04:00
|
|
|
#
|
2022-08-25 14:02:18 -04:00
|
|
|
# Time.at(secs, 0, :microsecond) # => 2000-12-31 23:59:59 -0600
|
|
|
|
# Time.at(secs, 500000, :microsecond) # => 2000-12-31 23:59:59.5 -0600
|
|
|
|
# Time.at(secs, 1000000, :microsecond) # => 2001-01-01 00:00:00 -0600
|
|
|
|
# Time.at(secs, -1000000, :microsecond) # => 2000-12-31 23:59:58 -0600
|
2021-05-07 22:40:20 -04:00
|
|
|
#
|
2022-08-25 14:02:18 -04:00
|
|
|
# - +:nsec+ or +:nanosecond+: +subsec+ in nanoseconds:
|
2021-05-07 22:40:20 -04:00
|
|
|
#
|
2022-08-25 14:02:18 -04:00
|
|
|
# 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
|
|
|
|
# Time.at(secs, 1000000000, :nanosecond) # => 2001-01-01 00:00:00 -0600
|
|
|
|
# Time.at(secs, -1000000000, :nanosecond) # => 2000-12-31 23:59:58 -0600
|
2021-05-07 22:40:20 -04:00
|
|
|
#
|
|
|
|
#
|
2022-08-25 14:02:18 -04:00
|
|
|
# Optional keyword argument <tt>+in: zone</tt> specifies the timezone
|
|
|
|
# for the returned time:
|
2021-05-07 22:40:20 -04:00
|
|
|
#
|
2022-08-25 14:02:18 -04:00
|
|
|
# Time.at(secs, in: '+12:00') # => 2001-01-01 17:59:59 +1200
|
|
|
|
# Time.at(secs, in: '-12:00') # => 2000-12-31 17:59:59 -1200
|
2021-05-07 22:40:20 -04:00
|
|
|
#
|
2022-08-25 14:02:18 -04:00
|
|
|
# For the forms of argument +zone+, see
|
|
|
|
# {Timezone Specifiers}[rdoc-ref:timezone_specifiers.rdoc].
|
2021-05-07 22:40:20 -04:00
|
|
|
#
|
2021-11-10 04:14:14 -05:00
|
|
|
def self.at(time, subsec = false, unit = :microsecond, in: nil)
|
2021-11-12 17:44:46 -05:00
|
|
|
if Primitive.mandatory_only?
|
|
|
|
Primitive.time_s_at1(time)
|
|
|
|
else
|
|
|
|
Primitive.time_s_at(time, subsec, unit, Primitive.arg!(:in))
|
|
|
|
end
|
2021-05-07 22:40:20 -04:00
|
|
|
end
|
2020-12-28 07:13:41 -05:00
|
|
|
|
2022-08-25 14:02:18 -04:00
|
|
|
# Returns a new \Time object based on the given arguments,
|
|
|
|
# by default in the local timezone.
|
2020-12-28 07:13:41 -05:00
|
|
|
#
|
2021-04-25 16:51:31 -04:00
|
|
|
# With no positional arguments, returns the value of Time.now:
|
2020-12-28 07:13:41 -05:00
|
|
|
#
|
2022-08-25 14:02:18 -04:00
|
|
|
# Time.new # => 2021-04-24 17:27:46.0512465 -0500
|
|
|
|
#
|
|
|
|
# With one to six arguments, returns a new \Time object
|
|
|
|
# based on the given arguments, in the local timezone.
|
|
|
|
#
|
|
|
|
# Time.new(2000, 1, 2, 3, 4, 5) # => 2000-01-02 03:04:05 -0600
|
|
|
|
#
|
|
|
|
# For the positional arguments (other than +zone+):
|
|
|
|
#
|
|
|
|
# - +year+: Year, with no range limits:
|
|
|
|
#
|
|
|
|
# Time.new(999999999) # => 999999999-01-01 00:00:00 -0600
|
|
|
|
# Time.new(-999999999) # => -999999999-01-01 00:00:00 -0600
|
|
|
|
#
|
|
|
|
# - +month+: Month in range (1..12), or case-insensitive
|
|
|
|
# 3-letter month name:
|
|
|
|
#
|
|
|
|
# Time.new(2000, 1) # => 2000-01-01 00:00:00 -0600
|
|
|
|
# Time.new(2000, 12) # => 2000-12-01 00:00:00 -0600
|
|
|
|
# Time.new(2000, 'jan') # => 2000-01-01 00:00:00 -0600
|
|
|
|
# Time.new(2000, 'JAN') # => 2000-01-01 00:00:00 -0600
|
|
|
|
#
|
|
|
|
# - +mday+: Month day in range(1..31):
|
|
|
|
#
|
|
|
|
# Time.new(2000, 1, 1) # => 2000-01-01 00:00:00 -0600
|
|
|
|
# Time.new(2000, 1, 31) # => 2000-01-31 00:00:00 -0600
|
|
|
|
#
|
|
|
|
# - +hour+: Hour in range (0..23), or 24 if +min+, +sec+, and +usec+
|
|
|
|
# are zero:
|
|
|
|
#
|
|
|
|
# Time.new(2000, 1, 1, 0) # => 2000-01-01 00:00:00 -0600
|
|
|
|
# Time.new(2000, 1, 1, 23) # => 2000-01-01 23:00:00 -0600
|
|
|
|
# Time.new(2000, 1, 1, 24) # => 2000-01-02 00:00:00 -0600
|
|
|
|
#
|
|
|
|
# - +min+: Minute in range (0..59):
|
|
|
|
#
|
|
|
|
# Time.new(2000, 1, 1, 0, 0) # => 2000-01-01 00:00:00 -0600
|
|
|
|
# Time.new(2000, 1, 1, 0, 59) # => 2000-01-01 00:59:00 -0600
|
|
|
|
#
|
|
|
|
# - +sec+: Second in range (0..59), or 60 if +usec+ is zero:
|
|
|
|
#
|
|
|
|
# Time.new(2000, 1, 1, 0, 0, 0) # => 2000-01-01 00:00:00 -0600
|
|
|
|
# Time.new(2000, 1, 1, 0, 0, 59) # => 2000-01-01 00:00:59 -0600
|
|
|
|
# Time.new(2000, 1, 1, 0, 0, 60) # => 2000-01-01 00:01:00 -0600
|
|
|
|
#
|
|
|
|
# These values may be:
|
|
|
|
#
|
|
|
|
# - Integers, as above.
|
|
|
|
# - Numerics convertible to integers:
|
|
|
|
#
|
|
|
|
# Time.new(Float(0.0), Rational(1, 1), 1.0, 0.0, 0.0, 0.0)
|
|
|
|
# # => 0000-01-01 00:00:00 -0600
|
2020-12-28 07:13:41 -05:00
|
|
|
#
|
2022-08-25 14:02:18 -04:00
|
|
|
# - \String integers:
|
2020-12-28 07:13:41 -05:00
|
|
|
#
|
2022-08-25 14:02:18 -04:00
|
|
|
# a = %w[0 1 1 0 0 0]
|
|
|
|
# # => ["0", "1", "1", "0", "0", "0"]
|
|
|
|
# Time.new(*a) # => 0000-01-01 00:00:00 -0600
|
2020-12-28 07:13:41 -05:00
|
|
|
#
|
2022-08-25 14:02:18 -04:00
|
|
|
# When positional argument +zone+ or keyword argument +in:+ is given,
|
|
|
|
# the new \Time object is in the specified timezone.
|
|
|
|
# For the forms of argument +zone+, see
|
|
|
|
# {Timezone Specifiers}[rdoc-ref:timezone_specifiers.rdoc]:
|
2020-12-28 07:13:41 -05:00
|
|
|
#
|
2022-08-25 14:02:18 -04:00
|
|
|
# Time.new(2000, 1, 1, 0, 0, 0, '+12:00')
|
|
|
|
# # => 2000-01-01 00:00:00 +1200
|
|
|
|
# Time.new(2000, 1, 1, 0, 0, 0, in: '-12:00')
|
|
|
|
# # => 2000-01-01 00:00:00 -1200
|
|
|
|
# Time.new(in: '-12:00')
|
|
|
|
# # => 2022-08-23 08:49:26.1941467 -1200
|
2020-12-28 07:13:41 -05:00
|
|
|
#
|
2021-01-13 04:25:07 -05:00
|
|
|
def initialize(year = (now = true), mon = nil, mday = nil, hour = nil, min = nil, sec = nil, zone = nil, in: nil)
|
|
|
|
if zone
|
2021-11-10 13:50:38 -05:00
|
|
|
if Primitive.arg!(:in)
|
2021-01-13 04:25:07 -05:00
|
|
|
raise ArgumentError, "timezone argument given as positional and keyword arguments"
|
|
|
|
end
|
|
|
|
else
|
2021-11-10 13:50:38 -05:00
|
|
|
zone = Primitive.arg!(:in)
|
2021-01-13 04:25:07 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
if now
|
2021-11-10 13:50:38 -05:00
|
|
|
return Primitive.time_init_now(zone)
|
2021-01-13 04:25:07 -05:00
|
|
|
end
|
|
|
|
|
2021-11-10 13:50:38 -05:00
|
|
|
Primitive.time_init_args(year, mon, mday, hour, min, sec, zone)
|
2020-12-28 07:13:41 -05:00
|
|
|
end
|
|
|
|
end
|