climer/time/builder/
mod.rs1use super::{Time, TimeConversion};
2
3#[derive(TimeConversion)]
4pub struct TimeBuilder {
5 hours: u64,
6 minutes: u64,
7 seconds: u64,
8 milliseconds: u64,
9 nanoseconds: u64,
10}
11
12impl TimeBuilder {
13 pub fn new() -> Self {
14 Self {
15 hours: 0,
16 minutes: 0,
17 seconds: 0,
18 milliseconds: 0,
19 nanoseconds: 0,
20 }
21 }
22
23 pub fn hours(mut self, hours: u64) -> Self {
24 self.hours = 0;
25 self.add_hours(hours);
26 self
27 }
28
29 pub fn minutes(mut self, minutes: u64) -> Self {
30 self.minutes = 0;
31 self.add_minutes(minutes);
32 self
33 }
34
35 pub fn seconds(mut self, seconds: u64) -> Self {
36 self.seconds = 0;
37 self.add_seconds(seconds);
38 self
39 }
40
41 pub fn milliseconds(mut self, milliseconds: u64) -> Self {
42 self.milliseconds = 0;
43 self.add_milliseconds(milliseconds);
44 self
45 }
46
47 pub fn nanoseconds(mut self, nanoseconds: u64) -> Self {
48 self.nanoseconds = 0;
49 self.add_nanoseconds(nanoseconds);
50 self
51 }
52
53 pub fn build(self) -> Time {
54 Time::new(
55 self.hours,
56 self.minutes,
57 self.seconds,
58 self.milliseconds,
59 self.nanoseconds,
60 )
61 }
62}
63
64#[cfg(test)]
65mod tests;