Skip to content

Commit 5453d67

Browse files
authored
Merge pull request #231 from yuankunzhang/rename-timezone-to-offset
refactor: rename the timezone module to offset
2 parents 5662a1b + 0c09d5b commit 5453d67

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

src/items/builder.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use jiff::{civil, Span, Zoned};
55

6-
use super::{date, epoch, error, relative, time, timezone, weekday, year, Item};
6+
use super::{date, epoch, error, offset, relative, time, weekday, year, Item};
77

88
/// The builder is used to construct a DateTime object from various components.
99
/// The parser creates a `DateTimeBuilder` object with the parsed components,
@@ -17,7 +17,7 @@ pub(crate) struct DateTimeBuilder {
1717
date: Option<date::Date>,
1818
time: Option<time::Time>,
1919
weekday: Option<weekday::Weekday>,
20-
timezone: Option<timezone::Offset>,
20+
offset: Option<offset::Offset>,
2121
relative: Vec<relative::Relative>,
2222
}
2323

@@ -41,7 +41,7 @@ impl DateTimeBuilder {
4141
} else if self.date.is_some()
4242
|| self.time.is_some()
4343
|| self.weekday.is_some()
44-
|| self.timezone.is_some()
44+
|| self.offset.is_some()
4545
|| !self.relative.is_empty()
4646
{
4747
return Err("timestamp cannot be combined with other date/time items");
@@ -67,7 +67,7 @@ impl DateTimeBuilder {
6767
return Err("timestamp cannot be combined with other date/time items");
6868
} else if self.time.is_some() {
6969
return Err("time cannot appear more than once");
70-
} else if self.timezone.is_some() && time.offset.is_some() {
70+
} else if self.offset.is_some() && time.offset.is_some() {
7171
return Err("time offset and timezone are mutually exclusive");
7272
}
7373

@@ -86,16 +86,16 @@ impl DateTimeBuilder {
8686
Ok(self)
8787
}
8888

89-
pub(super) fn set_timezone(mut self, timezone: timezone::Offset) -> Result<Self, &'static str> {
89+
pub(super) fn set_offset(mut self, timezone: offset::Offset) -> Result<Self, &'static str> {
9090
if self.timestamp.is_some() {
9191
return Err("timestamp cannot be combined with other date/time items");
92-
} else if self.timezone.is_some() {
93-
return Err("timezone cannot appear more than once");
94-
} else if self.time.as_ref().and_then(|t| t.offset.as_ref()).is_some() {
95-
return Err("time offset and timezone are mutually exclusive");
92+
} else if self.offset.is_some()
93+
|| self.time.as_ref().and_then(|t| t.offset.as_ref()).is_some()
94+
{
95+
return Err("time offset cannot appear more than once");
9696
}
9797

98-
self.timezone = Some(timezone);
98+
self.offset = Some(timezone);
9999
Ok(self)
100100
}
101101

@@ -162,7 +162,7 @@ impl DateTimeBuilder {
162162
&& self.date.is_none()
163163
&& self.time.is_none()
164164
&& self.weekday.is_none()
165-
&& self.timezone.is_none()
165+
&& self.offset.is_none()
166166
{
167167
base
168168
} else {
@@ -239,7 +239,7 @@ impl DateTimeBuilder {
239239
})?;
240240
}
241241

242-
if let Some(offset) = self.timezone {
242+
if let Some(offset) = self.offset {
243243
let (offset, hour_adjustment) = offset.normalize();
244244
dt = dt.checked_add(Span::new().hours(hour_adjustment))?;
245245
dt = dt.datetime().to_zoned((&offset).try_into()?)?;
@@ -262,7 +262,7 @@ impl TryFrom<Vec<Item>> for DateTimeBuilder {
262262
Item::Date(d) => builder.set_date(d)?,
263263
Item::Time(t) => builder.set_time(t)?,
264264
Item::Weekday(weekday) => builder.set_weekday(weekday)?,
265-
Item::TimeZone(tz) => builder.set_timezone(tz)?,
265+
Item::Offset(offset) => builder.set_offset(offset)?,
266266
Item::Relative(rel) => builder.push_relative(rel)?,
267267
Item::Pure(pure) => builder.set_pure(pure)?,
268268
}

src/items/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@
2121
//! - [`combined`]
2222
//! - [`date`]
2323
//! - [`epoch`]
24+
//! - [`offset`]
2425
//! - [`pure`]
2526
//! - [`relative`]
2627
//! - [`time`]
27-
//! - [`timezone`]
2828
//! - [`weekday`]
2929
//! - [`year`]
3030
3131
// date and time items
3232
mod combined;
3333
mod date;
3434
mod epoch;
35+
mod offset;
3536
mod pure;
3637
mod relative;
3738
mod time;
38-
mod timezone;
3939
mod weekday;
4040
mod year;
4141

@@ -66,7 +66,7 @@ enum Item {
6666
Time(time::Time),
6767
Weekday(weekday::Weekday),
6868
Relative(relative::Relative),
69-
TimeZone(timezone::Offset),
69+
Offset(offset::Offset),
7070
Pure(String),
7171
}
7272

@@ -231,7 +231,7 @@ fn parse_item(input: &mut &str) -> ModalResult<Item> {
231231
time::parse.map(Item::Time),
232232
relative::parse.map(Item::Relative),
233233
weekday::parse.map(Item::Weekday),
234-
timezone::parse.map(Item::TimeZone),
234+
offset::parse.map(Item::Offset),
235235
pure::parse.map(Item::Pure),
236236
)),
237237
)
@@ -369,7 +369,7 @@ mod tests {
369369
assert!(result
370370
.unwrap_err()
371371
.to_string()
372-
.contains("timezone cannot appear more than once"));
372+
.contains("time offset cannot appear more than once"));
373373

374374
let result = parse(&mut "2025-05-19 abcdef");
375375
assert!(result.is_err());

src/items/timezone.rs renamed to src/items/offset.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// For the full copyright and license information, please view the LICENSE
22
// file that was distributed with this source code.
33

4-
//! Parse a timezone item.
4+
//! Parse an offset item.
55
//!
66
//! From the GNU docs:
77
//!

src/items/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ use winnow::{
4545

4646
use super::{
4747
epoch::sec_and_nsec,
48+
offset::{timezone_offset, Offset},
4849
primitive::{colon, ctx_err, dec_uint, s},
49-
timezone::{timezone_offset, Offset},
5050
};
5151

5252
#[derive(PartialEq, Clone, Debug, Default)]

0 commit comments

Comments
 (0)