5 #ifndef HAVE_GETTIMEOFDAY
6 # error "Your platform isn't supported yet"
13 # include <winsock2.h>
21 #include "embryo_private.h"
23 /* exported time api */
26 _embryo_time_seconds(Embryo_Program *ep __UNUSED__, Embryo_Cell *params __UNUSED__)
32 gettimeofday(&timev, NULL);
33 t = (double)(timev.tv_sec - ((timev.tv_sec / (60 * 60 * 24)) * (60 * 60 * 24)))
34 + (((double)timev.tv_usec) / 1000000);
36 return EMBRYO_FLOAT_TO_CELL(f);
40 _embryo_time_date(Embryo_Program *ep, Embryo_Cell *params)
42 static time_t last_tzset = 0;
47 if (params[0] != (8 * sizeof(Embryo_Cell))) return 0;
48 gettimeofday(&timev, NULL);
49 tt = (time_t)(timev.tv_sec);
50 if ((tt > (last_tzset + 1)) ||
51 (tt < (last_tzset - 1)))
63 cptr = embryo_data_address_get(ep, params[1]);
64 if (cptr) *cptr = tm->tm_year + 1900;
65 cptr = embryo_data_address_get(ep, params[2]);
66 if (cptr) *cptr = tm->tm_mon + 1;
67 cptr = embryo_data_address_get(ep, params[3]);
68 if (cptr) *cptr = tm->tm_mday;
69 cptr = embryo_data_address_get(ep, params[4]);
70 if (cptr) *cptr = tm->tm_yday;
71 cptr = embryo_data_address_get(ep, params[5]);
72 if (cptr) *cptr = (tm->tm_wday + 6) % 7;
73 cptr = embryo_data_address_get(ep, params[6]);
74 if (cptr) *cptr = tm->tm_hour;
75 cptr = embryo_data_address_get(ep, params[7]);
76 if (cptr) *cptr = tm->tm_min;
77 cptr = embryo_data_address_get(ep, params[8]);
78 t = (double)tm->tm_sec + (((double)timev.tv_usec) / 1000000);
80 if (cptr) *cptr = EMBRYO_FLOAT_TO_CELL(f);
86 /* functions used by the rest of embryo */
89 _embryo_time_init(Embryo_Program *ep)
91 embryo_program_native_call_add(ep, "seconds", _embryo_time_seconds);
92 embryo_program_native_call_add(ep, "date", _embryo_time_date);