Struct ::exo::Duration

Overview

Duration is the time which has passed between two timepoints.

Methods

fn new() -> Duration

Creates a new empty Duration.

Example

let duration = exo::Duration::new();
assert!(duration.is_zero());
fn is_zero(self) -> bool

Returns true when the duration is zero

Example

let duration = exo::Duration::new();
assert!(duration.is_zero());

Clones the Duration and returns a new independet value.

Example

let dur = exo::Duration::new();
let dur_cloned = dur.clone();
dur += exo::Duration::from_days(1);
assert_ne!(dur, dur_cloned);
fn from_days(days: i64) -> Duration

Create a new Duartion from amount of days.

Example

let duration = exo::Duration::from_days(3);
assert_eq!(duration.whole_days(), 3);
fn from_hours(hours: i64) -> Duration

Create a new Duartion from amount of hours.

Example

let duration = exo::Duration::from_hours(3);
assert_eq!(duration.whole_hours(), 3);
fn from_weeks(weeks: i64) -> Duration

Create a new Duartion from amount of weeks.

Example

let duration = exo::Duration::from_weeks(3);
assert_eq!(duration.whole_weeks(), 3);
fn from_minutes(minutes: i64) -> Duration

Create a new Duartion from amount of minutes.

Example

let duration = exo::Duration::from_minutes(3);
assert_eq!(duration.whole_minutes(), 3);
fn from_seconds(seconds: i64) -> Duration

Create a new Duartion from amount of seconds.

Example

let duration = exo::Duration::from_seconds(3);
assert_eq!(duration.whole_seconds(), 3);
fn from_milliseconds(milliseconds: i64) -> Duration

Create a new Duartion from amount of milliseconds.

Example

let duration = exo::Duration::from_milliseconds(3);
assert_eq!(duration.whole_milliseconds(), 3);

Get the number of whole days from the duration.

Example

let duration = exo::Duration::from_days(3);
assert_eq!(duration.whole_days(), 3);

Get the whole_hours of whole hours from the duration.

Example

let duration = exo::Duration::from_hours(3);
assert_eq!(duration.whole_hours(), 3);

Get the whole_hours of whole weeks from the duration.

Example

let duration = exo::Duration::from_weeks(3);
assert_eq!(duration.whole_weeks(), 3);

Get the whole_hours of whole minutes from the duration.

Example

let duration = exo::Duration::from_minutes(3);
assert_eq!(duration.whole_minutes(), 3);

Get the whole_hours of whole seconds from the duration.

Example

let duration = exo::Duration::from_seconds(3);
assert_eq!(duration.whole_seconds(), 3);

Get the whole_hours of whole milliseconds from the duration.

Example

let duration = exo::Duration::from_milliseconds(3);
assert_eq!(duration.whole_milliseconds(), 3);

Protocols

protocol partial_eq
if value == b { }

Allows for partial equality operations to work.

protocol string_debug
println("{:?}", value)

Allows the value to be debug printed.

protocol string_display
println("{}", value)

Allows the value to be display printed.

protocol add
let output = value + b

Add two durations together.

Example add duration

let one = exo::Duration::from_days(1);
assert_eq!(one + one, exo::Duration::from_days(2));

Example add DateTime

let dt = exo::DateTime::new_epoch();
let one = exo::Duration::from_days(1);
let res = dt + one;
assert_eq!(res.day(), 2);
protocol add_assign
value += b

The add assign operation for Duration.

Example

let duration = exo::Duration::from_days(1);
duration += exo::Duration::from_days(1);
assert_eq!(duration, exo::Duration::from_days(2));
protocol sub
let output = value - b

The sub operation for Duration.

Example

let two = exo::Duration::from_days(2);
let one = exo::Duration::from_days(1);
assert_eq!(two - one, exo::Duration::from_days(1));
protocol sub_assign
value -= b

The sub assign operation for Duration.

Example

let duration = exo::Duration::from_days(2);
duration -= exo::Duration::from_days(1);
assert_eq!(duration, exo::Duration::from_days(1));