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

Re: Converting time with EPOCHSECONDS and zmodload zsh/datetime



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) ))



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