2025-06-24 14:43:56 +02:00
|
|
|
// For the full copyright and license information, please view the LICENSE
|
|
|
|
|
// file that was distributed with this source code.
|
|
|
|
|
|
2025-06-24 13:40:31 +02:00
|
|
|
use std::env;
|
|
|
|
|
|
2025-08-16 23:17:41 +08:00
|
|
|
use jiff::Zoned;
|
2026-03-31 09:17:07 +02:00
|
|
|
use parse_datetime::{parse_datetime, parse_datetime_at_date};
|
2025-06-20 09:02:45 +00:00
|
|
|
|
|
|
|
|
pub fn check_absolute(input: &str, expected: &str) {
|
2025-06-24 13:40:31 +02:00
|
|
|
env::set_var("TZ", "UTC0");
|
|
|
|
|
|
2025-06-20 09:02:45 +00:00
|
|
|
let parsed = match parse_datetime(input) {
|
|
|
|
|
Ok(v) => v,
|
|
|
|
|
Err(e) => panic!("Failed to parse date from value '{input}': {e}"),
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-31 09:17:07 +02:00
|
|
|
assert_eq!(parsed.to_string(), expected, "Input value: {input}");
|
2025-06-20 09:02:45 +00:00
|
|
|
}
|
|
|
|
|
|
2025-08-16 23:17:41 +08:00
|
|
|
pub fn check_relative(now: Zoned, input: &str, expected: &str) {
|
2025-06-24 13:40:31 +02:00
|
|
|
env::set_var("TZ", "UTC0");
|
|
|
|
|
|
2025-08-16 23:17:41 +08:00
|
|
|
let parsed = match parse_datetime_at_date(now, input) {
|
2025-06-20 09:02:45 +00:00
|
|
|
Ok(v) => v,
|
|
|
|
|
Err(e) => panic!("Failed to parse date from value '{input}': {e}"),
|
|
|
|
|
};
|
2025-08-16 23:17:41 +08:00
|
|
|
|
2026-03-31 09:17:07 +02:00
|
|
|
assert_eq!(parsed.to_string(), expected, "Input value: {input}");
|
2025-06-20 09:02:45 +00:00
|
|
|
}
|