Skip to content

Commit

Permalink
bin.rs fix parsing of example input strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jtmoon79 committed May 29, 2023
1 parent 481b5ef commit 99b8c46
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 19 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ DateTime Filters may be strftime specifier patterns:
"%Y-%m-%d %H:%M:%S %#z"
"%Y-%m-%d %H:%M:%S %Z"
"%Y-%m-%dT%H:%M:%S"
"%Y-%m-%dT%H:%M:%S"
"%Y-%m-%dT%H:%M:%S%z"
"%Y-%m-%dT%H:%M:%S%:z"
"%Y-%m-%dT%H:%M:%S%#z"
"%Y-%m-%dT%H:%M:%S%Z"
"%Y-%m-%dT%H:%M:%S %z"
"%Y-%m-%dT%H:%M:%S %:z"
"%Y-%m-%dT%H:%M:%S %#z"
Expand Down
68 changes: 49 additions & 19 deletions src/bin/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,25 +233,30 @@ const CLI_DT_FILTER_PATTERN8: CLI_DT_Filter_Pattern = ("%Y-%m-%d %H:%M:%S %:z",
const CLI_DT_FILTER_PATTERN9: CLI_DT_Filter_Pattern = ("%Y-%m-%d %H:%M:%S %#z", true, true, false, true);
const CLI_DT_FILTER_PATTERN10: CLI_DT_Filter_Pattern = ("%Y-%m-%d %H:%M:%S %Z", true, true, true, true);
const CLI_DT_FILTER_PATTERN11: CLI_DT_Filter_Pattern = ("%Y-%m-%dT%H:%M:%S", true, false, false, true);
const CLI_DT_FILTER_PATTERN12: CLI_DT_Filter_Pattern = ("%Y-%m-%dT%H:%M:%S %z", true, true, false, true);
const CLI_DT_FILTER_PATTERN13: CLI_DT_Filter_Pattern = ("%Y-%m-%dT%H:%M:%S %:z", true, true, false, true);
const CLI_DT_FILTER_PATTERN14: CLI_DT_Filter_Pattern = ("%Y-%m-%dT%H:%M:%S %#z", true, true, false, true);
const CLI_DT_FILTER_PATTERN15: CLI_DT_Filter_Pattern = ("%Y-%m-%dT%H:%M:%S %Z", true, true, true, true);
const CLI_DT_FILTER_PATTERN16: CLI_DT_Filter_Pattern = ("%Y/%m/%d %H:%M:%S", true, false, false, true);
const CLI_DT_FILTER_PATTERN17: CLI_DT_Filter_Pattern = ("%Y/%m/%d %H:%M:%S %z", true, true, false, true);
const CLI_DT_FILTER_PATTERN18: CLI_DT_Filter_Pattern = ("%Y/%m/%d %H:%M:%S %:z", true, true, false, true);
const CLI_DT_FILTER_PATTERN19: CLI_DT_Filter_Pattern = ("%Y/%m/%d %H:%M:%S %#z", true, true, false, true);
const CLI_DT_FILTER_PATTERN20: CLI_DT_Filter_Pattern = ("%Y/%m/%d %H:%M:%S %Z", true, true, true, true);
const CLI_DT_FILTER_PATTERN21: CLI_DT_Filter_Pattern = ("%Y%m%d", true, false, false, false);
const CLI_DT_FILTER_PATTERN22: CLI_DT_Filter_Pattern = ("%Y-%m-%d", true, false, false, false);
const CLI_DT_FILTER_PATTERN23: CLI_DT_Filter_Pattern = ("%Y/%m/%d", true, false, false, false);
const CLI_DT_FILTER_PATTERN24: CLI_DT_Filter_Pattern = ("%Y%m%d %z", true, true, false, false);
const CLI_DT_FILTER_PATTERN25: CLI_DT_Filter_Pattern = ("%Y%m%d %:z", true, true, false, false);
const CLI_DT_FILTER_PATTERN26: CLI_DT_Filter_Pattern = ("%Y%m%d %#z", true, true, false, false);
const CLI_DT_FILTER_PATTERN27: CLI_DT_Filter_Pattern = ("%Y%m%d %Z", true, true, true, false);
const CLI_DT_FILTER_PATTERN28: CLI_DT_Filter_Pattern = ("+%s", false, false, false, true);

const CLI_FILTER_PATTERNS_COUNT: usize = 28;
const CLI_DT_FILTER_PATTERN12: CLI_DT_Filter_Pattern = ("%Y-%m-%dT%H:%M:%S", true, false, false, true);
const CLI_DT_FILTER_PATTERN13: CLI_DT_Filter_Pattern = ("%Y-%m-%dT%H:%M:%S%z", true, true, false, true);
const CLI_DT_FILTER_PATTERN14: CLI_DT_Filter_Pattern = ("%Y-%m-%dT%H:%M:%S%:z", true, true, false, true);
const CLI_DT_FILTER_PATTERN15: CLI_DT_Filter_Pattern = ("%Y-%m-%dT%H:%M:%S%#z", true, true, false, true);
const CLI_DT_FILTER_PATTERN16: CLI_DT_Filter_Pattern = ("%Y-%m-%dT%H:%M:%S%Z", true, true, true, true);
const CLI_DT_FILTER_PATTERN17: CLI_DT_Filter_Pattern = ("%Y-%m-%dT%H:%M:%S %z", true, true, false, true);
const CLI_DT_FILTER_PATTERN18: CLI_DT_Filter_Pattern = ("%Y-%m-%dT%H:%M:%S %:z", true, true, false, true);
const CLI_DT_FILTER_PATTERN19: CLI_DT_Filter_Pattern = ("%Y-%m-%dT%H:%M:%S %#z", true, true, false, true);
const CLI_DT_FILTER_PATTERN20: CLI_DT_Filter_Pattern = ("%Y-%m-%dT%H:%M:%S %Z", true, true, true, true);
const CLI_DT_FILTER_PATTERN21: CLI_DT_Filter_Pattern = ("%Y/%m/%d %H:%M:%S", true, false, false, true);
const CLI_DT_FILTER_PATTERN22: CLI_DT_Filter_Pattern = ("%Y/%m/%d %H:%M:%S %z", true, true, false, true);
const CLI_DT_FILTER_PATTERN23: CLI_DT_Filter_Pattern = ("%Y/%m/%d %H:%M:%S %:z", true, true, false, true);
const CLI_DT_FILTER_PATTERN24: CLI_DT_Filter_Pattern = ("%Y/%m/%d %H:%M:%S %#z", true, true, false, true);
const CLI_DT_FILTER_PATTERN25: CLI_DT_Filter_Pattern = ("%Y/%m/%d %H:%M:%S %Z", true, true, true, true);
const CLI_DT_FILTER_PATTERN26: CLI_DT_Filter_Pattern = ("%Y%m%d", true, false, false, false);
const CLI_DT_FILTER_PATTERN27: CLI_DT_Filter_Pattern = ("%Y-%m-%d", true, false, false, false);
const CLI_DT_FILTER_PATTERN28: CLI_DT_Filter_Pattern = ("%Y/%m/%d", true, false, false, false);
const CLI_DT_FILTER_PATTERN29: CLI_DT_Filter_Pattern = ("%Y%m%d %z", true, true, false, false);
const CLI_DT_FILTER_PATTERN30: CLI_DT_Filter_Pattern = ("%Y%m%d %:z", true, true, false, false);
const CLI_DT_FILTER_PATTERN31: CLI_DT_Filter_Pattern = ("%Y%m%d %#z", true, true, false, false);
const CLI_DT_FILTER_PATTERN32: CLI_DT_Filter_Pattern = ("%Y%m%d %Z", true, true, true, false);
const CLI_DT_FILTER_PATTERN33: CLI_DT_Filter_Pattern = ("+%s", false, false, false, true);

const CLI_FILTER_PATTERNS_COUNT: usize = 33;

/// CLI acceptable datetime filter patterns for the user-passed `-a` or `-b`
const CLI_FILTER_PATTERNS: [&CLI_DT_Filter_Pattern; CLI_FILTER_PATTERNS_COUNT] = [
Expand Down Expand Up @@ -283,6 +288,11 @@ const CLI_FILTER_PATTERNS: [&CLI_DT_Filter_Pattern; CLI_FILTER_PATTERNS_COUNT] =
&CLI_DT_FILTER_PATTERN26,
&CLI_DT_FILTER_PATTERN27,
&CLI_DT_FILTER_PATTERN28,
&CLI_DT_FILTER_PATTERN29,
&CLI_DT_FILTER_PATTERN30,
&CLI_DT_FILTER_PATTERN31,
&CLI_DT_FILTER_PATTERN32,
&CLI_DT_FILTER_PATTERN33,
];

const CGN_DUR_OFFSET_TYPE: &str = "offset_type";
Expand Down Expand Up @@ -435,6 +445,21 @@ DateTime Filters may be strftime specifier patterns:
"\"
\"",
CLI_DT_FILTER_PATTERN28.0,
"\"
\"",
CLI_DT_FILTER_PATTERN29.0,
"\"
\"",
CLI_DT_FILTER_PATTERN30.0,
"\"
\"",
CLI_DT_FILTER_PATTERN31.0,
"\"
\"",
CLI_DT_FILTER_PATTERN32.0,
"\"
\"",
CLI_DT_FILTER_PATTERN33.0,
"\"",
r#"
Expand Down Expand Up @@ -5017,7 +5042,12 @@ mod tests {
tz_offset: FixedOffset,
expect: DateTimeLOpt,
) {
eprintln!(
"test_process_dt: process_dt({:?}, {:?}, &None, UTC_NOW: {:?})",
dts, tz_offset, &*UTC_NOW,
);
let dt = process_dt(&dts, &tz_offset, &None, &UTC_NOW);
eprintln!("test_process_dt: dt: {:?}", dt);
assert_eq!(dt, expect);
}

Expand Down

0 comments on commit 99b8c46

Please sign in to comment.