Skip to content

Commit 59cc08a

Browse files
committed
feat: add POSIX-compliant date +%s implementation
https://web.archive.org/web/0id_/etalabs.net/sh_tricks.html Signed-off-by: Lucas Larson <[email protected]>
1 parent ce9b06c commit 59cc08a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

custom/aliases.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,14 @@ curl_brew() {
11921192
--url "${@-}"
11931193
}
11941194

1195+
date_s() {
1196+
# POSIX-compliant implementation of `date +%s`
1197+
# https://web.archive.org/web/0id_/etalabs.net/sh_tricks.html
1198+
command -p -- printf -- '%d\n' "$(($(
1199+
command -p -- date -u -- '+( (%Y - 1600) * 365 + (%Y - 1600) / 4 - (%Y - 1600) / 100 + (%Y - 1600) / 400 + %j - 135140) * 86400 + %H * 3600 + %M * 60 + %S'
1200+
)))"
1201+
}
1202+
11951203
# define
11961204
alias -- d >/dev/null 2>&1 &&
11971205
unalias -- d

0 commit comments

Comments
 (0)