May be the collection of what is below may serve as an example

regards,
  Danil

require'dll'
cocurrent'unx'
NB. indexes of field in C struct tm
'tm_sec tm_min tm_hour tm_mday tm_mon tm_year tm_wday tm_yday tm_isdst'=:i.9
Jtm_map  =: tm_year,tm_mon,tm_mday,tm_hour,tm_min,tm_sec  NB. index map
from C to J
tmJ_map  =: /:/:Jtm_map                                   NB. index map
from J to C

Jcstr    =:((i.&({.a.) {.])@:>)"0 NB. take the boxed C str and return
unboxed up to /0
mallocTrim =: ((unxlib'c'), ' malloc_trim >i i')&cd
time     =:((unxlib'c'),' time >i *i')cd [:<1$0:  NB. y ignored, unboxed
epoch integer
NB. ctime gets epoch integer, asctime - boxed C struct, both return boxed C
string
ctime    =:(2{((unxlib'c'),' ctime_r *c *i *c')cd (32$' ');~,: )"0
asctime  =:(2{((unxlib'c'),' asctime_r *c *i *c')cd (32$' ');~> )"0
NB. both gmtime and localtime get epoch int and return boxed tm struct
NB. gmtime result is adjusted to GMT, localtime is local (unchanged)
gmtime   =:(2{((unxlib'c'),' gmtime_r *i *i *i')cd (9$0);~,: )"0
localtime=:(2{((unxlib'c'),' localtime_r *i *i *i')cd (9$0);~,: )"0
mktime   =:(((unxlib'c'),' mktime >i *i')cd])  "0            NB. mktime
takes boxed tm C struct, yields epoch time
Jtm      =:(([: ((1900+{.),}.) Jtm_map{])@:> ) "0         NB. convert C tm
to J 6!:0 format
tmJ      =:([:<9{.tmJ_map{((_1900+{.),}.)@:<.) "1         NB. convert J
6!:0 format to C tm
epochJ   =: (mktime@:tmJ) :. Jepoch_unx_                  NB. convert J to
C epoch int
Jepoch   =: (Jtm@:localtime) :. epochJ_unx_            NB. convert C epoch
int to J

cocurrent'base'

2018-01-23 8:23 GMT+03:00 bill lam <[email protected]>:

> Apart from using addons as suggested by Ric Sherlock, you can also try
> directly calling strftime in libc.
>
> On Jan 23, 2018 11:02 AM, "Ian Clark" <[email protected]> wrote:
>
> > (6!:0 NIL) returns the current date/time as an integer 6-list timestamp.
> >
> > (6!:0 'hh:mm:ss MM/DD/YY') ditto, but in the specified format (y).
> >
> > How can I use the *selfsame* algorithm to format any (valid) timestamp?
> >
> > If the answer is "only by writing my own formatting verb, or by setting
> the
> > system clock", might there be a case for extending (6!:0) to take an
> > optional (x)? Not just an integer 6-list timestamp as described, but a
> few
> > other forms, like (_1) meaning yesterday.
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to