Skip to content

Commit

Permalink
src: Address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mcronce committed Jun 28, 2023
1 parent 4cf8f8f commit dec01cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ impl Error for ParseError {
}

// to be used in this module and submodules
const OUT_OF_RANGE: ParseError = ParseError(ParseErrorKind::OutOfRange);
pub(crate) const OUT_OF_RANGE: ParseError = ParseError(ParseErrorKind::OutOfRange);
const IMPOSSIBLE: ParseError = ParseError(ParseErrorKind::Impossible);
const NOT_ENOUGH: ParseError = ParseError(ParseErrorKind::NotEnough);
const INVALID: ParseError = ParseError(ParseErrorKind::Invalid);
Expand Down Expand Up @@ -839,7 +839,7 @@ mod parsed;

// due to the size of parsing routines, they are in separate modules.
mod parse;
mod scan;
pub(crate) mod scan;

pub mod strftime;

Expand Down Expand Up @@ -992,15 +992,6 @@ impl FromStr for Weekday {
}
}

/// Parsing a `str` into a `FixedOffset` uses the format [`%z`](./format/strftime/index.html).
impl FromStr for FixedOffset {
type Err = ParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let (_, offset) = scan::timezone_offset(s, scan::colon_or_space)?;
Self::east_opt(offset).ok_or(OUT_OF_RANGE)
}
}

/// Formats single formatting item
#[cfg(feature = "unstable-locales")]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-locales")))]
Expand Down
13 changes: 13 additions & 0 deletions src/offset/fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
use core::fmt;
use core::ops::{Add, Sub};
use std::str::FromStr;

#[cfg(feature = "rkyv")]
use rkyv::{Archive, Deserialize, Serialize};

use super::{LocalResult, Offset, TimeZone};
use crate::format::scan;
use crate::format::OUT_OF_RANGE;
use crate::naive::{NaiveDate, NaiveDateTime, NaiveTime};
use crate::oldtime::Duration as OldDuration;
use crate::DateTime;
use crate::ParseError;
use crate::Timelike;

/// The time zone with fixed offset, from UTC-23:59:59 to UTC+23:59:59.
Expand Down Expand Up @@ -113,6 +117,15 @@ impl FixedOffset {
}
}

/// Parsing a `str` into a `FixedOffset` uses the format [`%z`](crate::format::strftime).
impl FromStr for FixedOffset {
type Err = ParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let (_, offset) = scan::timezone_offset(s, scan::colon_or_space)?;
Self::east_opt(offset).ok_or(OUT_OF_RANGE)
}
}

impl TimeZone for FixedOffset {
type Offset = FixedOffset;

Expand Down

0 comments on commit dec01cc

Please sign in to comment.