diff options
| -rw-r--r-- | home-manager/config/fish/config.fish | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/home-manager/config/fish/config.fish b/home-manager/config/fish/config.fish index 3782318..7f0d8b3 100644 --- a/home-manager/config/fish/config.fish +++ b/home-manager/config/fish/config.fish @@ -114,3 +114,18 @@ function terraform command terraform $argv end end + +# Conversion between unix time and human-readable datetime. +# Use `jq` for its small footprint and portability. +function unix2utc + echo $argv[1] | jq -Rr 'if . == "" then now else tonumber end | floor | strftime("%Y-%m-%dT%H:%M:%SZ")' +end +function unix2jst + echo $argv[1] | jq -Rr 'if . == "" then now else tonumber end | floor | . + 32400 | strftime("%Y-%m-%dT%H:%M:%S+09:00")' +end +function utc2unix + echo $argv[1] | jq -Rr 'strptime("%Y-%m-%dT%H:%M:%SZ") | mktime' +end +function jst2unix + echo $argv[1] | jq -Rr 'strptime("%Y-%m-%dT%H:%M:%S+09:00") | mktime | . - 32400' +end |
