# Struct spinoso_time::Time [−][src]

Implementation of Ruby `Time`

, a timezone-aware datetime, based on
`chrono`

.

`Time`

is represented as:

- a 64-bit signed integer of seconds since January 1, 1970 UTC (a Unix timestamp).
- an unsigned 32-bit integer of nanoseconds since the timestamp.
- An offset from UTC. See
`Offset`

for the types of supported offsets.

This data structure allows representing roughly 584 billion years. Unlike
MRI, there is no promotion to `Bignum`

or `Rational`

. The maximum
granularity of a `Time`

object is nanoseconds.

`Time`

objects are immutable. Date/time value manipulation always returns a
new `Time`

object.

# Examples

// Create a Time to the current system clock with local offset let time = Time::now(); assert!(!time.is_utc()); println!("{}", time.is_sunday());

let time = Time::now(); let one_hour_ago: Time = time - (60 * 60); assert_eq!(time.to_int() - 3600, one_hour_ago.to_int()); assert_eq!(time.nanosecond(), one_hour_ago.nanosecond());

# Implementation notes

Time stores raw timestamps and only converts to `chrono`

`DateTime`

for
computation. `chrono`

provides an aware datetime view over the raw
timestamp.

## Implementations

`impl Time`

[src]

`#[must_use]pub fn new() -> Self`

[src]

Creates a new `Time`

object for the current time with a local offset.

# Examples

use spinoso_time::Time; let now = Time::new();

`#[must_use]pub fn now() -> Self`

[src]

Creates a new `Time`

object for the current time with a local offset.

This is same as `new`

.

# Examples

use spinoso_time::Time; let now = Time::now();

`#[must_use]pub fn at(seconds: i64, sub_second_nanos: i64) -> Option<Self>`

[src]

Creates a new `Time`

object from the `seconds`

and `sub_second_nanos`

since the Unix EPOCH with a local offset.

# Examples

use spinoso_time::Time; let epoch = Time::at(0, 0); let epoch_plus_1_nano = Time::at(0, 1);

`impl Time`

[src]

`#[must_use]pub fn year(self) -> i32`

[src]

Returns the year for *time* (including the century).

# Examples

let now = Time::now(); let year = now.year();

`#[must_use]pub fn month(self) -> u32`

[src]

Returns the month of the year `1..=12`

for *time*.

# Examples

let now = Time::now(); let minute_of_hour = now.minute();

`#[must_use]pub fn day(self) -> u32`

[src]

Returns the day of the month `1..=n`

for *time*.

# Examples

let now = Time::now(); let day_of_month = now.day();

`impl Time`

[src]

`#[must_use]pub fn succ(self) -> Self`

[src]

Returns a new Time object, one second later than time.

This method should log a deprecation warning if `Time::nanosecond`

is
non-zero.

# Examples

let now = Time::now(); let next = now.succ(); assert_eq!(now.to_int() + 1, next.to_int());

`impl Time`

[src]

`#[must_use]pub fn year_day(self) -> u32`

[src]

Returns an integer representing the day of the year, `1..=366`

.

This method returns the date’s ordinal day.

# Examples

let now = Time::now(); let ordinal = now.year_day(); assert!(ordinal > 0); assert!(ordinal <= 366);

`impl Time`

[src]

`#[must_use]pub fn hour(self) -> u32`

[src]

Returns the hour of the day `0..=23`

for *time*.

# Examples

let now = Time::now(); let hour_of_day = now.hour();

`#[must_use]pub fn minute(self) -> u32`

[src]

Returns the minute of the hour `0..=59`

for *time*.

# Examples

let now = Time::now(); let minute_of_hour = now.minute();

`#[must_use]pub fn second(self) -> u32`

[src]

Returns the second of the minute `0..=60`

for *time*.

Seconds range from zero to 60 to allow the system to inject leap seconds.

# Examples

let now = Time::now(); let second_of_minute = now.second(); if second_of_minute >= 60 { // `now` is during a leap second }

`#[must_use]pub const fn microsecond(self) -> u32`

[src]

Returns the number of microseconds for *time*.

This method returns microseconds since the last second (including leap seconds. The range of this value is always from 0 to 999,999.

# Examples

let now = Time::now(); let usec_since_last_second = now.second(); if usec_since_last_second >= 1_000_000 { // `now` is during a leap second }

`#[must_use]pub fn nanosecond(self) -> u32`

[src]

Returns the number of nanoseconds for *time*.

This method returns nanoseconds since the last second (including leap seconds. The range of this value is always from 0 to 999,999,999.

# Examples

let now = Time::now(); let nsec_since_last_second = now.nanosecond();

# Implementation notes

The IEEE 754 double is not accurate enough to represent the exact number
of nanoseconds since the Unix Epoch. `nanosecond`

is
more accurate than `to_float`

.

`#[must_use]pub const fn subsec(self) -> (u32, u32)`

[src]

Returns the fraction for time.

The return value can be a rational number. This result is more accurate
than `to_float`

because IEEE 754 double precision is
not sufficient to losslessly encode nanosecond fractions of seconds.

# Examples

let time = Time::now(); let (sub_second_units, units_per_second) = time.subsec();

# Implementation notes

Time has a maximum granularity of nanoseconds, so in practice this method always returns nanoseconds, but the returned tuple accomodates returning any fractional part, such as millis or micros.

`impl Time`

[src]

`#[must_use]pub fn is_dst(self) -> bool`

[src]

Returns `true`

if *time* occurs during Daylight Saving Time in its time
zone.

# Implementation notes

This function is not implemented and always returns `false`

.

`#[must_use]pub fn is_utc(self) -> bool`

[src]

Returns `true`

if time represents a time in UTC (GMT).

# Examples

let local_time = Time::now(); assert!(!local_time.is_utc()); let utc_time = local_time.to_utc(); assert!(utc_time.is_utc());

`#[must_use]pub const fn to_local(self) -> Self`

[src]

Returns a new `Time`

object representing time in local time (using the
local time zone in effect for this process).

# Examples

let local_time = Time::now(); assert!(!local_time.is_utc()); let local_time2 = local_time.to_local(); assert!(!local_time2.is_utc()); let utc_time = local_time.to_utc(); assert!(utc_time.is_utc());

`#[must_use]pub const fn to_utc(self) -> Self`

[src]

Returns a new `Time`

object representing time in UTC.

# Examples

let local_time = Time::now(); assert!(!local_time.is_utc()); let utc_time = local_time.to_utc(); assert!(utc_time.is_utc()); let utc_time2 = utc_time.to_utc(); assert!(utc_time2.is_utc());

`#[must_use]pub fn timezone(self) -> Option<&'static str>`

[src]

Returns the name of the time zone used for *time*.

`impl Time`

[src]

`#[must_use]pub fn weekday(self) -> u32`

[src]

Returns an integer representing the day of the week, `0..=6`

, with
Sunday == 0.

# Examples

let now = Time::now(); match now { time if time.is_sunday() => assert_eq!(time.weekday(), 0), time if time.is_monday() => assert_eq!(time.weekday(), 1), time if time.is_tuesday() => assert_eq!(time.weekday(), 2), time if time.is_wednesday() => assert_eq!(time.weekday(), 3), time if time.is_thursday() => assert_eq!(time.weekday(), 4), time if time.is_friday() => assert_eq!(time.weekday(), 5), time if time.is_saturday() => assert_eq!(time.weekday(), 6), _ => {} }

`#[must_use]pub fn is_sunday(self) -> bool`

[src]

Returns true if *time* represents Sunday.

# Examples

let now = Time::now(); if now.is_sunday() { // go grocery shopping assert_eq!(now.weekday(), 0); }

`#[must_use]pub fn is_monday(self) -> bool`

[src]

Returns true if *time* represents Monday.

# Examples

let now = Time::now(); if now.is_monday() { // go to work assert_eq!(now.weekday(), 1); }

`#[must_use]pub fn is_tuesday(self) -> bool`

[src]

Returns true if *time* represents Tuesday.

# Examples

let now = Time::now(); if now.is_tuesday() { // go to the gym assert_eq!(now.weekday(), 2); }

`#[must_use]pub fn is_wednesday(self) -> bool`

[src]

Returns true if *time* represents Wednesday.

# Examples

let now = Time::now(); if now.is_wednesday() { // hump day! assert_eq!(now.weekday(), 3); }

`#[must_use]pub fn is_thursday(self) -> bool`

[src]

Returns true if *time* represents Thursday.

# Examples

let now = Time::now(); if now.is_thursday() { // Chinese food delivery for dinner assert_eq!(now.weekday(), 4); }

`#[must_use]pub fn is_friday(self) -> bool`

[src]

Returns true if *time* represents Friday.

# Examples

let now = Time::now(); if now.is_friday() { // TGIF // Friday, Friday, gotta get down assert_eq!(now.weekday(), 5); }

`#[must_use]pub fn is_saturday(self) -> bool`

[src]

Returns true if *time* represents Saturday.

# Examples

let now = Time::now(); if now.is_saturday() { // hike at the lake assert_eq!(now.weekday(), 6); }

`impl Time`

[src]

`#[must_use]pub fn to_float(&self) -> f64`

[src]

Returns the value of *time* as a floating point number of seconds since
the Unix Epoch.

# Examples

let now = Time::now(); let now_f = now.to_float(); let now_i = now.to_int(); assert!(now_i as f64 <= now_f);

# Implementation notes

The IEEE 754 double is not accurate enough to represent the exact number
of subsecond nanoseconds in the `Time`

.

`#[must_use]pub const fn to_int(self) -> i64`

[src]

Returns the value of *time* as an integer number of seconds since the
Unix Epoch.

# Examples

let now = Time::now(); let now_f = now.to_float(); let now_i = now.to_int(); assert!(now_i as f64 <= now_f);

`#[must_use]pub fn to_a(self) -> ToA`

[src]

Serialize a `Time`

into its components as a `ToA`

.

`ToA`

stores a `Time`

as a ten-element struct of time components: [sec,
min, hour, day, month, year, wday, yday, isdst, zone].

The ordering of the properties is important for the Ruby `Time`

API, and is accessible with the `ToA::to_tuple`

method.

# Examples

let now = Time::now(); let to_a = now.to_a(); assert_eq!(to_a.sec, now.second()); assert_eq!(to_a.wday, now.weekday());

## Trait Implementations

`impl Add<Duration> for Time`

[src]

`type Output = Self`

The resulting type after applying the `+`

operator.

`fn add(self, duration: Duration) -> Self::Output`

[src]

`impl Add<Duration> for Time`

[src]

`type Output = Self`

The resulting type after applying the `+`

operator.

`fn add(self, duration: Duration) -> Self::Output`

[src]

`impl Add<f32> for Time`

[src]

`type Output = Self`

The resulting type after applying the `+`

operator.

`fn add(self, seconds: f32) -> Self::Output`

[src]

`impl Add<f64> for Time`

[src]

`type Output = Self`

The resulting type after applying the `+`

operator.

`fn add(self, seconds: f64) -> Self::Output`

[src]

`impl Add<i16> for Time`

[src]

`type Output = Self`

The resulting type after applying the `+`

operator.

`fn add(self, seconds: i16) -> Self::Output`

[src]

`impl Add<i32> for Time`

[src]

`type Output = Self`

The resulting type after applying the `+`

operator.

`fn add(self, seconds: i32) -> Self::Output`

[src]

`impl Add<i64> for Time`

[src]

`type Output = Self`

The resulting type after applying the `+`

operator.

`fn add(self, seconds: i64) -> Self::Output`

[src]

`impl Add<i8> for Time`

[src]

`type Output = Self`

The resulting type after applying the `+`

operator.

`fn add(self, seconds: i8) -> Self::Output`

[src]

`impl Add<u16> for Time`

[src]

`type Output = Self`

The resulting type after applying the `+`

operator.

`fn add(self, seconds: u16) -> Self::Output`

[src]

`impl Add<u32> for Time`

[src]

`type Output = Self`

The resulting type after applying the `+`

operator.

`fn add(self, seconds: u32) -> Self::Output`

[src]

`impl Add<u64> for Time`

[src]

`type Output = Self`

The resulting type after applying the `+`

operator.

`fn add(self, seconds: u64) -> Self::Output`

[src]

`impl Add<u8> for Time`

[src]

`type Output = Self`

The resulting type after applying the `+`

operator.

`fn add(self, seconds: u8) -> Self::Output`

[src]

`impl Clone for Time`

[src]

`impl Copy for Time`

[src]

`impl Debug for Time`

[src]

`impl Default for Time`

[src]

`fn default() -> Self`

[src]

The zero-argument `Time#new`

constructor creates a local time set to
the current system time.

`impl Eq for Time`

[src]

`impl From<DateTime<FixedOffset>> for Time`

[src]

`fn from(time: DateTime<FixedOffset>) -> Self`

[src]

`impl From<DateTime<Local>> for Time`

[src]

`impl From<DateTime<Tz>> for Time`

[src]

`impl From<DateTime<Utc>> for Time`

[src]

`impl From<Time> for ToA`

[src]

`impl Hash for Time`

[src]

`fn hash<H: Hasher>(&self, state: &mut H)`

[src]

`pub fn hash_slice<H>(data: &[Self], state: &mut H) where`

H: Hasher,

1.3.0[src]

H: Hasher,

`impl Ord for Time`

[src]

`fn cmp(&self, other: &Self) -> Ordering`

[src]

`#[must_use]pub fn max(self, other: Self) -> Self`

1.21.0[src]

`#[must_use]pub fn min(self, other: Self) -> Self`

1.21.0[src]

`#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self`

1.50.0[src]

`impl PartialEq<Time> for Time`

[src]

`impl PartialOrd<Time> for Time`

[src]

`fn partial_cmp(&self, other: &Self) -> Option<Ordering>`

[src]

`#[must_use]pub fn lt(&self, other: &Rhs) -> bool`

1.0.0[src]

`#[must_use]pub fn le(&self, other: &Rhs) -> bool`

1.0.0[src]

`#[must_use]pub fn gt(&self, other: &Rhs) -> bool`

1.0.0[src]

`#[must_use]pub fn ge(&self, other: &Rhs) -> bool`

1.0.0[src]

`impl Sub<Duration> for Time`

[src]

`type Output = Self`

The resulting type after applying the `-`

operator.

`fn sub(self, duration: Duration) -> Self::Output`

[src]

`impl Sub<Duration> for Time`

[src]

`type Output = Self`

The resulting type after applying the `-`

operator.

`fn sub(self, duration: Duration) -> Self::Output`

[src]

`impl Sub<Time> for Time`

[src]

`type Output = Self`

The resulting type after applying the `-`

operator.

`fn sub(self, other: Time) -> Self::Output`

[src]

`impl Sub<f32> for Time`

[src]

`type Output = Self`

The resulting type after applying the `-`

operator.

`fn sub(self, seconds: f32) -> Self::Output`

[src]

`impl Sub<f64> for Time`

[src]

`type Output = Self`

The resulting type after applying the `-`

operator.

`fn sub(self, seconds: f64) -> Self::Output`

[src]

`impl Sub<i16> for Time`

[src]

`type Output = Self`

The resulting type after applying the `-`

operator.

`fn sub(self, seconds: i16) -> Self::Output`

[src]

`impl Sub<i32> for Time`

[src]

`type Output = Self`

The resulting type after applying the `-`

operator.

`fn sub(self, seconds: i32) -> Self::Output`

[src]

`impl Sub<i64> for Time`

[src]

`type Output = Self`

The resulting type after applying the `-`

operator.

`fn sub(self, seconds: i64) -> Self::Output`

[src]

`impl Sub<i8> for Time`

[src]

`type Output = Self`

The resulting type after applying the `-`

operator.

`fn sub(self, seconds: i8) -> Self::Output`

[src]

`impl Sub<u16> for Time`

[src]

`type Output = Self`

The resulting type after applying the `-`

operator.

`fn sub(self, seconds: u16) -> Self::Output`

[src]

`impl Sub<u32> for Time`

[src]

`type Output = Self`

The resulting type after applying the `-`

operator.

`fn sub(self, seconds: u32) -> Self::Output`

[src]

`impl Sub<u64> for Time`

[src]

`type Output = Self`

The resulting type after applying the `-`

operator.

`fn sub(self, seconds: u64) -> Self::Output`

[src]

`impl Sub<u8> for Time`

[src]

`type Output = Self`

The resulting type after applying the `-`

operator.

`fn sub(self, seconds: u8) -> Self::Output`

[src]

`impl TryFrom<ToA> for Time`

[src]

## Auto Trait Implementations

`impl RefUnwindSafe for Time`

`impl Send for Time`

`impl Sync for Time`

`impl Unpin for Time`

`impl UnwindSafe for Time`

## Blanket Implementations

`impl<T> Any for T where`

T: 'static + ?Sized,

[src]

T: 'static + ?Sized,

`impl<T> Borrow<T> for T where`

T: ?Sized,

[src]

T: ?Sized,

`impl<T> BorrowMut<T> for T where`

T: ?Sized,

[src]

T: ?Sized,

`pub fn borrow_mut(&mut self) -> &mut T`

[src]

`impl<T> From<T> for T`

[src]

`impl<T, U> Into<U> for T where`

U: From<T>,

[src]

U: From<T>,

`impl<T> ToOwned for T where`

T: Clone,

[src]

T: Clone,

`type Owned = T`

The resulting type after obtaining ownership.

`pub fn to_owned(&self) -> T`

[src]

`pub fn clone_into(&self, target: &mut T)`

[src]

`impl<T, U> TryFrom<U> for T where`

U: Into<T>,

[src]

U: Into<T>,

`type Error = Infallible`

The type returned in the event of a conversion error.

`pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>`

[src]

`impl<T, U> TryInto<U> for T where`

U: TryFrom<T>,

[src]

U: TryFrom<T>,