Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Useful zsh/datetime things



On Oct 9,  5:27pm, Bart Schaefer wrote:
}
} function rfcdate {
}   # Like GNU "date -R"
}   strftime "%a, %e %b %Y %H:%M:%S %z" $EPOCHSECONDS
} }

As this doesn't work without a version of strftime that supports the
nonstandard "%z", here's a replacement:

function rfcdate {
    # As much like GNU "date -R" as possible
    if [[ ${(%):-"%D{%z}"} == [-+]<-> ]]
    then strftime "%a, %e %b %Y %H:%M:%S %z" $EPOCHSECONDS
    else strftime "%a, %e %b %Y %H:%M:%S %Z" $EPOCHSECONDS
    fi
}

The quotes around "%D{%z}" are necessary lest zsh interpret the first
closing brace as the end of the parameter substitution (leaving a stray
second closing brace which becomes part of the comparison).  This does
not seem to be the behavior of other shells -- e.g., bash balances all
nested braces.



Messages sorted by: Reverse Date, Date, Thread, Author