pub struct HumanReadableDuration { /* private fields */ }Expand description
A data structure for parsing and managing a human readable duration representation
Trait Implementations§
Source§impl AsDays for HumanReadableDuration
impl AsDays for HumanReadableDuration
Source§impl AsDuration for HumanReadableDuration
impl AsDuration for HumanReadableDuration
Source§fn as_duration(&self) -> Duration
fn as_duration(&self) -> Duration
Convert the object to a chrono::Duration representation.
§Example
use std::str::FromStr;
use human_readable_time::HumanReadableDuration;
use human_readable_time::traits::AsDuration;
let duration = HumanReadableDuration::from_str("65m").unwrap();
assert_eq!(3900, duration.as_duration().num_seconds());
assert_eq!(1, duration.as_duration().num_hours());Source§impl AsHours for HumanReadableDuration
impl AsHours for HumanReadableDuration
Source§impl AsMinutes for HumanReadableDuration
impl AsMinutes for HumanReadableDuration
Source§fn as_minutes(&self) -> u64
fn as_minutes(&self) -> u64
Get the duration time in full minutes
§Example
use std::str::FromStr;
use human_readable_time::HumanReadableDuration;
use human_readable_time::traits::AsMinutes;
let duration = HumanReadableDuration::from_str("65s");
assert_eq!(1, duration.unwrap().as_minutes());Source§impl AsSeconds for HumanReadableDuration
impl AsSeconds for HumanReadableDuration
Source§fn as_seconds(&self) -> u64
fn as_seconds(&self) -> u64
Get the duration time in seconds
§Example
use std::str::FromStr;
use human_readable_time::HumanReadableDuration;
use human_readable_time::traits::AsSeconds;
let duration = HumanReadableDuration::from_str("10s");
assert_eq!(10, duration.unwrap().as_seconds());Source§impl From<u16> for HumanReadableDuration
Used to do value-to-value conversions while consuming the input value. It is the reciprocal of
Into.
impl From<u16> for HumanReadableDuration
Used to do value-to-value conversions while consuming the input value. It is the reciprocal of
Into.
Source§fn from(value: u16) -> Self
fn from(value: u16) -> Self
Create an instance for HumanReadableDuration from a u16 field representing the seconds
§Example
use human_readable_time::HumanReadableDuration;
use human_readable_time::traits::{AsMinutes, AsSeconds};
let seconds: u16 = 300;
let representation = HumanReadableDuration::from(seconds);
assert_eq!(300, representation.as_seconds());
assert_eq!(5, representation.as_minutes());Source§impl From<u32> for HumanReadableDuration
Used to do value-to-value conversions while consuming the input value. It is the reciprocal of
Into.
impl From<u32> for HumanReadableDuration
Used to do value-to-value conversions while consuming the input value. It is the reciprocal of
Into.
Source§fn from(value: u32) -> Self
fn from(value: u32) -> Self
Create an instance for HumanReadableDuration from a u32 field representing the seconds
§Example
use human_readable_time::HumanReadableDuration;
use human_readable_time::traits::{AsMinutes, AsSeconds};
let seconds: u32 = 300;
let representation = HumanReadableDuration::from(seconds);
assert_eq!(300, representation.as_seconds());
assert_eq!(5, representation.as_minutes());Source§impl From<u64> for HumanReadableDuration
Used to do value-to-value conversions while consuming the input value. It is the reciprocal of
Into.
impl From<u64> for HumanReadableDuration
Used to do value-to-value conversions while consuming the input value. It is the reciprocal of
Into.
Source§fn from(value: u64) -> Self
fn from(value: u64) -> Self
Create an instance for HumanReadableDuration from a u64 field representing the seconds
§Example
use human_readable_time::HumanReadableDuration;
use human_readable_time::traits::{AsMinutes, AsSeconds};
let seconds: u64 = 300;
let representation = HumanReadableDuration::from(seconds);
assert_eq!(300, representation.as_seconds());
assert_eq!(5, representation.as_minutes());Source§impl From<u8> for HumanReadableDuration
Used to do value-to-value conversions while consuming the input value. It is the reciprocal of
Into.
impl From<u8> for HumanReadableDuration
Used to do value-to-value conversions while consuming the input value. It is the reciprocal of
Into.
Source§fn from(value: u8) -> Self
fn from(value: u8) -> Self
Create an instance for HumanReadableDuration from a u8 field representing the seconds
§Example
use human_readable_time::HumanReadableDuration;
use human_readable_time::traits::{AsMinutes, AsSeconds};
let seconds: u8 = 120;
let representation = HumanReadableDuration::from(seconds);
assert_eq!(120, representation.as_seconds());
assert_eq!(2, representation.as_minutes());Source§impl FromStr for HumanReadableDuration
Parse a value from a string
impl FromStr for HumanReadableDuration
Parse a value from a string
FromStr’s from_str method is often used implicitly, through
str’s parse method. See parse’s documentation for examples.
Source§fn from_str(value: &str) -> Result<Self, Self::Err>
fn from_str(value: &str) -> Result<Self, Self::Err>
Parses a string s to return a value of the HumanReadableDuration type.
If parsing succeeds, return the value inside Ok, otherwise
when the string is ill-formatted return an error specific to the
inside Err.
§Examples
use std::str::FromStr;
use human_readable_time::HumanReadableDuration;
use human_readable_time::traits::AsSeconds;
let s = "50s";
let x = HumanReadableDuration::from_str(s).unwrap();
assert_eq!(50, x.as_seconds());