| 1 |
// For the full copyright and license information, please view the LICENSE |
| 2 |
// file that was distributed with this source code. |
| 3 |
|
| 4 |
//! Parse a pure number string. |
| 5 |
//! |
| 6 |
//! From the GNU docs: |
| 7 |
//! |
| 8 |
//! > The precise interpretation of a pure decimal number depends on the |
| 9 |
//! > context in the date string. |
| 10 |
//! > |
| 11 |
//! > If the decimal number is of the form YYYYMMDD and no other calendar |
| 12 |
//! > date item (*note Calendar date items::) appears before it in the date |
| 13 |
//! > string, then YYYY is read as the year, MM as the month number and DD as |
| 14 |
//! > the day of the month, for the specified calendar date. |
| 15 |
//! > |
| 16 |
//! > If the decimal number is of the form HHMM and no other time of day |
| 17 |
//! > item appears before it in the date string, then HH is read as the hour |
| 18 |
//! > of the day and MM as the minute of the hour, for the specified time of |
| 19 |
//! > day. MM can also be omitted. |
| 20 |
//! > |
| 21 |
//! > If both a calendar date and a time of day appear to the left of a |
| 22 |
//! > number in the date string, but no relative item, then the number |
| 23 |
//! > overrides the year. |
| 24 |
|
| 25 |
use winnow::{ModalResult, Parser}; |
| 26 |
|
| 27 |
use super::primitive::{dec_uint_str, s}; |
| 28 |
|
| 29 |
/// Parse a pure number string and return it as an owned `String`. We return a |
| 30 |
/// `String` here because the interpretation of the number depends on the |
| 31 |
/// parsing context in which it appears. The interpretation is deferred to the |
| 32 |
/// result building phase. |
| 33 |
pub(super) fn parse(input: &mut &str) -> ModalResult<String> { |
| 34 |
s(dec_uint_str) |
| 35 |
.map(|s: &str| s.to_owned()) |
| 36 |
.parse_next(input) |
| 37 |
} |