diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-04-29 10:34:46 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-04-29 10:34:46 +0900 |
| commit | d4d546b82006e1bb792a24fa3d9046198e0d1e44 (patch) | |
| tree | 83ad064b0dd1efd1d1d7b2676c6278afdbc489e9 | |
| parent | e6ff233c4de9a2cfe16fdbb68cb076a55eeb7b94 (diff) | |
| download | dotfiles-d4d546b82006e1bb792a24fa3d9046198e0d1e44.tar.gz dotfiles-d4d546b82006e1bb792a24fa3d9046198e0d1e44.tar.zst dotfiles-d4d546b82006e1bb792a24fa3d9046198e0d1e44.zip | |
fish: add unix2utc, unix2jst, utc2unix and jst2unix
| -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 |
