From 1b88f87cb1755e3a5ff8199962687773be936164 Mon Sep 17 00:00:00 2001 From: ache Date: Fri, 9 Aug 2024 04:25:24 +0200 Subject: Improve timestamp function --- functions/timestamp.fish | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'functions') diff --git a/functions/timestamp.fish b/functions/timestamp.fish index 6ea08e2..6a4c0ed 100644 --- a/functions/timestamp.fish +++ b/functions/timestamp.fish @@ -1,4 +1,18 @@ +# Deal with timestamps using the date command function timestamp --wraps "date" --description "Return current unix timestamp" + # Without argument it only prints the current timestamp + if test (count $argv) -gt 0 + # If the argument if help or --help or -h, it prints usage. + if test "$argv[1]" = "--help" -o "$argv[1]" = "-h" -o "$argv[1]" = "help" + echo -e "timestamp [TIMESTAMP]\n" + echo "Print the current timestamp" + echo "Pass a timestamp to get the corresponding date, so timestamp (timestamp) = date." + else + # Convert the argument to ISO 8601 date + date --iso-8601=seconds -d @$argv[1] + end + else # The Unix timestamp is the number of seconds from 01 January 1970 (the unix epoch date) - date "%s" + date "+%s" + end end -- cgit v1.3-2-g11bf