Skip to content

Commit 5ca5586

Browse files
authored
Merge pull request #203 from yuankunzhang/refactor-timezone-related-code
refactor: extract timezone functionality from time module to timezone module
2 parents 3eb58ab + 2bc18c5 commit 5ca5586

File tree

5 files changed

+365
-341
lines changed

5 files changed

+365
-341
lines changed

src/items/builder.rs

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

44
use chrono::{DateTime, Datelike, FixedOffset, NaiveDate, TimeZone, Timelike};
55

6-
use super::{date, relative, time, weekday, year};
6+
use super::{date, relative, time, timezone, weekday, year};
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<time::Offset>,
20+
timezone: Option<timezone::Offset>,
2121
relative: Vec<relative::Relative>,
2222
}
2323

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

89-
pub(super) fn set_timezone(mut self, timezone: time::Offset) -> Result<Self, &'static str> {
89+
pub(super) fn set_timezone(mut self, timezone: timezone::Offset) -> Result<Self, &'static str> {
9090
if self.timestamp.is_some() {
9191
return Err("timestamp cannot be combined with other date/time items");
9292
} else if self.timezone.is_some() {
@@ -338,7 +338,7 @@ fn new_date(
338338
/// Restores year, month, day, etc after applying the timezone
339339
/// returns None if timezone overflows the date
340340
fn with_timezone_restore(
341-
offset: time::Offset,
341+
offset: timezone::Offset,
342342
at: DateTime<FixedOffset>,
343343
) -> Option<DateTime<FixedOffset>> {
344344
let offset: FixedOffset = chrono::FixedOffset::try_from(offset).ok()?;

src/items/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub(crate) enum Item {
6464
Time(time::Time),
6565
Weekday(weekday::Weekday),
6666
Relative(relative::Relative),
67-
TimeZone(time::Offset),
67+
TimeZone(timezone::Offset),
6868
Pure(String),
6969
}
7070

src/items/primitive.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ where
132132
.parse_next(input)
133133
}
134134

135+
/// Parse a colon preceded by whitespace
136+
pub(super) fn colon<'a, E>(input: &mut &'a str) -> winnow::Result<(), E>
137+
where
138+
E: ParserError<&'a str>,
139+
{
140+
s(':').void().parse_next(input)
141+
}
142+
135143
/// Create a context error with a reason.
136144
pub(super) fn ctx_err(reason: &'static str) -> ContextError {
137145
let mut err = ContextError::new();

0 commit comments

Comments
 (0)