use chrono::NaiveDateTime;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct TzUtc;
impl TzUtc {
#[inline]
pub fn utcoffset(&self, _dt: NaiveDateTime, _fold: bool) -> i32 {
0
}
#[inline]
pub fn dst(&self, _dt: NaiveDateTime, _fold: bool) -> i32 {
0
}
#[inline]
pub fn tzname(&self, _dt: NaiveDateTime, _fold: bool) -> &str {
"UTC"
}
#[inline]
pub fn is_ambiguous(&self, _dt: NaiveDateTime) -> bool {
false
}
#[inline]
pub fn fromutc(&self, dt: NaiveDateTime) -> NaiveDateTime {
dt
}
}
#[cfg(test)]
mod tests {
use chrono::NaiveDate;
use super::*;
fn dt(y: i32, m: u32, d: u32, h: u32, mi: u32, s: u32) -> NaiveDateTime {
NaiveDate::from_ymd_opt(y, m, d).unwrap().and_hms_opt(h, mi, s).unwrap()
}
#[test]
fn test_utcoffset() {
let tz = TzUtc;
assert_eq!(tz.utcoffset(dt(2024, 6, 15, 12, 0, 0), false), 0);
assert_eq!(tz.utcoffset(dt(2024, 6, 15, 12, 0, 0), true), 0);
}
#[test]
fn test_dst() {
assert_eq!(TzUtc.dst(dt(2024, 1, 1, 0, 0, 0), false), 0);
}
#[test]
fn test_tzname() {
assert_eq!(TzUtc.tzname(dt(2024, 1, 1, 0, 0, 0), false), "UTC");
}
#[test]
fn test_is_ambiguous() {
assert!(!TzUtc.is_ambiguous(dt(2024, 1, 1, 0, 0, 0)));
}
#[test]
fn test_fromutc() {
let dt_val = dt(2024, 6, 15, 12, 0, 0);
assert_eq!(TzUtc.fromutc(dt_val), dt_val);
}
}