can1357/oh-my-pi · error · TouchError
Unable to parse date: {0}
Error message
Unable to parse date: {0} What it means
This touch builtin error (crates/pi-builtins/src/touch.rs, InvalidDateFormat) means the date string supplied with -d/--date could not be parsed. Touch accepts a limited set of human date formats (matching GNU touch); the raw string is echoed back in the message. It is a pure argument-validation error raised before any file is touched.
Source
Thrown at crates/pi-builtins/src/touch.rs:41
use jiff::{Timestamp, ToSpan, Zoned, civil::Time, fmt::strtime, tz::TimeZone};
#[cfg(unix)]
use libc::O_NONBLOCK;
#[cfg(unix)]
use rustix::fs::Timestamps;
#[cfg(unix)]
use rustix::fs::futimens;
#[cfg(target_os = "linux")]
use uucore::libc;
use uucore::{display::Quotable, parser::shortcut_value_parser::ShortcutValueParser};
use brush_core::{ShellExtensions, builtins::Registration};
use thiserror::Error as ThisError;
use crate::host::{Host, Utility, format_usage, matches_parser, util};
#[derive(Debug, ThisError)]
enum TouchError {
#[error("Unable to parse date: {0}")]
InvalidDateFormat(String),
#[error("Source has invalid access or modification time: {0}")]
InvalidFiletime(FileTime),
#[error("failed to get attributes of {}: {}", .0.quote(), io_error(.1))]
ReferenceFileInaccessible(PathBuf, std::io::Error),
#[cfg(windows)]
#[error("GetFinalPathNameByHandleW failed with code {0}")]
WindowsStdoutPathError(String),
#[error("{0}")]
Message(String),
}
fn io_error(error: &std::io::Error) -> String {
if error.raw_os_error().is_some() {
match error.kind() {
ErrorKind::NotFound => "No such file or directory".into(),
ErrorKind::PermissionDenied => "Permission denied".into(),
ErrorKind::AlreadyExists => "Already exists".into(),View on GitHub (pinned to 9690622007)
Solutions
- Use an ISO 8601 timestamp: `touch -d '2026-08-30 12:00:00' file`.
- Feed dates through `date -I` / `date --iso-8601` when generating the value in scripts.
- Validate/normalize the date variable before invoking touch (non-empty, ISO order YYYY-MM-DD).
- If you meant 'now', omit -d entirely or use `touch -d now file`.
Example fix
// before touch -d '31/12/2026' stamp.txt // Unable to parse date: 31/12/2026 // after touch -d '2026-12-31 00:00:00' stamp.txt
Defensive patterns
Strategy: validation
Validate before calling
function isIsoDate(s) {
return typeof s === 'string' && /^\d{4}-\d{2}-\d{2}([ T]\d{2}:\d{2}(:\d{2})?)?$/.test(s) && !Number.isNaN(Date.parse(s.replace(' ', 'T')));
} Try / catch
try {
await touch.run(['-d', dateStr, file]);
} catch (err) {
if (String(err).startsWith('Unable to parse date:')) {
console.error(`normalize '${dateStr}' to ISO 8601 (YYYY-MM-DD HH:MM:SS)`);
} else throw err;
} Prevention
- Always generate -d values in ISO 8601 (YYYY-MM-DD HH:MM:SS).
- Produce dates via `date --iso-8601` in scripts rather than locale formats.
- Guard against empty/unset variables before passing them to -d.
When it happens
Trigger: Running touch with an unparsable --date value, e.g. `touch -d 'not a date' f`, locale-dependent formats like `touch -d '31/12/2026'` (day-first is not supported), or missing time components.
Common situations: Scripts generating dates with `date`-specific formats touch doesn't accept; regional date orders (DD/MM/YYYY); empty variables expanding to `touch -d ''`; porting from systems whose touch has a different date grammar.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- invalid date: {value}
- date is out of range
- dates before 1970 are unsupported
- err.to_string() (timestamp parse error)
- duration is too large: {value}
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/22f7d81b34931b31.
Report an issue: GitHub.