1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
use crate::arithmetic;
use crate::date::*;
use std::convert::TryInto;
use std::str::FromStr;
use tinystr::tinystr8;
#[derive(Debug, Default)]
pub struct MockDateTime {
pub year: i32,
pub month: u32,
pub day: u32,
pub hour: IsoHour,
pub minute: IsoMinute,
pub second: IsoSecond,
}
impl MockDateTime {
pub const fn new(
year: i32,
month: u32,
day: u32,
hour: IsoHour,
minute: IsoMinute,
second: IsoSecond,
) -> Self {
Self {
year,
month,
day,
hour,
minute,
second,
}
}
pub fn try_new(
year: usize,
month: usize,
day: usize,
hour: usize,
minute: usize,
second: usize,
) -> Result<Self, DateTimeError> {
Ok(Self {
year: year.try_into().map_err(|_| DateTimeError::Overflow {
field: "Year",
max: i32::MAX as usize,
})?,
month: month as u32,
day: day as u32,
hour: hour.try_into()?,
minute: minute.try_into()?,
second: second.try_into()?,
})
}
}
impl FromStr for MockDateTime {
type Err = DateTimeError;
fn from_str(input: &str) -> Result<Self, Self::Err> {
let year: i32 = input[0..4].parse()?;
let month: u32 = input[5..7].parse()?;
let day: u32 = input[8..10].parse()?;
let hour: IsoHour = input[11..13].parse()?;
let minute: IsoMinute = input[14..16].parse()?;
let second: IsoSecond = input[17..19].parse()?;
Ok(Self {
year,
month: month - 1,
day: day - 1,
hour,
minute,
second,
})
}
}
impl DateInput for MockDateTime {
fn year(&self) -> Option<Year> {
Some(arithmetic::iso_year_to_gregorian(self.year))
}
fn month(&self) -> Option<Month> {
Some(Month {
number: self.month + 1,
code: MonthCode(tinystr8!("TODO")),
})
}
fn day_of_month(&self) -> Option<DayOfMonth> {
Some(DayOfMonth(self.day + 1))
}
fn iso_weekday(&self) -> Option<IsoWeekday> {
Some(arithmetic::iso_date_to_weekday(
self.year,
self.month as usize,
self.day as usize,
))
}
fn day_of_year_info(&self) -> Option<DayOfYearInfo> {
unimplemented!()
}
}
impl IsoTimeInput for MockDateTime {
fn hour(&self) -> Option<IsoHour> {
Some(self.hour)
}
fn minute(&self) -> Option<IsoMinute> {
Some(self.minute)
}
fn second(&self) -> Option<IsoSecond> {
Some(self.second)
}
fn fraction(&self) -> Option<FractionalSecond> {
None
}
}