diff --git a/src/items/builder.rs b/src/items/builder.rs index 060be9b..da74e84 100644 --- a/src/items/builder.rs +++ b/src/items/builder.rs @@ -3,7 +3,7 @@ use jiff::{civil, Span, Zoned}; -use super::{date, epoch, error, relative, time, timezone, weekday, year, Item}; +use super::{date, epoch, error, offset, relative, time, weekday, year, Item}; /// The builder is used to construct a DateTime object from various components. /// The parser creates a `DateTimeBuilder` object with the parsed components, @@ -17,7 +17,7 @@ pub(crate) struct DateTimeBuilder { date: Option, time: Option, weekday: Option, - timezone: Option, + offset: Option, relative: Vec, } @@ -41,7 +41,7 @@ impl DateTimeBuilder { } else if self.date.is_some() || self.time.is_some() || self.weekday.is_some() - || self.timezone.is_some() + || self.offset.is_some() || !self.relative.is_empty() { return Err("timestamp cannot be combined with other date/time items"); @@ -67,7 +67,7 @@ impl DateTimeBuilder { return Err("timestamp cannot be combined with other date/time items"); } else if self.time.is_some() { return Err("time cannot appear more than once"); - } else if self.timezone.is_some() && time.offset.is_some() { + } else if self.offset.is_some() && time.offset.is_some() { return Err("time offset and timezone are mutually exclusive"); } @@ -86,16 +86,16 @@ impl DateTimeBuilder { Ok(self) } - pub(super) fn set_timezone(mut self, timezone: timezone::Offset) -> Result { + pub(super) fn set_offset(mut self, timezone: offset::Offset) -> Result { if self.timestamp.is_some() { return Err("timestamp cannot be combined with other date/time items"); - } else if self.timezone.is_some() { - return Err("timezone cannot appear more than once"); - } else if self.time.as_ref().and_then(|t| t.offset.as_ref()).is_some() { - return Err("time offset and timezone are mutually exclusive"); + } else if self.offset.is_some() + || self.time.as_ref().and_then(|t| t.offset.as_ref()).is_some() + { + return Err("time offset cannot appear more than once"); } - self.timezone = Some(timezone); + self.offset = Some(timezone); Ok(self) } @@ -162,7 +162,7 @@ impl DateTimeBuilder { && self.date.is_none() && self.time.is_none() && self.weekday.is_none() - && self.timezone.is_none() + && self.offset.is_none() { base } else { @@ -239,7 +239,7 @@ impl DateTimeBuilder { })?; } - if let Some(offset) = self.timezone { + if let Some(offset) = self.offset { let (offset, hour_adjustment) = offset.normalize(); dt = dt.checked_add(Span::new().hours(hour_adjustment))?; dt = dt.datetime().to_zoned((&offset).try_into()?)?; @@ -262,7 +262,7 @@ impl TryFrom> for DateTimeBuilder { Item::Date(d) => builder.set_date(d)?, Item::Time(t) => builder.set_time(t)?, Item::Weekday(weekday) => builder.set_weekday(weekday)?, - Item::TimeZone(tz) => builder.set_timezone(tz)?, + Item::Offset(offset) => builder.set_offset(offset)?, Item::Relative(rel) => builder.push_relative(rel)?, Item::Pure(pure) => builder.set_pure(pure)?, } diff --git a/src/items/mod.rs b/src/items/mod.rs index 30818a2..d6f9cfe 100644 --- a/src/items/mod.rs +++ b/src/items/mod.rs @@ -21,10 +21,10 @@ //! - [`combined`] //! - [`date`] //! - [`epoch`] +//! - [`offset`] //! - [`pure`] //! - [`relative`] //! - [`time`] -//! - [`timezone`] //! - [`weekday`] //! - [`year`] @@ -32,10 +32,10 @@ mod combined; mod date; mod epoch; +mod offset; mod pure; mod relative; mod time; -mod timezone; mod weekday; mod year; @@ -66,7 +66,7 @@ enum Item { Time(time::Time), Weekday(weekday::Weekday), Relative(relative::Relative), - TimeZone(timezone::Offset), + Offset(offset::Offset), Pure(String), } @@ -231,7 +231,7 @@ fn parse_item(input: &mut &str) -> ModalResult { time::parse.map(Item::Time), relative::parse.map(Item::Relative), weekday::parse.map(Item::Weekday), - timezone::parse.map(Item::TimeZone), + offset::parse.map(Item::Offset), pure::parse.map(Item::Pure), )), ) @@ -369,7 +369,7 @@ mod tests { assert!(result .unwrap_err() .to_string() - .contains("timezone cannot appear more than once")); + .contains("time offset cannot appear more than once")); let result = parse(&mut "2025-05-19 abcdef"); assert!(result.is_err()); diff --git a/src/items/timezone.rs b/src/items/offset.rs similarity index 99% rename from src/items/timezone.rs rename to src/items/offset.rs index dcd0604..fe92b0f 100644 --- a/src/items/timezone.rs +++ b/src/items/offset.rs @@ -1,7 +1,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -//! Parse a timezone item. +//! Parse an offset item. //! //! From the GNU docs: //! diff --git a/src/items/time.rs b/src/items/time.rs index bbad9a8..777ca5e 100644 --- a/src/items/time.rs +++ b/src/items/time.rs @@ -45,8 +45,8 @@ use winnow::{ use super::{ epoch::sec_and_nsec, + offset::{timezone_offset, Offset}, primitive::{colon, ctx_err, dec_uint, s}, - timezone::{timezone_offset, Offset}, }; #[derive(PartialEq, Clone, Debug, Default)]