Struct timemachine::Clock[][src]

pub struct Clock { /* fields omitted */ }

Time range iterator for convenience

Clocks are iterators from a start time to an end time, stepping by a given increment.

Simple clocks can be made with the seconds, minutes, and hours functions. To set a custom step size, use every.

The start can be set as a time with start, or manually with start_h, start_hm, and start_hms.

The end can be set as a time with end, or manually with end_h, end_hm, and end_hms.

The default values for start and end are Time(0, 0, 0) and Time(24, 0, 0), so if you don’t manually set either the clock will iterate from 00:00:00 until 23:59:59 (if stepping by seconds).

use timemachine::Time;
use timemachine::Clock;

let mut clock = Clock::minutes();

assert_eq!(clock.next().unwrap(), Time::new_hms(0, 0, 0));
assert_eq!(clock.next().unwrap(), Time::new_hms(0, 1, 0));
// ...
assert_eq!(clock.last().unwrap(), Time::new_hms(23, 59, 0));
use timemachine::Time;
use timemachine::Clock;

let mut clock = Clock::minutes()
    .start_hms(3, 45, 5)
    .end_hms(4, 37, 0);

assert_eq!(clock.next().unwrap(), Time::new_hms(3, 45, 5));
assert_eq!(clock.next().unwrap(), Time::new_hms(3, 46, 5));
// ...
assert_eq!(clock.last().unwrap(), Time::new_hms(4, 36, 5));

Implementations

impl Clock[src]

pub fn seconds() -> Self[src]

Creates a new clock with a tick rate of 1 second.

use timemachine::Clock;
use timemachine::Time;

let mut clock = Clock::seconds();

assert_eq!(clock.next().unwrap(), Time::midnight());
assert_eq!(clock.next().unwrap(), Time(0, 0, 1));
assert_eq!(clock.next().unwrap(), Time(0, 0, 2));

pub fn minutes() -> Self[src]

Creates a new clock with a tick rate of 1 minute.

use timemachine::Clock;
use timemachine::Time;

let mut clock = Clock::minutes();

assert_eq!(clock.next().unwrap(), Time::midnight());
assert_eq!(clock.next().unwrap(), Time(0, 1, 0));
assert_eq!(clock.next().unwrap(), Time(0, 2, 0));

pub fn hours() -> Self[src]

Creates a new clock with a tick rate of 1 hour.

use timemachine::Clock;
use timemachine::Time;

let mut clock = Clock::hours();

assert_eq!(clock.next().unwrap(), Time::midnight());
assert_eq!(clock.next().unwrap(), Time(1, 0, 0));
assert_eq!(clock.next().unwrap(), Time(2, 0, 0));

pub fn every(hours: u8, minutes: u8, seconds: u8) -> Self[src]

Creates a new clock with a given tick rate.

use timemachine::Clock;
use timemachine::Time;

let mut clock = Clock::every(0, 1, 30);

assert_eq!(clock.next().unwrap(), Time::midnight());
assert_eq!(clock.next().unwrap(), Time(0, 1, 30));
assert_eq!(clock.next().unwrap(), Time(0, 3, 0));

pub fn start(self, time: &Time) -> Self[src]

Builder function to add a start offset to a clock.

use timemachine::Clock;
use timemachine::Time;

let mut clock = Clock::minutes()
    .start(&Time(3, 0, 0));

assert_eq!(clock.next().unwrap(), Time(3, 0, 0));
assert_eq!(clock.next().unwrap(), Time(3, 1, 0));
assert_eq!(clock.next().unwrap(), Time(3, 2, 0));

pub fn start_h(self, hour: u8) -> Self[src]

Builder function to add a start offset in hours to a clock.

use timemachine::Clock;
use timemachine::Time;

let mut clock = Clock::minutes().start_h(3);

assert_eq!(clock.next().unwrap(), Time(3, 0, 0));
assert_eq!(clock.next().unwrap(), Time(3, 1, 0));
assert_eq!(clock.next().unwrap(), Time(3, 2, 0));

pub fn start_hm(self, hour: u8, minute: u8) -> Self[src]

Builder function to add a start offset in hours and minutes to a clock.

use timemachine::Clock;
use timemachine::Time;

let mut clock = Clock::minutes().start_hm(3, 30);

assert_eq!(clock.next().unwrap(), Time(3, 30, 0));
assert_eq!(clock.next().unwrap(), Time(3, 31, 0));
assert_eq!(clock.next().unwrap(), Time(3, 32, 0));

pub fn start_hms(self, hour: u8, minute: u8, second: u8) -> Self[src]

Builder function to add a start offset in hours, minutes, and seconds to a clock.

use timemachine::Clock;
use timemachine::Time;

let mut clock = Clock::minutes().start_hms(3, 30, 54);

assert_eq!(clock.next().unwrap(), Time(3, 30, 54));
assert_eq!(clock.next().unwrap(), Time(3, 31, 54));
assert_eq!(clock.next().unwrap(), Time(3, 32, 54));

pub fn end(self, time: &Time) -> Self[src]

Builder function to add an end time to a clock.

End time is exclusive. The last element of the iterator is the element before the end time.

use timemachine::Clock;
use timemachine::Time;

let mut clock = Clock::minutes()
    .start(&Time(3, 0, 0))
    .end(&Time(4, 0, 0));

assert_eq!(clock.next().unwrap(), Time(3, 0, 0));
assert_eq!(clock.next().unwrap(), Time(3, 1, 0));
// ...
assert_eq!(clock.last().unwrap(), Time(3, 59, 0));

pub fn end_h(self, hour: u8) -> Self[src]

Builder function to add an end time in hours to a clock.

End time is exclusive. The last element of the iterator is the element before the end time.

use timemachine::Clock;
use timemachine::Time;

let mut clock = Clock::minutes().start_h(3).end_h(4);

assert_eq!(clock.next().unwrap(), Time(3, 0, 0));
assert_eq!(clock.next().unwrap(), Time(3, 1, 0));
// ...
assert_eq!(clock.last().unwrap(), Time(3, 59, 0));

pub fn end_hm(self, hour: u8, minute: u8) -> Self[src]

Builder function to add an end time in hours and minutes to a clock.

End time is exclusive. The last element of the iterator is the element before the end time.

use timemachine::Clock;
use timemachine::Time;

let mut clock = Clock::minutes().start_hm(3, 30).end_hm(4, 15);

assert_eq!(clock.next().unwrap(), Time(3, 30, 0));
assert_eq!(clock.next().unwrap(), Time(3, 31, 0));
// ...
assert_eq!(clock.last().unwrap(), Time(4, 14, 0));

pub fn end_hms(self, hour: u8, minute: u8, second: u8) -> Self[src]

Builder function to add an end time in hours, minutes, and seconds to a clock.

End time is exclusive. The last element of the iterator is the element before the end time.

use timemachine::Clock;
use timemachine::Time;

let mut clock = Clock::minutes().start_hms(3, 30, 54).end_hms(4, 15, 25);

assert_eq!(clock.next().unwrap(), Time(3, 30, 54));
assert_eq!(clock.next().unwrap(), Time(3, 31, 54));
// ...
assert_eq!(clock.last().unwrap(), Time(4, 14, 54));

Trait Implementations

impl Iterator for Clock[src]

type Item = Time

The type of the elements being iterated over.

Auto Trait Implementations

impl RefUnwindSafe for Clock

impl Send for Clock

impl Sync for Clock

impl Unpin for Clock

impl UnwindSafe for Clock

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.