Search results

There are no results.

std.time.Time

Value
type pub copy Time

A type that represents a point in time (hours, minutes and seconds) without a specific associated date.

Static methods

new

Show source code
Hide source code
fn pub inline static new(
  hour: Int,
  minute: Int,
  second: Int,
  nanosecond: Int,
) -> Option[Time] {
  if
    hour >= 0
      and hour <= 23
      and minute >= 0
      and minute <= 59
      and second >= 0
      and second <= 60
      and nanosecond >= 0
      and nanosecond < 1_000_000_000
  {
    Option.Some(new_unchecked(hour, minute, second, nanosecond))
  } else {
    Option.None
  }
}
fn pub inline static new(hour: Int, minute: Int, second: Int, nanosecond: Int) -> Option[Time]

Returns a new Time, provided the given components are valid.

The arguments must be values in the following ranges:

  • hour: 0 up to and including 23
  • minute: 0 up to and including 59
  • second: 0 up to and including 60
  • nanosecond: 0 up to but excluding 1 000 000 000

If any of the arguments are out of bounds, an Option.None is returned.

The nanosecond argument specifies the number of nanoseconds past the second.

Examples

import std.time (Time)

let time = Time
  .new(hour: 12, minute: 30, second: 0, nanosecond: 0)
  .or_panic('the Time is invalid')

time.hour # => 12

Instance methods

!=

Show source code
Hide source code
fn pub !=(other: ref Self) -> Bool {
  (self == other).false?
}
fn pub !=(other: ref Self) -> Bool

Returns true if self and the given object are not equal to each other.

==

Show source code
Hide source code
fn pub ==(other: Time) -> Bool {
  @bits == other.bits
}
fn pub ==(other: Time) -> Bool

Returns true if self and the given object are equal to each other.

This operator is used to perform structural equality. This means two objects residing in different memory locations may be considered equal, provided their structure is equal. For example, two different arrays may be considered to have structural equality if they contain the exact same values.

fmt

Show source code
Hide source code
fn pub fmt(formatter: mut Formatter) {
  let hour = hour.to_string.pad_start(with: '0', chars: 2)
  let min = minute.to_string.pad_start(with: '0', chars: 2)
  let secs = second.to_string.pad_start(with: '0', chars: 2)
  let sub = nanosecond

  formatter.write('${hour}:${min}:${secs}')

  if sub > 0 {
    formatter.write('.')
    (sub / MICROS_PER_SEC).fmt(formatter)
  }
}
fn pub fmt(formatter: mut Formatter)

Formats self in a human-readable format for debugging purposes.

hour

Show source code
Hide source code
fn pub inline hour -> Int {
  @bits >> 12 & 0x1F
}
fn pub inline hour -> Int

Returns the hour of the day in the range 0 to 23.

minute

Show source code
Hide source code
fn pub inline minute -> Int {
  @bits >> 6 & 0x3F
}
fn pub inline minute -> Int

Returns the minute of the hour in the range 0 to 59.

nanosecond

Show source code
Hide source code
fn pub inline nanosecond -> Int {
  @bits >> 17
}
fn pub inline nanosecond -> Int

Returns the number of nanoseconds after the second.

second

Show source code
Hide source code
fn pub inline second -> Int {
  @bits & 0x3F
}
fn pub inline second -> Int

Returns the number of seconds in the range 0 to 59.

Implemented traits

std.cmp.

Equal

impl Equal for Time
std.fmt.

Format

impl Format for Time