Skip to content

Commit

Permalink
simplify local timezone name computation
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxVerevkin committed Nov 14, 2024
1 parent 8e077a4 commit e06651b
Showing 1 changed file with 2 additions and 26 deletions.
28 changes: 2 additions & 26 deletions src/formatting/formatter/datetime.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use chrono::format::{Fixed, Item, StrftimeItems};
use chrono::{DateTime, Datelike, Local, LocalResult, Locale, TimeZone, Timelike};
use chrono::{DateTime, Local, Locale, TimeZone};
use chrono_tz::{OffsetName, Tz};

use std::fmt::Display;
Expand Down Expand Up @@ -117,31 +117,7 @@ impl TimezoneName for Local {
let tz = tz_name
.parse::<Tz>()
.error("Could not parse local timezone")?;

match tz.with_ymd_and_hms(
datetime.year(),
datetime.month(),
datetime.day(),
datetime.hour(),
datetime.minute(),
datetime.second(),
) {
LocalResult::Single(tz_datetime) => Ok(Item::OwnedLiteral(
tz_datetime
.offset()
.abbreviation()
.error("Timezone name unknown")?
.into(),
)),
LocalResult::Ambiguous(..) => {
error!("Timezone is ambiguous");
todo!();
}
LocalResult::None => {
error!("Timezone is none");
todo!();
}
}
Tz::timezone_name(&datetime.with_timezone(&tz)).map(|x| x.to_owned())
}
}

Expand Down

0 comments on commit e06651b

Please sign in to comment.