-
-
Save rawiriblundell/cd3bd422ea9c5383de8523f1d5d8347d to your computer and use it in GitHub Desktop.
Add ordinal date representation i.e. Mar 2 => Mar 2nd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
date() { | |
case "$@" in | |
(*"%o"*) | |
declare -a args1 | |
declare -a args2 | |
while [[ -n "$1" ]]; do | |
args2+=("$1") | |
if [[ "${1:0:1}" != + ]]; then | |
args1+=("$1") | |
fi | |
shift | |
done | |
case $(command date +%d "${args1[@]}") in | |
(01|21|31) dSfx="st";; | |
(02|22) dSfx="nd";; | |
(03|23) dSfx="rd";; | |
(*) dSfx="th";; | |
esac | |
command date "${args2[@]}" | sed -e "s/%o/${dSfx}/g" | |
;; | |
(*) | |
command date "$@" | |
;; | |
esac | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment