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 timestamp item.
5+ //!
46//! From the GNU docs:
57//!
68//! > If you precede a number with ‘@’, it represents an internal timestamp as
@@ -22,7 +24,7 @@ use winnow::{
2224 ModalResult , Parser ,
2325} ;
2426
25- use super :: primitive:: { dec_uint, s} ;
27+ use super :: primitive:: { dec_uint, plus_or_minus , s} ;
2628
2729/// Represents a timestamp with nanosecond accuracy.
2830///
@@ -43,7 +45,7 @@ impl TryFrom<Timestamp> for jiff::Timestamp {
4345 fn try_from ( ts : Timestamp ) -> Result < Self , Self :: Error > {
4446 jiff:: Timestamp :: new (
4547 ts. second ,
46- i32:: try_from ( ts. nanosecond ) . map_err ( |_| "nanosecond value exceeds i32::MAX" ) ?,
48+ i32:: try_from ( ts. nanosecond ) . map_err ( |_| "nanosecond in timestamp exceeds i32::MAX" ) ?,
4749 )
4850 . map_err ( |_| "timestamp value is out of valid range" )
4951 }
@@ -52,7 +54,7 @@ impl TryFrom<Timestamp> for jiff::Timestamp {
5254/// Parse a timestamp in the form of `@1234567890` or `@-1234567890.12345` or
5355/// `@1234567890,12345`.
5456pub ( super ) fn parse ( input : & mut & str ) -> ModalResult < Timestamp > {
55- ( s ( "@" ) , opt ( s ( one_of ( [ '-' , '+' ] ) ) ) , sec_and_nsec)
57+ ( s ( "@" ) , opt ( plus_or_minus ) , s ( sec_and_nsec) )
5658 . verify_map ( |( _, sign, ( sec, nsec) ) | {
5759 let sec = i64:: try_from ( sec) . ok ( ) ?;
5860 let ( second, nanosecond) = match ( sign, nsec) {
@@ -74,7 +76,7 @@ pub(super) fn parse(input: &mut &str) -> ModalResult<Timestamp> {
7476/// (padded with zeros on the right if fewer digits are present). If the second
7577/// part is omitted, it defaults to 0 nanoseconds.
7678pub ( super ) fn sec_and_nsec ( input : & mut & str ) -> ModalResult < ( u64 , u32 ) > {
77- ( s ( dec_uint) , opt ( preceded ( one_of ( [ '.' , ',' ] ) , digit1) ) )
79+ ( dec_uint, opt ( preceded ( one_of ( [ '.' , ',' ] ) , digit1) ) )
7880 . verify_map ( |( sec, opt_nsec_str) | match opt_nsec_str {
7981 Some ( nsec_str) if nsec_str. len ( ) >= 9 => Some ( ( sec, nsec_str[ ..9 ] . parse ( ) . ok ( ) ?) ) ,
8082 Some ( nsec_str) => {
0 commit comments