|
| 1 | +use rstest::rstest; |
| 2 | + |
| 3 | +mod common; |
| 4 | +use common::check_absolute; |
| 5 | + |
| 6 | +// The expected values are produced by GNU date version 8.32 |
| 7 | +// export LC_TIME=en_US.UTF-8 |
| 8 | +// export TZ=UTC |
| 9 | +// date --rfc-3339=seconds --date="2022-11-14" |
| 10 | +// |
| 11 | +// Documentation for the date format can be found at: |
| 12 | +// https://www.gnu.org/software/coreutils/manual/html_node/Calendar-date-items.html |
| 13 | + |
| 14 | +#[rstest] |
| 15 | +#[case::iso8601("2022-11-14", "2022-11-14 00:00:00+00:00")] |
| 16 | +#[case::short_year_22("22-11-14", "2022-11-14 00:00:00+00:00")] |
| 17 | +#[case::short_year_68("68-11-14", "2068-11-14 00:00:00+00:00")] |
| 18 | +#[case::short_year_00("00-11-14", "2000-11-14 00:00:00+00:00")] |
| 19 | +#[case::short_year_69("69-11-14", "1969-11-14 00:00:00+00:00")] |
| 20 | +#[case::short_year_99("99-11-14", "1999-11-14 00:00:00+00:00")] |
| 21 | +#[case::us_style("11/14/2022", "2022-11-14 00:00:00+00:00")] |
| 22 | +#[case::us_style_short_year("11/14/22", "2022-11-14 00:00:00+00:00")] |
| 23 | +#[case::year_zero("0000-01-01", "0000-01-01 00:00:00+00:00")] |
| 24 | +#[case::year_001("001-11-14", "0001-11-14 00:00:00+00:00")] |
| 25 | +#[case::year_100("100-11-14", "0100-11-14 00:00:00+00:00")] |
| 26 | +#[case::year_999("999-11-14", "0999-11-14 00:00:00+00:00")] |
| 27 | +#[case::year_9999("9999-11-14", "9999-11-14 00:00:00+00:00")] |
| 28 | +/** TODO: https://github.com/uutils/parse_datetime/issues/160 |
| 29 | +#[case::year_10000("10000-12-31", "10000-12-31 00:00:00+00:00")] |
| 30 | +#[case::year_100000("100000-12-31", "100000-12-31 00:00:00+00:00")] |
| 31 | +#[case::year_1000000("1000000-12-31", "1000000-12-31 00:00:00+00:00")] |
| 32 | +#[case::year_10000000("10000000-12-31", "10000000-12-31 00:00:00+00:00")] |
| 33 | +#[case::max_date("2147485547-12-31", "2147485547-12-31 00:00:00+00:00")] |
| 34 | +**/ |
| 35 | +#[case::long_month_in_the_middle("14 November 2022", "2022-11-14 00:00:00+00:00")] |
| 36 | +#[case::long_month_in_the_middle_lowercase("14 november 2022", "2022-11-14 00:00:00+00:00")] |
| 37 | +#[case::long_month_in_the_middle_uppercase("14 NOVEMBER 2022", "2022-11-14 00:00:00+00:00")] |
| 38 | +#[case::short_month_in_the_middle("14 nov 2022", "2022-11-14 00:00:00+00:00")] |
| 39 | +#[case::short_month_in_the_uppercase("14 NOV 2022", "2022-11-14 00:00:00+00:00")] |
| 40 | +#[case::long_month_in_the_middle_hyphened("14-november-2022", "2022-11-14 00:00:00+00:00")] |
| 41 | +#[case::long_month_in_the_middle_nospace("14november2022", "2022-11-14 00:00:00+00:00")] |
| 42 | +#[case::short_month_in_the_middle_hyphened("14-nov-2022", "2022-11-14 00:00:00+00:00")] |
| 43 | +#[case::short_month_in_the_middle_nospace("14nov2022", "2022-11-14 00:00:00+00:00")] |
| 44 | +#[case::long_month_at_start("November 14 2022", "2022-11-14 00:00:00+00:00")] |
| 45 | +#[case::long_month_at_start_with_comma("November 14, 2022", "2022-11-14 00:00:00+00:00")] |
| 46 | +#[case::short_month_at_start("nov 14 2022", "2022-11-14 00:00:00+00:00")] |
| 47 | +#[case::long_month_in_the_middle_jan("14 January 2022", "2022-01-14 00:00:00+00:00")] |
| 48 | +#[case::long_month_in_the_middle_feb("14 February 2022", "2022-02-14 00:00:00+00:00")] |
| 49 | +#[case::long_month_in_the_middle_mar("14 March 2022", "2022-03-14 00:00:00+00:00")] |
| 50 | +#[case::long_month_in_the_middle_apr("14 April 2022", "2022-04-14 00:00:00+00:00")] |
| 51 | +#[case::long_month_in_the_middle_may("14 May 2022", "2022-05-14 00:00:00+00:00")] |
| 52 | +#[case::long_month_in_the_middle_jun("14 June 2022", "2022-06-14 00:00:00+00:00")] |
| 53 | +#[case::long_month_in_the_middle_jul("14 July 2022", "2022-07-14 00:00:00+00:00")] |
| 54 | +#[case::long_month_in_the_middle_aug("14 August 2022", "2022-08-14 00:00:00+00:00")] |
| 55 | +#[case::long_month_in_the_middle_sep("14 September 2022", "2022-09-14 00:00:00+00:00")] |
| 56 | +#[case::long_month_in_the_middle_oct("14 October 2022", "2022-10-14 00:00:00+00:00")] |
| 57 | +#[case::long_month_in_the_middle_dec("14 December 2022", "2022-12-14 00:00:00+00:00")] |
| 58 | +#[case::short_month_in_the_middle_jan("14 jan 2022", "2022-01-14 00:00:00+00:00")] |
| 59 | +#[case::short_month_in_the_middle_feb("14 feb 2022", "2022-02-14 00:00:00+00:00")] |
| 60 | +#[case::short_month_in_the_middle_mar("14 mar 2022", "2022-03-14 00:00:00+00:00")] |
| 61 | +#[case::short_month_in_the_middle_apr("14 apr 2022", "2022-04-14 00:00:00+00:00")] |
| 62 | +#[case::short_month_in_the_middle_may("14 may 2022", "2022-05-14 00:00:00+00:00")] |
| 63 | +#[case::short_month_in_the_middle_jun("14 jun 2022", "2022-06-14 00:00:00+00:00")] |
| 64 | +#[case::short_month_in_the_middle_jul("14 jul 2022", "2022-07-14 00:00:00+00:00")] |
| 65 | +#[case::short_month_in_the_middle_aug("14 aug 2022", "2022-08-14 00:00:00+00:00")] |
| 66 | +#[case::short_month_in_the_middle_sep("14 sep 2022", "2022-09-14 00:00:00+00:00")] |
| 67 | +#[case::short_month_in_the_middle_sept("14 sept 2022", "2022-09-14 00:00:00+00:00")] |
| 68 | +#[case::short_month_in_the_middle_oct("14 oct 2022", "2022-10-14 00:00:00+00:00")] |
| 69 | +#[case::short_month_in_the_middle_dec("14 dec 2022", "2022-12-14 00:00:00+00:00")] |
| 70 | +fn test_absolute_date_numeric(#[case] input: &str, #[case] expected: &str) { |
| 71 | + check_absolute(input, expected); |
| 72 | +} |
| 73 | + |
| 74 | +#[rstest] |
| 75 | +#[case::us_style("11/14", 2022, "2022-11-14 00:00:00+00:00")] |
| 76 | +#[case::aphabetical_full_month_in_front("november 14", 2022, "2022-11-14 00:00:00+00:00")] |
| 77 | +#[case::aphabetical_full_month_at_back("14 november", 2022, "2022-11-14 00:00:00+00:00")] |
| 78 | +#[case::aphabetical_short_month_in_front("nov 14", 2022, "2022-11-14 00:00:00+00:00")] |
| 79 | +#[case::aphabetical_short_month_at_back("14 nov", 2022, "2022-11-14 00:00:00+00:00")] |
| 80 | +#[case::aphabetical_full_month_in_front("november 14", 2022, "2022-11-14 00:00:00+00:00")] |
| 81 | +#[case::aphabetical_full_month_at_back("14 november", 2022, "2022-11-14 00:00:00+00:00")] |
| 82 | +#[case::aphabetical_short_month_in_front("nov 14", 2022, "2022-11-14 00:00:00+00:00")] |
| 83 | +#[case::aphabetical_short_month_at_back("14 nov", 2022, "2022-11-14 00:00:00+00:00")] |
| 84 | +#[case::aphabetical_long_month_at_back_hyphen("14-november", 2022, "2022-11-14 00:00:00+00:00")] |
| 85 | +#[case::aphabetical_short_month_at_back_hyphen("14-nov", 2022, "2022-11-14 00:00:00+00:00")] |
| 86 | +fn test_date_ommititing_year(#[case] input: &str, #[case] year: u32, #[case] expected: &str) { |
| 87 | + use chrono::DateTime; |
| 88 | + use common::check_relative; |
| 89 | + |
| 90 | + let now = DateTime::parse_from_rfc3339(&format!("{year}-06-01T00:00:00+00:00")).unwrap(); |
| 91 | + check_relative(now, input, expected); |
| 92 | +} |
0 commit comments