From d4d546b82006e1bb792a24fa3d9046198e0d1e44 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 29 Apr 2025 10:34:46 +0900 Subject: fish: add unix2utc, unix2jst, utc2unix and jst2unix --- home-manager/config/fish/config.fish | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 -- cgit v1.2.3-70-g09d2