summaryrefslogtreecommitdiff
path: root/functions/timestamp.fish
diff options
context:
space:
mode:
authorache <ache@ache.one>2024-08-09 04:25:24 +0200
committerache <ache@ache.one>2024-08-09 04:25:24 +0200
commit1b88f87cb1755e3a5ff8199962687773be936164 (patch)
tree809dc5c3a6a5cca6627d3f7357c560654332bfc2 /functions/timestamp.fish
parentIPv6 ctrl (diff)
Improve timestamp function
Diffstat (limited to 'functions/timestamp.fish')
-rw-r--r--functions/timestamp.fish16
1 files changed, 15 insertions, 1 deletions
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