You've already forked parse_datetime
mirror of
https://github.com/uutils/parse_datetime.git
synced 2026-06-10 16:13:15 -07:00
Merge pull request #255 from ChrisDryden/fix-tz-prefix-with-base-date
fix: TZ prefix should override base date timezone
This commit is contained in:
@@ -187,9 +187,13 @@ impl DateTimeBuilder {
|
||||
/// - e. Apply final fixed offset if present.
|
||||
pub(super) fn build(self) -> Result<Zoned, error::Error> {
|
||||
// 1. Choose the base instant.
|
||||
let base = match (self.base, &self.timezone) {
|
||||
(Some(b), _) => b,
|
||||
(None, Some(tz)) => jiff::Timestamp::now().to_zoned(tz.clone()),
|
||||
// If a TZ="..." prefix was parsed, it should override the base's timezone
|
||||
// while keeping the base's timestamp for relative date calculations.
|
||||
let has_timezone = self.timezone.is_some();
|
||||
let base = match (self.base, self.timezone) {
|
||||
(Some(b), Some(tz)) => b.timestamp().to_zoned(tz),
|
||||
(Some(b), None) => b,
|
||||
(None, Some(tz)) => jiff::Timestamp::now().to_zoned(tz),
|
||||
(None, None) => Zoned::now(),
|
||||
};
|
||||
|
||||
@@ -204,7 +208,7 @@ impl DateTimeBuilder {
|
||||
|| self.time.is_some()
|
||||
|| self.weekday.is_some()
|
||||
|| self.offset.is_some()
|
||||
|| self.timezone.is_some();
|
||||
|| has_timezone;
|
||||
|
||||
let mut dt = if need_midnight {
|
||||
base.with().time(civil::time(0, 0, 0, 0)).build()?
|
||||
|
||||
Reference in New Issue
Block a user