zsh-users
 help / color / mirror / code / Atom feed
* Converting time with EPOCHSECONDS and zmodload zsh/datetime
@ 2011-08-22  5:30 TJ Luoma
  2011-08-22 14:48 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: TJ Luoma @ 2011-08-22  5:30 UTC (permalink / raw)
  To: Zsh Users

I'm just learning 'zmodload zsh/datetime'

I know I can use

	strftime %Y-%m-%d_%H.%M.%S $EPOCHSECONDS

to get a time format like 2011-08-21_14.45.38


If I know that something it going to happen in 22:05:03 (22hrs 5
minutes 3 seconds) from now, how do I convert that to a specific time
like `strftime %Y-%m-%d_%H.%M.%S`?

TjL


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Converting time with EPOCHSECONDS and zmodload zsh/datetime
  2011-08-22  5:30 Converting time with EPOCHSECONDS and zmodload zsh/datetime TJ Luoma
@ 2011-08-22 14:48 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2011-08-22 14:48 UTC (permalink / raw)
  To: Zsh Users

On Aug 22,  1:30am, TJ Luoma wrote:
}
} If I know that something it going to happen in 22:05:03 (22hrs 5
} minutes 3 seconds) from now, how do I convert that to a specific time
} like `strftime %Y-%m-%d_%H.%M.%S`?

$((EPOCHSECONDS + 22 * 3600 + 5 * 60 + 3))

Something like

    hms2s() {
      setopt localoptions no_octal_zeroes
      argv[1]=( ${(s.:.)1} )
      print $(($1 * 3600 + $2 * 60 + $3))
    }

    strftime %Y-%m-%d_%H.%M.%S $(( EPOCHSECONDS + $(hms2s 22:05:03) ))

Or you can make a math function:

    hms2s() { ((${1:-0} * 3600 + ${2:-0} * 60 + ${3:-0})) }
    functions -M hms2s 1 3

    strftime %Y-%m-%d_%H.%M.%S $(( EPOCHSECONDS + hms2s(22,5,3) ))


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-08-22 14:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-22  5:30 Converting time with EPOCHSECONDS and zmodload zsh/datetime TJ Luoma
2011-08-22 14:48 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).