blob: 6a4c0ed70646d112e7c65beff5f90bc6b51a39e1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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"
end
end
|