Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions crates/bashkit/src/builtins/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ fn parse_base_date(s: &str, now: DateTime<Utc>) -> std::result::Result<DateTime<
return local_naive_to_utc(dt, s);
}

// Try RFC 2822: "Mon, 06 Apr 2026 12:00:00 +0000"
if let Ok(dt) = DateTime::parse_from_rfc2822(s) {
return Ok(dt.with_timezone(&Utc));
}

// Try RFC 3339 / ISO 8601 with timezone: "2024-01-15T12:00:00+00:00"
if let Ok(dt) = DateTime::parse_from_rfc3339(s) {
return Ok(dt.with_timezone(&Utc));
}

Err(format!("date: invalid date '{}'", s))
}

Expand Down Expand Up @@ -813,6 +823,29 @@ mod tests {
assert_eq!(date.len(), 10);
}

// === --date with RFC 2822 input ===

#[tokio::test]
async fn test_date_parse_rfc2822_input() {
let result = run_date(&["+%B %d, %Y", "--date=Mon, 06 Apr 2026 12:00:00 +0000"]).await;
assert_eq!(result.exit_code, 0);
assert_eq!(result.stdout.trim(), "April 06, 2026");
}

#[tokio::test]
async fn test_date_parse_rfc2822_epoch_output() {
let result = run_date(&["+%s", "--date=Wed, 01 Jan 2020 00:00:00 +0000"]).await;
assert_eq!(result.exit_code, 0);
assert_eq!(result.stdout.trim(), "1577836800");
}

#[tokio::test]
async fn test_date_parse_rfc3339_input() {
let result = run_date(&["+%Y", "--date=2024-06-15T12:00:00+00:00"]).await;
assert_eq!(result.exit_code, 0);
assert_eq!(result.stdout.trim(), "2024");
}

// === -R (RFC 2822) tests ===

#[tokio::test]
Expand Down
14 changes: 14 additions & 0 deletions crates/bashkit/tests/spec_cases/bash/date.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,17 @@ date -d 'yesterday + 12 hours' +%Y-%m-%d | grep -qE '^[0-9]{4}-[0-9]{2}-[0-9]{2}
### expect
valid
### end

### date_rfc2822_input
# Parse an RFC 2822 date string via --date
date +"%B %d, %Y" --date="Mon, 06 Apr 2026 12:00:00 +0000"
### expect
April 06, 2026
### end

### date_rfc2822_input_epoch
# Parse an RFC 2822 date string and output as epoch
date +%s --date="Wed, 01 Jan 2020 00:00:00 +0000"
### expect
1577836800
### end
2 changes: 1 addition & 1 deletion specs/009-implementation-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Bashkit implements IEEE 1003.1-2024 Shell Command Language. See
| conditional.test.sh | 29 | `[[ ]]` conditionals, `=~` regex, BASH_REMATCH, glob `==`/`!=` |
| control-flow.test.sh | 60 | if/elif/else, for, while, case `;;`/`;&`/`;;&`, select, trap ERR, `[[ =~ ]]` BASH_REMATCH, compound input redirects |
| cuttr.test.sh | 39 | cut and tr commands, `-z` zero-terminated |
| date.test.sh | 37 | format specifiers, `-d` relative/compound/epoch, `-R`, `-I`, `%N` (2 skipped) |
| date.test.sh | 39 | format specifiers, `-d` relative/compound/epoch/RFC2822, `-R`, `-I`, `%N` (2 skipped) |
| declare.test.sh | 23 | `declare`/`typeset`, `-i`, `-r`, `-x`, `-a`, `-p`, `-n` nameref, `-l`/`-u` case conversion |
| df.test.sh | 3 | disk free reporting |
| diff.test.sh | 6 | line diffs |
Expand Down
Loading