Struct
struct DateTime
public struct DateTime <: ToString & Hashable & Comparable<DateTime>
Description: Indicates a date-time, which is a time type describing a point of time. It provides functionality such as time zone-based date-time reading, calculation, comparison, and conversion, as well as serialization and deserialization.
-
DateTime is an immutable type that contains date, time, and time zone information. It represents a time range of [-999,999,999-01-01T00:00:00.000000000, 999,999,999-12-31T23:59:59.999999999], which is applicable to any valid time zone.
-
The following lists the system call functions used by the now and nowUTC functions in DateTime to obtain the current time.
System System Call Function Clock Type Linux clock_gettime CLOCK_REALTIME Windows clock_gettime CLOCK_REALTIME macOS clock_gettime CLOCK_REALTIME
Parent Type:
static prop UnixEpoch
public static prop UnixEpoch: DateTime
Description: Obtains the Unix epoch, that is, the DateTime instance that indicates 1970-01-01 00:00:00
in the zero time zone.
Type: DateTime
prop dayOfMonth
public prop dayOfMonth: Int64
Description: Obtains the day of the current month in the DateTime instance.
Type: Int64
prop dayOfWeek
public prop dayOfWeek: DayOfWeek
Description: Obtains the day of the current week in the DateTime instance.
Type: DayOfWeek
prop dayOfYear
public prop dayOfYear: Int64
Description: Obtains the day of the current year in the DateTime instance.
Type: Int64
prop hour
public prop hour: Int64
Description: Obtains the hour information in the DateTime instance.
Type: Int64
prop isoWeek
public prop isoWeek: (Int64, Int64)
Description: Obtains the ISO 8601-compliant year and the number of weeks in the year in the DateTime instance.
prop minute
public prop minute: Int64
Description: Obtains the minute information in the DateTime instance.
Type: Int64
prop month
public prop month: Month
Description: Obtains the month in the DateTime instance.
Type: Month
prop monthValue
public prop monthValue: Int64
Description: Obtains the month represented by a number in the DateTime instance.
Type: Int64
prop nanosecond
public prop nanosecond: Int64
Description: Obtains the nanosecond information in the DateTime instance.
Type: Int64
prop second
public prop second: Int64
Description: Obtains the second information in the DateTime instance.
Type: Int64
prop year
public prop year: Int64
Description: Obtains the year in the DateTime instance.
Type: Int64
prop zone
public prop zone: TimeZone
Description: Obtains the time zone associated with the DateTime instance.
Type: TimeZone
prop zoneId
public prop zoneId: String
Description: Obtains the time zone ID in the TimeZone instance associated with the DateTime instance.
Type: String
prop zoneOffset
public prop zoneOffset: Duration
Description: Obtains the time offset in the TimeZone instance associated with the DateTime instance.
Type: Duration
static func fromUnixTimeStamp(Duration)
public static func fromUnixTimeStamp(d: Duration): DateTime
Description: Obtains the date-time after the time interval specified by the parameter d
since UnixEpoch.
Parameters:
- d: Duration: time interval
Returns:
Throws:
- ArithmeticException: If the result exceeds the date-time range, this exception is thrown.
static func now(TimeZone)
public static func now(timeZone!: TimeZone = TimeZone.Local): DateTime
Description: Obtains the current time of the time zone specified by the parameter timeZone
. The current time obtained using this method is affected by the system time. If timing is not affected by the system time, MonoTime.now() can be used instead.
Parameters:
- timeZone!: TimeZone: time zone, which is the local time zone by default.
Returns:
- DateTime: current time of the specified time zone
static func nowUTC()
public static func nowUTC(): DateTime
Description: Obtains the current time of the UTC time zone. The current time obtained using this method is affected by the system time. If timing is not affected by the system time, MonoTime.now() can be used instead.
Returns:
- DateTime: current time of the UTC time zone
static func of(Int64, Int64, Int64, Int64, Int64, Int64, Int64, TimeZone)
public static func of(
year!: Int64,
month!: Int64,
dayOfMonth!: Int64,
hour!: Int64 = 0,
minute!: Int64 = 0,
second!: Int64 = 0,
nanosecond!: Int64 = 0,
timeZone!: TimeZone = TimeZone.Local
): DateTime
Description: Constructs a DateTime instance based on the year, month, day, hour, minute, second, nanosecond, and time zone specified by parameters.
Parameters:
- year!: Int64: year, in the value range of [-999,999,999, 999,999,999]
- month!: Int64: month, in the value range of [1, 12]
- dayOfMonth!: Int64: day, in the value range of [1, 31]. The maximum value depends on month, which can be 28, 29, 30, or 31.
- hour!: Int64: hour, in the value range of [0, 23]
- minute!: Int64: minute, in the value range of [0, 59]
- second!: Int64: second, in the value range of [0, 59]
- nanosecond!: Int64: nanosecond, in the value range of [0, 999,999,999]
- timeZone!: TimeZone: time zone
Returns:
Throws:
- IllegalArgumentException: If the parameter value exceeds the specified range, this exception is thrown.
static func of(Int64, Month, Int64, Int64, Int64, Int64, Int64, TimeZone)
public static func of(
year!: Int64,
month!: Month,
dayOfMonth!: Int64,
hour!: Int64 = 0,
minute!: Int64 = 0,
second!: Int64 = 0,
nanosecond!: Int64 = 0,
timeZone!: TimeZone = TimeZone.Local
): DateTime
Description: Constructs a DateTime instance based on the year, month, day, hour, minute, second, nanosecond, and time zone specified by parameters.
Parameters:
- year!: Int64: year, in the value range of [-999,999,999, 999,999,999]
- month!: Month: month of the Month type
- dayOfMonth!: Int64: day, in the value range of [1, 31]. The maximum value depends on month, which can be 28, 29, 30, or 31.
- hour!: Int64: hour, in the value range of [0, 23]
- minute!: Int64: minute, in the value range of [0, 59]
- second!: Int64: second, in the value range of [0, 59]
- nanosecond!: Int64: nanosecond, in the value range of [0, 999,999,999]
- timeZone!: TimeZone: time zone
Returns:
Throws:
- IllegalArgumentException: If the parameter value exceeds the specified range, this exception is thrown.
static func ofEpoch(Int64, Int64)
public static func ofEpoch(second!: Int64, nanosecond!: Int64): DateTime
Description: Constructs a DateTime instance based on the input parameters second
and nanosecond
. The input parameter second
indicates the second part of the Unix time, and nanosecond
indicates the nanosecond part of the Unix time. The Unix time counts from UnixEpoch. The value range of nanosecond
cannot exceed [0, 999,999,999]. Otherwise, an exception is thrown.
Parameters:
- second!: Int64: second part of the Unix time
- nanosecond!: Int64: nanosecond part of the Unix time. The value range is [0, 999,999,999].
Returns:
Throws:
- IllegalArgumentException: If the value of
nanosecond
exceeds the specified range, this exception is thrown. - ArithmeticException: If the result exceeds the date-time range, this exception is thrown.
static func ofUTC(Int64, Int64, Int64, Int64, Int64, Int64, Int64)
public static func ofUTC(
year!: Int64,
month!: Int64,
dayOfMonth!: Int64,
hour!: Int64 = 0,
minute!: Int64 = 0,
second!: Int64 = 0,
nanosecond!: Int64 = 0
): DateTime
Description: Constructs a DateTime instance of the UTC
time zone based on the year, month, day, hour, minute, second, nanosecond, and time zone specified by parameters.
Parameters:
- year!: Int64: year, in the value range of [-999,999,999, 999,999,999]
- month!: Int64: month, in the value range of [1, 12]
- dayOfMonth!: Int64: day, in the value range of [1, 31]. The maximum value depends on month, which can be 28, 29, 30, or 31.
- hour!: Int64: hour, in the value range of [0, 23]
- minute!: Int64: minute, in the value range of [0, 59]
- second!: Int64: second, in the value range of [0, 59]
- nanosecond!: Int64: nanosecond, in the value range of [0, 999,999,999]
Returns:
Throws:
- IllegalArgumentException: If the parameter value exceeds the specified range, this exception is thrown.
static func ofUTC(Int64, Month, Int64, Int64, Int64, Int64, Int64)
public static func ofUTC(
year!: Int64,
month!: Month,
dayOfMonth!: Int64,
hour!: Int64 = 0,
minute!: Int64 = 0,
second!: Int64 = 0,
nanosecond!: Int64 = 0
): DateTime
Description: Constructs a DateTime instance of the UTC
time zone based on the year, month, day, hour, minute, second, nanosecond, and time zone specified by parameters.
Parameters:
- year!: Int64: year, in the value range of [-999,999,999, 999,999,999]
- month!: Month: month of the Month type
- dayOfMonth!: Int64: day, in the value range of [1, 31]. The maximum value depends on month, which can be 28, 29, 30, or 31.
- hour!: Int64: hour, in the value range of [0, 23]
- minute!: Int64: minute, in the value range of [0, 59]
- second!: Int64: second, in the value range of [0, 59]
- nanosecond!: Int64: nanosecond, in the value range of [0, 999,999,999]
Returns:
Throws:
- IllegalArgumentException: If the parameter value exceeds the specified range, this exception is thrown.
static func parse(String)
public static func parse(str: String): DateTime
Description: Parses the parameter str
to acquire a time. If the parsing is successful, the DateTime instance is returned.
Parameters:
- str: String: time string, in the format of
date-time
inRFC3339
. It may contain fractional seconds, for example, "2023-04-10T08:00:00[.123456]+08:00" (content in[]
is optional).
Returns:
Throws:
- TimeParseException: If the parsing fails, this exception is thrown.
static func parse(String, String)
public static func parse(str: String, format: String): DateTime
Description: Parses the string str
based on the time format specified by format
to acquire a time. If the parsing is successful, the DateTime instance is returned. For details about the parsing specifications, see "Parsing time from a string."
Parameters:
- str: String: time string, for example, 2023/04/10 08:00:00 +08:00
- format: String: time string format, for example, yyyy/MM/dd HH:mm:ss OOOO For details about the formats, see Time String Formats.
Returns:
- DateTime: DateTime instance parsed from the parameter
str
based on time format specified by the parameterformat
Throws:
- TimeParseException: This exception is thrown if the parsing fails or the same
format
has multiple values. - IllegalArgumentException: If
format
is incorrect, this exception is thrown.
static func parse(String, DateTimeFormat)
public static func parse(str: String, format: DateTimeFormat): DateTime
Description: Parses the string str
based on the time format specified by format
to acquire a time. If the parsing is successful, the DateTime instance is returned. For details about the parsing specifications, see "Parsing time from a string."
Parameters:
- str: String: time string, for example, 2023/04/10 08:00:00 +08:00
- format: DateTimeFormat: time format, for example, a time format corresponding to yyyy/MM/dd HH:mm:ss OOOO For details about the formats, see Time String Formats.
Returns:
- DateTime: DateTime instance parsed from the parameter
str
based on time format specified by the parameterformat
Throws:
- TimeParseException: This exception is thrown if the parsing fails or the same
format
has multiple values. - IllegalArgumentException: If
format
is incorrect, this exception is thrown.
func addDays(Int64)
public func addDays(n: Int64): DateTime
Description: Obtains the time n
days after the DateTime instance, and returns a new DateTime instance.
Parameters:
Returns:
Throws:
- ArithmeticException: If the date-time
n
days after the DateTime instance exceeds a range, this exception is thrown.
func addHours(Int64)
public func addHours(n: Int64): DateTime
Description: Obtains the time n
hours after the DateTime instance, and returns a new DateTime instance.
Parameters:
Returns:
Throws:
- ArithmeticException: If the date-time
n
hours after the DateTime instance exceeds a range, this exception is thrown.
func addMinutes(Int64)
public func addMinutes(n: Int64): DateTime
Description: Obtains the time n
minutes after the DateTime instance, and returns a new DateTime instance.
Parameters:
Returns:
Throws:
- ArithmeticException: If the date-time
n
minutes after the DateTime instance exceeds a range, this exception is thrown.
func addMonths(Int64)
public func addMonths(n: Int64): DateTime
Description: Obtains the time n
months after the DateTime instance, and returns a new DateTime instance.
Note:
The interval between months is not fixed. If dt is set to March 30, 2020,
dt.addMonths(1)
does not return an invalid date March 31, 2020. To ensure that a valid date is returned, the last day of the current month is used, and April 30, 2020 is returned.
Parameters:
Returns:
Throws:
- ArithmeticException: If the date-time
n
months after the DateTime instance exceeds a range, this exception is thrown.
func addNanoseconds(Int64)
public func addNanoseconds(n: Int64): DateTime
Description: Obtains the time n
nanoseconds after the DateTime instance, and returns a new DateTime instance.
Parameters:
Returns:
Throws:
- ArithmeticException: If the date-time
n
nanoseconds after the DateTime instance exceeds a range, this exception is thrown.
func addSeconds(Int64)
public func addSeconds(n: Int64): DateTime
Description: Obtains the time n
seconds after the DateTime instance, and returns a new DateTime instance.
Parameters:
Returns:
Throws:
- ArithmeticException: If the date-time
n
seconds after the DateTime instance exceeds a range, this exception is thrown.
func addWeeks(Int64)
public func addWeeks(n: Int64): DateTime
Description: Obtains the time n
weeks after the DateTime instance, and returns a new DateTime instance.
Parameters:
Returns:
Throws:
Description: Obtains the time n weeks later, and returns a new DateTime instance.
func addYears(Int64)
public func addYears(n: Int64): DateTime
Description: Obtains the time n
years after the DateTime instance, and returns a new DateTime instance.
Note:
The interval between years is not fixed. If dt is set to February 29, 2020,
dt.addYears(1)
does not return an invalid date February 29, 2021. To ensure that a valid date is returned, the last day of the current month is used, and February 28, 2021 is returned.
Parameters:
Returns:
Throws:
- ArithmeticException: If the date-time
n
years after the DateTime instance exceeds a range, this exception is thrown.
func compare(DateTime)
public func compare(rhs: DateTime): Ordering
Description: Compares the value of a DateTime instance with that of the parameter rhs
. If the value of the instance is greater, Ordering.GT is returned. If they are equal, Ordering.EQ is returned. If the value of the instance is smaller, Ordering.LT is returned.
Parameters:
Returns:
func hashCode()
public func hashCode(): Int64
Description: Obtains the hash value of a DateTime instance.
Returns:
- Int64: hash value
func inLocal()
public func inLocal(): DateTime
Description: Obtains the time of the DateTime instance in the local time zone.
Returns:
Throws:
- ArithmeticException: If the date-time specified by the DateTime instance exceeds a range, this exception is thrown.
func inTimeZone(TimeZone)
public func inTimeZone(timeZone: TimeZone): DateTime
Description: Obtains the time of the DateTime instance in the time zone specified by the parameter timeZone
.
Parameters:
- timeZone: TimeZone: target time zone
Returns:
Throws:
- ArithmeticException: If the date-time specified by the DateTime instance exceeds a range, this exception is thrown.
func inUTC()
public func inUTC(): DateTime
Description: Obtains the time of the DateTime instance in the UTC
time zone.
Returns:
Throws:
- ArithmeticException: If the date-time specified by the DateTime instance exceeds a range, this exception is thrown.
func toString()
public func toString(): String
Description: Returns a string indicating a DateTime instance. The string adopts the format of date-time
in RFC3339
. If the time contains nanosecond information (not zero), fractional seconds are returned.
Returns:
func toString(String)
public func toString(format: String): String
Description: Returns a string indicating a DateTime instance. The format is specified by the parameter format
. For details about the formats, see Time String Formats.
Parameters:
- format: String: format of the returned string. The format can be yyyy/MM/dd HH:mm:ss OOOO.
Returns:
Throws:
- IllegalArgumentException: If
format
is incorrect, this exception is thrown.
func toString(DateTimeFormat)
public func toString(format: DateTimeFormat): String
Description: Returns a string indicating a DateTime instance. The format is specified by the parameter format
. For details about the formats, see Time String Formats.
Parameters:
- format: DateTimeFormat: time format. The format can be yyyy/MM/dd HH:mm:ss OOOO.
Returns:
Throws:
- IllegalArgumentException: If
format
is incorrect, this exception is thrown.
func toUnixTimeStamp()
public func toUnixTimeStamp(): Duration
Description: Obtains the time interval between the current instance and UnixEpoch.
Returns:
operator func !=(DateTime)
public operator func !=(r: DateTime): Bool
Description: Checks whether the current DateTime instance is not equal to r
.
If two DateTime instances are not equal, they point to different UTC time.
Parameters:
Returns:
- Bool:
true
orfalse
. If the current DateTime instance is not equal tor
,true
is returned; otherwise,false
is returned.
operator func +(Duration)
public operator func +(r: Duration): DateTime
Description: Implements an addition of the DateTime instance and the Duration instance, that is, DateTime + Duration.
Parameters:
- r: Duration: right operand of the addition
Returns:
Throws:
- ArithmeticException: If the result exceeds the date-time range, this exception is thrown.
operator func -(DateTime)
public operator func -(r: DateTime): Duration
Description: Implements a subtraction between DateTime types, that is, DateTime - DateTime.
Parameters:
- r: DateTime: right operand of the subtraction
Returns:
operator func -(Duration)
public operator func -(r: Duration): DateTime
Description: Implements a subtraction between the DateTime type and the Duration type, that is, DateTime - Duration.
Parameters:
- r: Duration: right operand of the subtraction
Returns:
Throws:
- ArithmeticException: If the result exceeds the date-time range, this exception is thrown.
operator func <(DateTime)
public operator func <(r: DateTime): Bool
Description: Checks whether the current DateTime instance is earlier than r
(the DateTime instance pointing to an earlier UTC time is smaller).
Parameters:
Returns:
- Bool:
true
orfalse
. If the current DateTime instance is earlier thanr
,true
is returned; otherwise,false
is returned.
operator func <=(DateTime)
public operator func <=(r: DateTime): Bool
Description: Checks whether the current DateTime instance is earlier than or equal to r
(the DateTime instance pointing to an earlier UTC time is smaller).
Parameters:
Returns:
- Bool:
true
orfalse
. If the current DateTime instance is earlier than or equal tor
,true
is returned; otherwise,false
is returned.
operator func ==(DateTime)
public operator func ==(r: DateTime): Bool
Description: Checks whether the current DateTime instance is equal to r
.
If two DateTime instances are equal, they point to the same UTC time.
Parameters:
Returns:
- Bool:
true
orfalse
. If the current DateTime instance is equal tor
,true
is returned; otherwise,false
is returned.
operator func >(DateTime)
public operator func >(r: DateTime): Bool
Description: Checks whether the current DateTime instance is later than r
(the DateTime instance pointing to a later UTC time is greater).
Parameters:
Returns:
- Bool:
true
orfalse
. If the current DateTime instance is later thanr
,true
is returned; otherwise,false
is returned.
operator func >=(DateTime)
public operator func >=(r: DateTime): Bool
Description: Checks whether the current DateTime instance is later than or equal to r
(the DateTime instance pointing to a later UTC time is greater).
Parameters:
Returns:
- Bool:
true
orfalse
. If the current DateTime instance is later than or equal tor
,true
is returned; otherwise,false
is returned.
struct Duration
public struct Duration <: ToString & Hashable & Comparable<Duration>
Description: Indicates a time interval, which is a time type describing a period of time. It provides common static instances and functionality such as calculation and comparison.
Notes:
- Duration specifies a range from Duration.Min to Duration.Max, numerically, [-263, 263) in seconds. It is accurate to nanoseconds.
- Duration in each unit of time is represented by an integer. If the actual value is not an integer, the value is rounded up to the smaller absolute value. For example, if the
toHours
method is called on the Duration instance indicating1 hour 30 minutes 46 seconds
, 1 instead of 1.5 or 2 is returned.
Parent Type:
static prop Max
public static prop Max: Duration
Description: Specifies the Duration instance of the maximum time interval.
Type: Duration
static prop Min
public static prop Min: Duration
Description: Specifies the Duration instance of the minimum time interval.
Type: Duration
static prop Zero
public static prop Zero: Duration
Description: Specifies the Duration instance of a 0-nanosecond time interval.
Type: Duration
static prop day
public static prop day: Duration
Description: Specifies the Duration instance of a 1-day time interval.
Type: Duration
static prop hour
public static prop hour: Duration
Description: Specifies the Duration instance of a 1-hour time interval.
Type: Duration
static prop microsecond
public static prop microsecond: Duration
Description: Specifies the Duration instance of a 1-microsecond time interval.
Type: Duration
static prop millisecond
public static prop millisecond: Duration
Description: Specifies the Duration instance of a 1-millisecond time interval.
Type: Duration
static prop minute
public static prop minute: Duration
Description: Specifies the Duration instance of a 1-minute time interval.
Type: Duration
static prop nanosecond
public static prop nanosecond: Duration
Description: Specifies the Duration instance of a 1-nanosecond time interval.
Type: Duration
static prop second
public static prop second: Duration
Description: Specifies the Duration instance of a 1-second time interval.
Type: Duration
static func since(DateTime)
public static func since(t: DateTime): Duration
Description: Calculates the time interval counted from t
to the current time.
Parameters:
Returns:
static func until(DateTime)
public static func until(t: DateTime): Duration
Description: Calculates the time interval counted from the current time to t
.
Parameters:
Returns:
func abs()
public func abs(): Duration
Description: Returns a new Duration instance. Its value is the absolute value of the current Duration instance.
Returns:
Throws:
- ArithmeticException: If the current Duration instance is equal to Duration.Min, this exception is thrown because the absolute value exceeds the range of Duration.
func compare(Duration)
public func compare(rhs: Duration): Ordering
Description: Compares the current Duration instance with another Duration instance. If the current Duration instance is greater, Ordering.GT is returned. If they are equal, Ordering.EQ is returned. If the current Duration instance is smaller, Ordering.LT is returned.
Parameters:
Returns:
func hashCode()
public func hashCode(): Int64
Description: Obtains the hash value of the current Duration instance.
Returns:
func toDays()
public func toDays(): Int64
Description: Obtains the integer value of the current Duration instance, in units of days.
Returns:
func toHours()
public func toHours(): Int64
Description: Obtains the integer value of the current Duration instance, in units of hours.
Returns:
func toMicroseconds()
public func toMicroseconds(): Int64
Description: Obtains the integer value of the current Duration instance, in units of microseconds.
Returns:
Throws:
- ArithmeticException: If the value of the Duration instance in units of microseconds exceeds the range specified by Int64, this exception is thrown.
func toMilliseconds()
public func toMilliseconds(): Int64
Description: Obtains the integer value of the current Duration instance, in units of milliseconds.
Returns:
Throws:
- ArithmeticException: If the value of the Duration instance in units of milliseconds exceeds the range specified by Int64, this exception is thrown.
func toMinutes()
public func toMinutes(): Int64
Description: Obtains the integer value of the current Duration instance, in units of minutes.
Returns:
func toNanoseconds()
public func toNanoseconds(): Int64
Description: Obtains the integer value of the current Duration instance, in units of nanoseconds. The value is rounded up to the smaller absolute value.
Returns:
Throws:
- ArithmeticException: If the value of the Duration instance in units of nanoseconds exceeds the range specified by Int64, this exception is thrown.
func toSeconds()
public func toSeconds(): Int64
Description: Obtains the integer value of the current Duration instance, in units of seconds.
Returns:
func toString()
public func toString(): String
Description: Obtains the string representation of the current Duration instance. For example, "1d2h3m4s5ms6us7ns" indicates 1 day, 2 hours, 3 minutes, 4 seconds, 5 milliseconds, 6 microseconds, and 7 nanoseconds. A unit of time followed by 0 is omitted. Particularly, 0s is returned if all units of time are followed by 0.
Returns:
operator func !=(Duration)
public operator func !=(r: Duration): Bool
Description: Checks whether the current Duration instance is not equal to r
.
Parameters:
Returns:
- Bool:
true
orfalse
. If the current Duration instance is not equal tor
,true
is returned; otherwise,false
is returned.
operator func *(Float64)
public operator func *(r: Float64): Duration
Description: Implements a multiplication of a Duration instance and a Float64 instance, that is, Duration * Float64.
Parameters:
- r: Float64: right operand of the multiplication
Returns:
Throws:
- ArithmeticException: If the result of the multiplication exceeds the range specified by Duration, this exception is thrown.
operator func *(Int64)
public operator func *(r: Int64): Duration
Description: Implements a multiplication of a Duration instance and an Int64 instance, that is, Duration * Int64.
Parameters:
- r: Int64: right operand of the multiplication
Returns:
Throws:
- ArithmeticException: If the result of the multiplication exceeds the range specified by Duration, this exception is thrown.
operator func +(Duration)
public operator func +(r: Duration): Duration
Description: Implements an addition of Duration instances, that is, Duration + Duration.
Parameters:
- r: Duration: right operand of the addition
Returns:
Throws:
- ArithmeticException: If the result of the addition exceeds the range specified by Duration, this exception is thrown.
operator func -(Duration)
public operator func -(r: Duration): Duration
Description: Implements a subtraction between Duration types, that is, Duration - Duration.
Parameters:
- r: Duration: right operand of the subtraction
Returns:
Throws:
- ArithmeticException: If the result of the subtraction exceeds the range specified by Duration, this exception is thrown.
operator func /(Duration)
public operator func /(r: Duration): Float64
Description: Implements a division between Duration instances, that is, Duration / Duration.
Parameters:
- r: Duration: divisor
Returns:
Throws:
- IllegalArgumentException: If
r
is equal to Duration.Zero, this exception is thrown.
operator func /(Float64)
public operator func /(r: Float64): Duration
Description: Implements a division between a Duration instance and a Float64 instance, that is, Duration/Float64.
Parameters:
- r: Float64: divisor
Returns:
Throws:
- IllegalArgumentException: If
r
is 0, this exception is thrown. - ArithmeticException: If the result of the division exceeds the range specified by Duration, this exception is thrown.
operator func /(Int64)
public operator func /(r: Int64): Duration
Description: Implements a division between a Duration instance and an Int64 instance, that is, Duration/Int64.
Parameters:
- r: Int64: divisor
Returns:
Throws:
- IllegalArgumentException: If
r
is 0, this exception is thrown. - ArithmeticException: If the result of the division exceeds the range specified by Duration, this exception is thrown.
operator func <(Duration)
public operator func <(r: Duration): Bool
Description: Checks whether the current Duration instance is less than r
.
Parameters:
Returns:
- Bool:
true
orfalse
. If the current Duration instance is less thanr
,true
is returned; otherwise,false
is returned.
operator func <=(Duration)
public operator func <=(r: Duration): Bool
Description: Checks whether the current Duration instance is less than or equal to r
.
Parameters:
Returns:
- Bool:
true
orfalse
. If the current Duration instance is less than or equal tor
,true
is returned; otherwise,false
is returned.
operator func ==(Duration)
public operator func ==(r: Duration): Bool
Description: Checks whether the current Duration instance is equal to r
.
Parameters:
Returns:
- Bool:
true
orfalse
. If the current Duration instance is equal tor
,true
is returned; otherwise,false
is returned.
operator func >(Duration)
public operator func >(r: Duration): Bool
Description: Checks whether the current Duration instance is greater than r
.
Parameters:
Returns:
- Bool:
true
orfalse
. If the current Duration instance is greater thanr
,true
is returned; otherwise,false
is returned.
operator func >=(Duration)
public operator func >=(r: Duration): Bool
Description: Checks whether the current Duration instance is greater than or equal to r
.
Parameters:
Returns:
- Bool:
true
orfalse
. If the current Duration instance is greater than or equal tor
,true
is returned; otherwise,false
is returned.
struct MonoTime
public struct MonoTime <: Hashable & Comparable<MonoTime>
Description: Indicates monotonic time, which is a time type used to measure the elapsed time. Similar to an ever-running stopwatch, it provides functionality such as obtaining current time, calculation, and comparison.
-
MonoTime specifies a range from Duration.Zero to Duration.Max, numerically, [0, 263) in seconds. It is accurate to nanoseconds. MonoTime created using the now method is always later than MonoTime created earlier using this method. It is usually used for performance tests and time-prioritized task queues.
-
The following lists the system call functions used by the now function in MonoTime to obtain the current time.
System System Call Function Clock Type Linux clock_gettime CLOCK_MONOTONIC Windows clock_gettime CLOCK_MONOTONIC macOS clock_gettime CLOCK_MONOTONIC
Parent Type:
static func now()
public static func now(): MonoTime
Description: Obtains MonoTime corresponding to the current time.
Returns:
func compare(MonoTime)
public func compare(rhs: MonoTime): Ordering
Description: Compares the value of a MonoTime instance with that of the parameter rhs
. If the value of the instance is greater, Ordering.GT is returned. If they are equal, Ordering.EQ is returned. If the value of the instance is smaller, Ordering.LT is returned.
Parameters:
Returns:
func hashCode()
public func hashCode(): Int64
Description: Obtains the hash value of the current MonoTime instance.
Returns:
- Int64: hash value
operator func !=(MonoTime)
public operator func !=(r: MonoTime): Bool
Description: Checks whether the current MonoTime instance is not equal to r
.
Parameters:
- r: MonoTime: monotonic time
Returns:
- Bool:
true
orfalse
. If the current MonoTime instance is not equal tor
,true
is returned; otherwise,false
is returned.
operator func +(Duration)
public operator func +(r: Duration): MonoTime
Description: Implements an addition of the MonoTime instance and the Duration instance, that is, MonoTime + Duration.
Parameters:
- r: Duration: time interval
Returns:
- MonoTime: monotonic time after the time interval specified by the parameter
r
Throws:
- ArithmeticException: If the result exceeds the monotonic time range, this exception is thrown.
operator func -(Duration)
public operator func -(r: Duration): MonoTime
Description: Implements a subtraction between the MonoTime instance and the Duration instance, that is, MonoTime - Duration.
Parameters:
- r: Duration: time interval
Returns:
- MonoTime: monotonic time before the time interval specified by the parameter
r
Throws:
- ArithmeticException: If the result exceeds the monotonic time range, this exception is thrown.
operator func -(MonoTime)
public operator func -(r: MonoTime): Duration
Description: Implements a subtraction between MonoTime instances, that is, MonoTime - MonoTime.
Parameters:
- r: MonoTime: monotonic time
Returns:
- Duration: time elapsed from the current instance to
r
operator func <(MonoTime)
public operator func <(r: MonoTime): Bool
Description: Checks whether the current MonoTime instance is earlier than r
.
Parameters:
- r: MonoTime: monotonic time
Returns:
- Bool:
true
orfalse
. If the current MonoTime instance is earlier thanr
,true
is returned; otherwise,false
is returned.
operator func <=(MonoTime)
public operator func <=(r: MonoTime): Bool
Description: Checks whether the current MonoTime instance is earlier than or equal to r
.
Parameters:
- r: MonoTime: monotonic time
Returns:
- Bool:
true
orfalse
. If the current MonoTime instance is earlier than or equal tor
,true
is returned; otherwise,false
is returned.
operator func ==(MonoTime)
public operator func ==(r: MonoTime): Bool
Description: Checks whether the current MonoTime instance is equal to r
.
Parameters:
- r: MonoTime: monotonic time
Returns:
- Bool:
true
orfalse
. If the current MonoTime instance is equal tor
,true
is returned; otherwise,false
is returned.
operator func >(MonoTime)
public operator func >(r: MonoTime): Bool
Description: Checks whether the current MonoTime instance is later than r
.
Parameters:
- r: MonoTime: monotonic time
Returns:
- Bool:
true
orfalse
. If the current MonoTime instance is later thanr
,true
is returned; otherwise,false
is returned.
operator func >=(MonoTime)
public operator func >=(r: MonoTime): Bool
Description: Checks whether the current MonoTime instance is later than or equal to r
.
Parameters:
- r: MonoTime: monotonic time
Returns: