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
use crate::Time;
use time::format_description::FormatItem;
use time::formatting::Formattable;
use time::macros::format_description;
pub const SHORT: &[FormatItem<'_>] = format_description!("[year]-[month]-[day]");
impl Time {
pub fn format(&self, format: &(impl Formattable + ?Sized)) -> String {
self.to_time()
.format(&format)
.expect("well-known format into memory never fails")
}
}
impl Time {
fn to_time(self) -> time::OffsetDateTime {
time::OffsetDateTime::from_unix_timestamp(self.seconds_since_unix_epoch as i64)
.expect("always valid unix time")
.replace_offset(time::UtcOffset::from_whole_seconds(self.offset_in_seconds).expect("valid offset"))
}
}