Struct DeltaTime

Source
pub struct DeltaTime {
    pub hour: Hour12,
    pub minute: Minute,
    pub formal: bool,
}
Expand description

Time expressed as minutes (a delta) past/to an hour.

Traditionally, it supports a minimalist 12-hour format.

use chinese_format::{*, gregorian::*};

let o_clock = DeltaTime {
    hour: 6.try_into()?,
    minute: 0.try_into()?,
    formal: false
};
assert_eq!(o_clock.to_chinese(Variant::Simplified), "六点钟");
assert_eq!(o_clock.to_chinese(Variant::Traditional), "六點鐘");

let past_one = DeltaTime {
    hour: 6.try_into()?,
    minute: 1.try_into()?,
    formal: false
};
assert_eq!(past_one.to_chinese(Variant::Simplified), "六点过一分");
assert_eq!(past_one.to_chinese(Variant::Traditional), "六點過一分");

let past_five = DeltaTime {
    hour: 6.try_into()?,
    minute: 5.try_into()?,
    formal: false
};
assert_eq!(past_five.to_chinese(Variant::Simplified), "六点过五分");
assert_eq!(past_five.to_chinese(Variant::Traditional), "六點過五分");

let past_fourteen = DeltaTime {
    hour: 6.try_into()?,
    minute: 14.try_into()?,
    formal: false
};
assert_eq!(past_fourteen.to_chinese(Variant::Simplified), "六点过十四分");
assert_eq!(past_fourteen.to_chinese(Variant::Traditional), "六點過十四分");

let quarter = DeltaTime {
    hour: 6.try_into()?,
    minute: 15.try_into()?,
    formal: false
};
assert_eq!(quarter.to_chinese(Variant::Simplified), "六点刻");
assert_eq!(quarter.to_chinese(Variant::Traditional), "六點刻");

let past_sixteen = DeltaTime {
    hour: 6.try_into()?,
    minute: 16.try_into()?,
    formal: false
};
assert_eq!(past_sixteen.to_chinese(Variant::Simplified), "六点过十六分");
assert_eq!(past_sixteen.to_chinese(Variant::Traditional), "六點過十六分");

let past_twenty_nine = DeltaTime {
    hour: 6.try_into()?,
    minute: 29.try_into()?,
    formal: false
};
assert_eq!(past_twenty_nine.to_chinese(Variant::Simplified), "六点过二十九分");
assert_eq!(past_twenty_nine.to_chinese(Variant::Traditional), "六點過二十九分");

let half = DeltaTime {
    hour: 6.try_into()?,
    minute: 30.try_into()?,
    formal: false
};
assert_eq!(half.to_chinese(Variant::Simplified), "六点半");
assert_eq!(half.to_chinese(Variant::Traditional), "六點半");

let twenty_nine_to = DeltaTime {
    hour: 6.try_into()?,
    minute: 31.try_into()?,
    formal: false
};
assert_eq!(twenty_nine_to.to_chinese(Variant::Simplified), "七点差二十九分");
assert_eq!(twenty_nine_to.to_chinese(Variant::Traditional), "七點差二十九分");

let sixteen_to = DeltaTime {
    hour: 6.try_into()?,
    minute: 44.try_into()?,
    formal: false
};
assert_eq!(sixteen_to.to_chinese(Variant::Simplified), "七点差十六分");
assert_eq!(sixteen_to.to_chinese(Variant::Traditional), "七點差十六分");

let three_quarters = DeltaTime {
    hour: 6.try_into()?,
    minute: 45.try_into()?,
    formal: false
};
assert_eq!(three_quarters.to_chinese(Variant::Simplified), "六点三刻");
assert_eq!(three_quarters.to_chinese(Variant::Traditional), "六點三刻");

let fourteen_to = DeltaTime {
    hour: 6.try_into()?,
    minute: 46.try_into()?,
    formal: false
};
assert_eq!(fourteen_to.to_chinese(Variant::Simplified), "七点差十四分");
assert_eq!(fourteen_to.to_chinese(Variant::Traditional), "七點差十四分");

let one_to = DeltaTime {
    hour: 6.try_into()?,
    minute: 59.try_into()?,
    formal: false
};
assert_eq!(one_to.to_chinese(Variant::Simplified), "七点差一分");
assert_eq!(one_to.to_chinese(Variant::Traditional), "七點差一分");

In formal style, 差 is placed before the hour expression, while 过 remains at its place:

use chinese_format::{*, gregorian::*};

let past_sixteen = DeltaTime {
    hour: 6.try_into()?,
    minute: 16.try_into()?,
    formal: true
};
assert_eq!(past_sixteen.to_chinese(Variant::Simplified), "六点过十六分");
assert_eq!(past_sixteen.to_chinese(Variant::Traditional), "六點過十六分");


let fourteen_to = DeltaTime {
    hour: 6.try_into()?,
    minute: 46.try_into()?,
    formal: true
};
assert_eq!(fourteen_to.to_chinese(Variant::Simplified), "差十四分七点");
assert_eq!(fourteen_to.to_chinese(Variant::Traditional), "差十四分七點");

Fields§

§hour: Hour12

The hour, as displayed by the hour hand of an analog clock.

§minute: Minute

The minute, as displayed by the minute hand of an analog clock.

§formal: bool

Whether the time should be expressed in a formal way.

Trait Implementations§

Source§

impl ChineseFormat for DeltaTime

Source§

fn to_chinese(&self, variant: Variant) -> Chinese

Source§

impl Clone for DeltaTime

Source§

fn clone(&self) -> DeltaTime

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DeltaTime

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for DeltaTime

Source§

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

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

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

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for DeltaTime

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for DeltaTime

Source§

fn eq(&self, other: &DeltaTime) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for DeltaTime

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for DeltaTime

Source§

impl Eq for DeltaTime

Source§

impl StructuralPartialEq for DeltaTime

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

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

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.