#compdef date

autoload -U is-at-least

_date() {
    typeset -A opt_args
    typeset -a _arguments_options
    local ret=1

    if is-at-least 5.2; then
        _arguments_options=(-s -S -C)
    else
        _arguments_options=(-s -C)
    fi

    local context curcontext="$curcontext" state line
    _arguments "${_arguments_options[@]}" : \
'-d+[display time described by STRING, not '\''now'\'']:STRING:_default' \
'--date=[display time described by STRING, not '\''now'\'']:STRING:_default' \
'(-d --date)-f+[like --date; once for each line of DATEFILE]:DATEFILE:_files' \
'(-d --date)--file=[like --date; once for each line of DATEFILE]:DATEFILE:_files' \
'-I+[output date/time in ISO 8601 format. FMT='\''date'\'' for date only (the default), '\''hours'\'', '\''minutes'\'', '\''seconds'\'', or '\''ns'\'' for date and time to the indicated precision. Example\: 2006-08-14T02\:34\:56-06\:00]::FMT:(date hours minutes seconds ns)' \
'--iso-8601=[output date/time in ISO 8601 format. FMT='\''date'\'' for date only (the default), '\''hours'\'', '\''minutes'\'', '\''seconds'\'', or '\''ns'\'' for date and time to the indicated precision. Example\: 2006-08-14T02\:34\:56-06\:00]::FMT:(date hours minutes seconds ns)' \
'--rfc-3339=[output date/time in RFC 3339 format. FMT='\''date'\'', '\''seconds'\'', or '\''ns'\'' for date and time to the indicated precision. Example\: 2006-08-14 02\:34\:56-06\:00]:FMT:(date seconds ns)' \
'(-d --date -f --file --resolution)-r+[display the last modification time of FILE]:FILE:_files' \
'(-d --date -f --file --resolution)--reference=[display the last modification time of FILE]:FILE:_files' \
'-s+[set time described by STRING]:STRING:_default' \
'--set=[set time described by STRING]:STRING:_default' \
'(-d --date -f --file)--resolution[output the available resolution of timestamps Example\: 0.000000001]' \
'-R[output date and time in RFC 5322 format. Example\: Mon, 14 Aug 2006 02\:34\:56 -0600]' \
'--rfc-email[output date and time in RFC 5322 format. Example\: Mon, 14 Aug 2006 02\:34\:56 -0600]' \
'--debug[annotate the parsed date, and warn about questionable usage to stderr]' \
'-u[print or set Coordinated Universal Time (UTC)]' \
'--universal[print or set Coordinated Universal Time (UTC)]' \
'--utc[print or set Coordinated Universal Time (UTC)]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'*::format:_default' \
&& ret=0
}

(( $+functions[_date_commands] )) ||
_date_commands() {
    local commands; commands=()
    _describe -t commands 'date commands' commands "$@"
}

if [ "$funcstack[1]" = "_date" ]; then
    _date "$@"
else
    compdef _date date
fi
