File: mod.rs

package info (click to toggle)
rust-coreutils 0.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 505,620 kB
  • sloc: ansic: 103,594; asm: 28,570; sh: 8,910; python: 5,581; makefile: 472; cpp: 97; javascript: 72
file content (37 lines) | stat: -rw-r--r-- 993 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

use std::env;

use jiff::Zoned;
use parse_datetime::{parse_datetime, parse_datetime_at_date};

pub fn check_absolute(input: &str, expected: &str) {
    env::set_var("TZ", "UTC0");

    let parsed = match parse_datetime(input) {
        Ok(v) => v,
        Err(e) => panic!("Failed to parse date from value '{input}': {e}"),
    };

    assert_eq!(
        parsed.strftime("%Y-%m-%d %H:%M:%S%:z").to_string(),
        expected,
        "Input value: {input}"
    );
}

pub fn check_relative(now: Zoned, input: &str, expected: &str) {
    env::set_var("TZ", "UTC0");

    let parsed = match parse_datetime_at_date(now, input) {
        Ok(v) => v,
        Err(e) => panic!("Failed to parse date from value '{input}': {e}"),
    };

    assert_eq!(
        parsed.strftime("%Y-%m-%d %H:%M:%S%:z").to_string(),
        expected,
        "Input value: {input}"
    );
}