From 00135d1c287b434aa4eda4a4f68a356f912927bd Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 7 May 2024 13:57:45 +0300 Subject: [PATCH] feat(tools/when): simple time-conversion tool I often need unix timestamps, or have unix timestamps, or need timestamps at certain relative offsets etc. This adds a tool called `when` which can do all of this. It has basically no user interface, you just call it with a time query and it does it if it understands what you meant. This will get smarter over time as I find more uses. Example: ~> when yesterday 5PM Local: Mon 06 May 2024 at 17:00:00 MSK UTC: 2024-05-06T14:00:00Z UNIX: 1715004000 It supports all kinds of queries already, see the usage for details. Change-Id: I694ffef7608586acfb1ff8010ac0fac4d9951e2e Reviewed-on: https://cl.tvl.fyi/c/depot/+/11598 Tested-by: BuildkiteCI Autosubmit: tazjin Reviewed-by: tazjin --- tools/when/default.nix | 6 ++ tools/when/when.go | 141 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 tools/when/default.nix create mode 100644 tools/when/when.go diff --git a/tools/when/default.nix b/tools/when/default.nix new file mode 100644 index 000000000..1aee5e1ea --- /dev/null +++ b/tools/when/default.nix @@ -0,0 +1,6 @@ +{ depot, ... }: + +depot.nix.buildGo.program { + name = "when"; + srcs = [ ./when.go ]; +} diff --git a/tools/when/when.go b/tools/when/when.go new file mode 100644 index 000000000..3102328fe --- /dev/null +++ b/tools/when/when.go @@ -0,0 +1,141 @@ +package main + +import ( + "fmt" + "os" + "strconv" + "time" +) + +const usage = `usage: when