ajouter de nouveaux formats pour parse_date

This commit is contained in:
Jephté Clain 2018-11-10 09:58:22 +04:00
parent 1151b5c01a
commit e6be47eb32
1 changed files with 3 additions and 0 deletions

View File

@ -393,7 +393,9 @@ function parse_date() {
local value="$1" type="${2:-date}"
local now="$(awk 'BEGIN { print mktime(strftime("%Y %m %d 00 00 00 +0400")) }')"
case "$value" in
=*) value="${value#=}";;
+*) value="$(($now + ${value#+} * 86400))";;
-*) value="$(($now - ${value#-} * 86400))";;
*) value="$(<<<"$value" awk -F/ '{
nd = strftime("%d"); nm = strftime("%m"); ny = strftime("%Y")
d = $1 + 0; if (d < 1) d = nd;
@ -407,6 +409,7 @@ function parse_date() {
d|date) awk '{ print strftime("%d/%m/%Y", $0 + 0) }' <<<"$value";;
l|ldap) awk '{ print strftime("%Y%m%d%H%M%S+0400", $0 + 0) }' <<<"$value";;
m|mysql) awk '{ print strftime("%Y-%m-%d", $0 + 0) }' <<<"$value";;
t|ts|timestamp) echo "$value";;
*) recho "$value";;
esac
}