diff options
Diffstat (limited to 'functions')
| -rw-r--r-- | functions/timestamp.fish | 16 |
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 |