I sent this just to Jack by mistake, but I guess it might be of wider
interest.
On Thu, 7 Feb 2019, Riccardo (Jack) Lucchetti wrote:
On Thu, 7 Feb 2019, Allin Cottrell wrote:
> [...] I think it might be nice to return a 2-vector holding
> time_t and epoch day. Then
>
> if $now[1] > n
>
> would have one-second resolution and
>
> if $now[2] > n
>
> would have one-day resolution, and now[2] could be passed directly to
> isodate() or juldate().
sounds good to me!
Here's what I just pushed to git: $now gives a 2-vector with Epoch
seconds (time_t) first then ISO 8601 basic date (numeric, YYYYMMDD).
I've modified the epochday() function so that it will accept a single
argument in the latter form in place of separate Y, M and D arguments.
I've also exposed strftime under the name "strtime": you can pass it
$now[1] to get formatted date/time. The default format is "%c" ("the
preferred date and time representation for the current locale") but
you can pass a format of your own choosing via a second, optional
string argument. The possibilities for this can be found in the
strftime manpage.
http://man7.org/linux/man-pages/man3/strftime.3.html
<input>
matrix tm = $now
printf "seconds since Epoch %.0f, ISO basic date %d\n", tm[1], tm[2]
eval strtime(tm[1])
eval epochday(tm[2])
s = strtime(tm[1], "It's now %l:%M %p on %A.")
s
</input>
<output>
? matrix tm = $now
Generated matrix tm
seconds since Epoch 1549567516, ISO basic date 20190207
? eval strtime(tm[1])
Thu 07 Feb 2019 02:25:16 PM EST
? eval epochday(tm[2])
737097
? s = strtime(tm[1], "It's now %l:%M %p on %A.")
Generated string s
? s
It's now 2:25 PM on Thursday.
</output>
Allin