Skip to content

date input: HH:MM am/pm forms rejected (e.g. 2024-06-15 12:00 PM) #282

@sylvestre

Description

@sylvestre

Summary

parse_datetime accepts 3pm and 2024-06-15 3pm, but rejects the HH:MM am/pm forms that GNU date handles fine.

Found by a fuzz_date run on uutils/coreutils.

Reproduction

$ /usr/bin/date -d '2024-06-15 12:00 PM' '+%H:%M'
12:00
$ target/debug/coreutils date -d '2024-06-15 12:00 PM' '+%H:%M'
date: invalid date '2024-06-15 12:00 PM'

$ /usr/bin/date -d '2024-06-15 11:30am' '+%H:%M'
11:30
$ target/debug/coreutils date -d '2024-06-15 11:30am' '+%H:%M'
date: invalid date '2024-06-15 11:30am'

$ /usr/bin/date -d '2024-06-15 3:00 PM' '+%H:%M'
15:00
$ target/debug/coreutils date -d '2024-06-15 3:00 PM' '+%H:%M'
date: invalid date '2024-06-15 3:00 PM'

The forms that already work for reference:

$ target/debug/coreutils date -d '3pm' '+%H:%M'
15:00
$ target/debug/coreutils date -d '2024-06-15 3pm' '+%H:%M'
15:00

Test (in uutils/coreutils integration suite)

#[test]
fn test_date_input_hhmm_ampm() {
    for input in [
        "2024-06-15 12:00 PM",
        "2024-06-15 11:30am",
        "2024-06-15 3:00 PM",
    ] {
        new_ucmd!()
            .env("LC_ALL", "C")
            .env("TZ", "UTC")
            .arg("-d")
            .arg(input)
            .arg("+%H:%M")
            .succeeds();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions