Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/items/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,20 @@ where
O: Uint + FromStr,
E: ParserError<&'a str>,
{
digit1
.void()
.take()
dec_uint_str
.verify_map(|s: &str| s.parse().ok())
.parse_next(input)
}

/// Parse a colon preceded by whitespace
/// Parse an unsigned decimal integer as a string slice.
pub(super) fn dec_uint_str<'a, E>(input: &mut &'a str) -> winnow::Result<&'a str, E>
where
E: ParserError<&'a str>,
{
digit1.void().take().parse_next(input)
}

/// Parse a colon preceded by whitespace.
pub(super) fn colon<'a, E>(input: &mut &'a str) -> winnow::Result<(), E>
where
E: ParserError<&'a str>,
Expand Down
32 changes: 8 additions & 24 deletions src/items/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use winnow::{
use super::{
epoch::sec_and_nsec,
primitive::{colon, ctx_err, dec_uint, s},
timezone::{timezone_num, Offset},
timezone::{timezone_offset, Offset},
};

#[derive(PartialEq, Clone, Debug, Default)]
Expand All @@ -55,7 +55,7 @@ pub(crate) struct Time {
pub(crate) minute: u8,
pub(crate) second: u8,
pub(crate) nanosecond: u32,
pub(crate) offset: Option<Offset>,
pub(super) offset: Option<Offset>,
}

impl TryFrom<Time> for jiff::civil::Time {
Expand Down Expand Up @@ -87,7 +87,7 @@ pub(crate) fn parse(input: &mut &str) -> ModalResult<Time> {
/// Also used by the [`combined`](super::combined) module
pub(super) fn iso(input: &mut &str) -> ModalResult<Time> {
alt((
(hour24, timezone_num).map(|(hour, offset)| Time {
(hour24, timezone_offset).map(|(hour, offset)| Time {
hour,
minute: 0,
second: 0,
Expand All @@ -99,7 +99,7 @@ pub(super) fn iso(input: &mut &str) -> ModalResult<Time> {
colon,
minute,
opt(preceded(colon, second)),
opt(timezone_num),
opt(timezone_offset),
)
.map(|(hour, _, minute, sec_nsec, offset)| Time {
hour,
Expand Down Expand Up @@ -337,11 +337,7 @@ mod tests {
minute: 23,
second: 0,
nanosecond: 0,
offset: Some(Offset {
negative: false,
hours: 5,
minutes: 0,
}),
offset: Some((false, 5, 0).try_into().unwrap()),
};

for mut s in [
Expand All @@ -368,11 +364,7 @@ mod tests {
minute: 45,
second: 0,
nanosecond: 0,
offset: Some(Offset {
negative: false,
hours: 5,
minutes: 35,
}),
offset: Some((false, 5, 35).try_into().unwrap()),
};

for mut s in [
Expand Down Expand Up @@ -401,11 +393,7 @@ mod tests {
minute: 45,
second: 0,
nanosecond: 0,
offset: Some(Offset {
negative: false,
hours: 0,
minutes: 35,
}),
offset: Some((false, 0, 35).try_into().unwrap()),
};

for mut s in [
Expand Down Expand Up @@ -433,11 +421,7 @@ mod tests {
minute: 45,
second: 0,
nanosecond: 0,
offset: Some(Offset {
negative: true,
hours: 5,
minutes: 35,
}),
offset: Some((true, 5, 35).try_into().unwrap()),
};

for mut s in [
Expand Down
Loading
Loading