Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Useful zsh/datetime things



In the latest 4.1.1 dev version from CVS, we have the zsh/datetime module,
which defines a strftime builtin and the EPOCHSECONDS variable.  Here are
a couple of simple helper functions that make use of these:

function ctime {
  # Print the current or argument time in standard format
  local time=${1:-$EPOCHSECONDS}
  strftime "%a %b %e %H:%M:%S %Y" $time
}
function starttime {
  # Print the time this shell was started
  # (doesn't work if SECONDS has been reset)
  typeset -i SECONDS=$SECONDS	# No floating point
  ctime $((EPOCHSECONDS - SECONDS))
}
function rfcdate {
  # Like GNU "date -R"
  strftime "%a, %e %b %Y %H:%M:%S %z" $EPOCHSECONDS
}

A useful addition to strftime would be an option to assign the result to a
parameter, similar to the -A and -H options of "stat" (from zsh/stat).

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



Messages sorted by: Reverse Date, Date, Thread, Author