Lines
60.98 %
Functions
35 %
Branches
100 %
#[derive(Clone, Debug, PartialEq)]
pub struct Duration {
pub(crate) sign: i8,
pub(crate) weeks: Option<u64>,
pub(crate) days: Option<u64>,
pub(crate) hours: Option<u64>,
pub(crate) minutes: Option<u64>,
pub(crate) seconds: Option<u64>,
}
impl Default for Duration {
fn default() -> Self {
Duration {
sign: 1,
weeks: None,
days: None,
hours: None,
minutes: None,
seconds: None,
impl Duration {
pub fn weeks(sign: i8, weeks: u64) -> Self {
sign,
weeks: Some(weeks),
pub fn days(sign: i8, days: u64) -> Self {
days: Some(days),
pub fn days_and_time(sign: i8, days: u64) -> DurationTimeBuilder {
DurationTimeBuilder {
duration: Duration {
},
pub fn hours(sign: i8, hours: u64) -> DurationTimeMinutesBuilder {
DurationTimeMinutesBuilder {
hours: Some(hours),
pub fn minutes(sign: i8, minutes: u64) -> DurationTimeSecondsBuilder {
DurationTimeSecondsBuilder {
minutes: Some(minutes),
pub fn seconds(sign: i8, seconds: u64) -> Self {
seconds: Some(seconds),
pub fn to_std(self) -> (i8, std::time::Duration) {
let secs = self
.weeks
.map(|weeks| weeks * 7 * 24 * 60 * 60)
.unwrap_or(0)
+ self.days.map(|days| days * 24 * 60 * 60).unwrap_or(0)
+ self.hours.map(|hours| hours * 60 * 60).unwrap_or(0)
+ self.minutes.map(|minutes| minutes * 60).unwrap_or(0)
+ self.seconds.unwrap_or(0);
(self.sign, std::time::Duration::from_secs(secs))
pub struct DurationTimeBuilder {
duration: Duration,
impl DurationTimeBuilder {
pub fn hours(mut self, hours: u64) -> DurationTimeMinutesBuilder {
self.duration.hours = Some(hours);
duration: self.duration,
pub fn minutes(mut self, minutes: u64) -> DurationTimeSecondsBuilder {
self.duration.minutes = Some(minutes);
pub fn seconds(mut self, seconds: u64) -> Duration {
self.duration.seconds = Some(seconds);
self.build()
pub fn build(self) -> Duration {
self.duration
pub struct DurationTimeMinutesBuilder {
impl DurationTimeMinutesBuilder {
pub struct DurationTimeSecondsBuilder {
impl DurationTimeSecondsBuilder {