You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.1 KiB
44 lines
1.1 KiB
use chrono::{DateTime, FixedOffset, Utc};
|
|
|
|
pub const DEFAULT_TIMEZONE_OFFSET: i32 = -6 * 3600;
|
|
|
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
|
pub struct LocalTimestampRange {
|
|
pub start: DateTime<FixedOffset>,
|
|
pub end: DateTime<FixedOffset>,
|
|
}
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
|
pub struct UtcTimestampRange {
|
|
pub start: DateTime<Utc>,
|
|
pub end: DateTime<Utc>,
|
|
}
|
|
|
|
impl From<LocalTimestampRange> for UtcTimestampRange {
|
|
fn from(item: LocalTimestampRange) -> Self {
|
|
Self {
|
|
start: item.start.to_utc(),
|
|
end: item.end.to_utc(),
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// Super naive implementation. Just a quick and dirty to get a string
|
|
pub fn tz_offset_to_string(tz_offset_seconds: i32) -> String {
|
|
if tz_offset_seconds == 3600 * -6 {
|
|
return "Central".to_string();
|
|
}
|
|
else if tz_offset_seconds == 3600 * -5 {
|
|
return "Eastern".to_string();
|
|
}
|
|
else if tz_offset_seconds == 3600 * -7 {
|
|
return "Pacific".to_string();
|
|
}
|
|
else if tz_offset_seconds < 0 {
|
|
return format!("UTC{}", tz_offset_seconds).to_string();
|
|
}
|
|
|
|
format!("UTC+{}", tz_offset_seconds).to_string()
|
|
} |