5 #ifndef HAVE_GETTIMEOFDAY
6 # error "Your platform isn't supported yet"
17 #include "embryo_private.h"
19 /* exported time api */
22 _embryo_time_seconds(Embryo_Program *ep __UNUSED__, Embryo_Cell *params __UNUSED__)
28 gettimeofday(&timev, NULL);
29 t = (double)(timev.tv_sec - ((timev.tv_sec / (60 * 60 * 24)) * (60 * 60 * 24)))
30 + (((double)timev.tv_usec) / 1000000);
32 return EMBRYO_FLOAT_TO_CELL(f);
36 _embryo_time_date(Embryo_Program *ep, Embryo_Cell *params)
38 static time_t last_tzset = 0;
43 if (params[0] != (8 * sizeof(Embryo_Cell))) return 0;
44 gettimeofday(&timev, NULL);
45 tt = (time_t)(timev.tv_sec);
46 if ((tt > (last_tzset + 1)) ||
47 (tt < (last_tzset - 1)))
59 cptr = embryo_data_address_get(ep, params[1]);
60 if (cptr) *cptr = tm->tm_year + 1900;
61 cptr = embryo_data_address_get(ep, params[2]);
62 if (cptr) *cptr = tm->tm_mon + 1;
63 cptr = embryo_data_address_get(ep, params[3]);
64 if (cptr) *cptr = tm->tm_mday;
65 cptr = embryo_data_address_get(ep, params[4]);
66 if (cptr) *cptr = tm->tm_yday;
67 cptr = embryo_data_address_get(ep, params[5]);
68 if (cptr) *cptr = (tm->tm_wday + 6) % 7;
69 cptr = embryo_data_address_get(ep, params[6]);
70 if (cptr) *cptr = tm->tm_hour;
71 cptr = embryo_data_address_get(ep, params[7]);
72 if (cptr) *cptr = tm->tm_min;
73 cptr = embryo_data_address_get(ep, params[8]);
74 t = (double)tm->tm_sec + (((double)timev.tv_usec) / 1000000);
76 if (cptr) *cptr = EMBRYO_FLOAT_TO_CELL(f);
82 /* functions used by the rest of embryo */
85 _embryo_time_init(Embryo_Program *ep)
87 embryo_program_native_call_add(ep, "seconds", _embryo_time_seconds);
88 embryo_program_native_call_add(ep, "date", _embryo_time_date);