pub struct Duration {
/// The underlying seconds of the duration.
seconds: u64,
}
Expand description
A duration of time.
Fields
seconds: u64
The underlying seconds of the duration.
Implementations
A duration of 0 seconds.
Examples
use std::time::Duration;
fn foo() {
let zero_seconds = Duration::ZERO;
assert(zero_seconds.as_seconds() == 0u64);
}
The maximum duration.
Examples
use std::time::Duration;
fn foo() {
let max_duration = Duration::MAX;
assert(max_duration.as_seconds() == u64::MAX);
}
The minimum duration.
Examples
use std::time::Duration;
fn foo() {
let min_duration = Duration::MIN;
assert(min_duration.as_seconds() == u64::MIN);
}
One second of duration.
Examples
use std::time::Duration;
fn foo() {
let 1_second = Duration::SECOND;
assert(1_second.as_seconds() == 1);
}
One minute of duration.
Examples
use std::time::MINUTE;
fn foo() {
let 1_minute = Duration::MINUTE;
assert(1_minute.as_minutes() == 1);
}
One hour of duration.
Examples
use std::time::Duration;
fn foo() {
let 1_hour = Duration::HOUR;
assert(1_hour.as_hours() == 1);
}
One day of duration.
Examples
use std::time::Duration;
fn foo() {
let 1_day = Duration::DAY;
assert(1_day.as_days() == 1);
}
1 week of duration.
Examples
use std::time::Duration;
fn foo() {
let 1_week = Duration::WEEK;
assert(1_week.as_weeks() == 1);
}
pub fn seconds(seconds: u64) -> Self
pub fn seconds(seconds: u64) -> Self
Creates a new Duration
from a number of seconds.
Arguments
seconds
: [u64] - The number of seconds from which to create a duration.
Returns
- [Duration] - A new
Duration
with the specified number of seconds.
Examples
use std::time::Duration;
fn foo() {
let 30_seconds = Duration::seconds(30);
assert(30_seconds.as_seconds() == 30);
}
pub fn minutes(minutes: u64) -> Self
pub fn minutes(minutes: u64) -> Self
Creates a new Duration
from a number of minutes.
Arguments
minutes
: [u64] - The number of minutes from which to create a duration.
Returns
- [Duration] - A new
Duration
with the specified number of minutes.
Examples
use std::time::Duration;
fn foo() {
let 30_minutes = Duration::minutes(30);
assert(30_minutes.as_minutes() == 30);
}
pub fn hours(hours: u64) -> Self
pub fn hours(hours: u64) -> Self
Creates a new Duration
from a number of hours.
Arguments
hours
: [u64] - The number of hours from which to create a duration.
Returns
- [Duration] - A new
Duration
with the specified number of hours.
Examples
use std::time::Duration;
fn foo() {
let 30_hours = Duration::hours(30);
assert(30_hours.as_hours() == 30);
}
pub fn days(days: u64) -> Self
pub fn days(days: u64) -> Self
Creates a new Duration
from a number of days.
Arguments
days
: [u64] - The number of days from which to create a duration.
Returns
- [Duration] - A new
Duration
with the specified number of days.
Examples
use std::time::Duration;
fn foo() {
let 30_days = Duration::days(30);
assert(30_days.as_days() == 30);
}
pub fn weeks(weeks: u64) -> Self
pub fn weeks(weeks: u64) -> Self
Creates a new Duration
from a number of weeks.
Arguments
weeks
: [u64] - The number of weeks from which to create a duration.
Returns
- [Duration] - A new
Duration
with the specified number of weeks.
Examples
use std::time::Duration;
fn foo() {
let 30_weeks = Duration::weeks(30);
assert(30_weeks.as_weeks() == 30);
}
pub fn as_seconds(self) -> u64
pub fn as_seconds(self) -> u64
Returns the number of seconds in a Duration
.
Returns
- [u64] - The number of seconds in a
Duration
.
Examples
use std::time::Duration;
use fn foo() {
let 2_minutes = Duration::minutes(2);
let result_seconds = 2_minutes.as_seconds();
assert(result_seconds == 120);
}
pub fn as_minutes(self) -> u64
pub fn as_minutes(self) -> u64
Returns the number of minutes in a Duration
.
Additional Information
Warning If the duration is not perfectly divisible by a minute, a rounded value is returned.
Returns
- [u64] - The number of minutes in a
Duration
.
Examples
use std::time::Duration;
use fn foo() {
let 2_hours = Duration::hours(2);
let result_minutes = 2_hours.as_minutes();
assert(result_minutes == 120);
}
pub fn as_hours(self) -> u64
pub fn as_hours(self) -> u64
Returns the number of hours in a Duration
.
Additional Information
Warning If the duration is not perfectly divisible by an hour, a rounded value is returned.
Returns
- [u64] - The number of hours in a
Duration
.
Examples
use std::time::Duration;
use fn foo() {
let 2_days = Duration::days(2);
let result_hours = 2_days.as_hours();
assert(result_hours == 48);
}
pub fn as_days(self) -> u64
pub fn as_days(self) -> u64
Returns the number of days in a Duration
.
Additional Information
Warning If the duration is not perfectly divisible by a day, a rounded value is returned.
Returns
- [u64] - The number of days in a
Duration
.
Examples
use std::time::Duration;
use fn foo() {
let 2_weeks = Duration::weeks(2);
let result_days = 2_weeks.as_days();
assert(result_days == 14);
}
pub fn as_weeks(self) -> u64
pub fn as_weeks(self) -> u64
Returns the number of weeks in a Duration
.
Additional Information
Warning If the duration is not perfectly divisible by a week, a rounded value is returned.
Returns
- [u64] - The number of weeks in a
Duration
.
Examples
use std::time::Duration;
use fn foo() {
let 2_weeks = Duration::weeks(2);
let result_weeks = 2_weeks.as_weeks();
assert(result_weeks == 2);
}
pub fn is_zero(self) -> bool
pub fn is_zero(self) -> bool
Returns whether the Duration
is zero seconds.
Returns
- [bool] -
true
if theDuration
is zero, otherwisefalse
.
Examples
use std::time::Duration;
fn foo() {
let zero_duration = Duration::ZERO;
assert(zero_duration.is_zero() == true);
}
Trait Implementations
impl AbiEncode for Duration<>
impl AbiEncode for Duration<>
pub fn abi_encode(self, buffer: Buffer) -> Buffer
impl AbiDecode for Duration<>
impl AbiDecode for Duration<>
pub fn abi_decode(refmut buffer: BufferReader) -> Self
impl PartialEq for Duration
impl PartialEq for Duration
pub fn eq(self, other: Self) -> bool
pub fn neq(self, other: Self) -> bool
pub fn neq(self, other: Self) -> bool
Evaluates if two values of the same type are not equal.
Additional Information
This function is inherited when eq()
is implemented.
Arguments
other
: [Self] - The value of the same type.
Returns
- [bool] -
true
if the two values are not equal, otherwisefalse
.
Examples
struct MyStruct {
val: u64,
}
impl PartialEq for MyStruct {
fn eq(self, other: Self) -> bool {
self.val == other.val
}
}
fn foo() {
let struct1 = MyStruct { val: 10 };
let struct2 = MyStruct { val: 2 };
let result = struct1 != struct2;
assert(result);
}
impl Eq for Duration
impl OrdEq for Duration
impl OrdEq for Duration
pub fn ge(self, other: Self) -> bool
pub fn ge(self, other: Self) -> bool
Evaluates if one value of the same type is greater or equal to than another.
Additional Information
This trait requires that the Ord
and Eq
traits are implemented.
Arguments
other
: [Self] - The value of the same type.
Returns
- [bool] -
true
ifself
is greater than or equal toother
, otherwisefalse
.
Examples
struct MyStruct {
val: u64,
}
impl Eq for MyStruct {
fn eq(self, other: Self) -> bool {
self.val == other.val
}
}
impl Ord for MyStruct {
fn gt(self, other: Self) -> bool {
self.val > other.val
}
}
impl OrdEq for MyStruct {}
fn foo() {
let struct1 = MyStruct { val: 10 };
let struct2 = MyStruct { val: 10 };
let result = struct1 >= struct2;
assert(result);
}
pub fn le(self, other: Self) -> bool
pub fn le(self, other: Self) -> bool
Evaluates if one value of the same type is less or equal to than another.
Additional Information
This trait requires that the Ord
and Eq
traits are implemented.
Arguments
other
: [Self] - The value of the same type.
Returns
- [bool] -
true
ifself
is less than or equal toother
, otherwisefalse
.
Examples
struct MyStruct {
val: u64,
}
impl Eq for MyStruct {
fn eq(self, other: Self) -> bool {
self.val == other.val
}
}
impl Ord for MyStruct {
fn lt(self, other: Self) -> bool {
self.val < other.val
}
}
impl OrdEq for MyStruct {}
fn foo() {
let struct1 = MyStruct { val: 10 };
let struct2 = MyStruct { val: 10 };
let result = struct1 <= struct2;
assert(result);
}