#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+[date-help-date]:STRING:_default' \
'--date=[date-help-date]:STRING:_default' \
'-f+[date-help-file]:DATEFILE:_files' \
'--file=[date-help-file]:DATEFILE:_files' \
'-I+[date-help-iso-8601]' \
'--iso-8601=[date-help-iso-8601]' \
'--rfc-3339=[date-help-rfc-3339]:FMT:(date seconds ns)' \
'-r+[date-help-reference]:FILE:_files' \
'--reference=[date-help-reference]:FILE:_files' \
'-s+[date-help-set]:STRING:_default' \
'--set=[date-help-set]:STRING:_default' \
'-R[date-help-rfc-email]' \
'--rfc-email[date-help-rfc-email]' \
'--debug[date-help-debug]' \
'-u[date-help-universal]' \
'--universal[date-help-universal]' \
'-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
