diff options
author | Carsten Haitzler <raster@rasterman.com> | 2004-03-29 11:58:57 +0000 |
---|---|---|
committer | Carsten Haitzler <raster@rasterman.com> | 2004-03-29 11:58:57 +0000 |
commit | 811cd94fbab432b59866aed3b9a724fe66227a4a (patch) | |
tree | 5271e95060d2acd529857b5d6e6d06b1b5dd5522 /legacy/embryo/src/lib/embryo_time.c | |
parent | 419bd778771ae100be0402de0795b71052cbd58e (diff) |
more meaty api...
SVN revision: 9518
Diffstat (limited to '')
-rw-r--r-- | legacy/embryo/src/lib/embryo_time.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/legacy/embryo/src/lib/embryo_time.c b/legacy/embryo/src/lib/embryo_time.c new file mode 100644 index 0000000000..6601bffafe --- /dev/null +++ b/legacy/embryo/src/lib/embryo_time.c | |||
@@ -0,0 +1,68 @@ | |||
1 | #include "embryo_private.h" | ||
2 | #include <sys/time.h> | ||
3 | #include <time.h> | ||
4 | |||
5 | /* exported time api */ | ||
6 | |||
7 | static Embryo_Cell | ||
8 | _embryo_time_seconds(Embryo_Program *ep, Embryo_Cell *params) | ||
9 | { | ||
10 | struct timeval timev; | ||
11 | double t; | ||
12 | float f; | ||
13 | |||
14 | gettimeofday(&timev, NULL); | ||
15 | t = (double)(timev.tv_sec - ((timev.tv_sec / (60 * 60 * 24)) * (60 * 60 * 24))) | ||
16 | + (((double)timev.tv_usec) / 1000000); | ||
17 | f = (float)t; | ||
18 | return EMBRYO_FLOAT_TO_CELL(f); | ||
19 | } | ||
20 | |||
21 | static Embryo_Cell | ||
22 | _embryo_time_date(Embryo_Program *ep, Embryo_Cell *params) | ||
23 | { | ||
24 | struct timeval timev; | ||
25 | struct tm *tm; | ||
26 | time_t tt; | ||
27 | |||
28 | if (params[0] != (8 * sizeof(Embryo_Cell))) return 0; | ||
29 | gettimeofday(&timev, NULL); | ||
30 | tt = (time_t)(timev.tv_sec); | ||
31 | tm = localtime(&tt); | ||
32 | if (tm) | ||
33 | { | ||
34 | Embryo_Cell *cptr; | ||
35 | double t; | ||
36 | float f; | ||
37 | |||
38 | cptr = embryo_data_address_get(ep, params[1]); | ||
39 | if (cptr) *cptr = tm->tm_year + 1900; | ||
40 | cptr = embryo_data_address_get(ep, params[2]); | ||
41 | if (cptr) *cptr = tm->tm_mon + 1; | ||
42 | cptr = embryo_data_address_get(ep, params[3]); | ||
43 | if (cptr) *cptr = tm->tm_mday; | ||
44 | cptr = embryo_data_address_get(ep, params[4]); | ||
45 | if (cptr) *cptr = tm->tm_yday; | ||
46 | cptr = embryo_data_address_get(ep, params[5]); | ||
47 | if (cptr) *cptr = (tm->tm_wday + 6) % 7; | ||
48 | cptr = embryo_data_address_get(ep, params[6]); | ||
49 | if (cptr) *cptr = tm->tm_hour; | ||
50 | cptr = embryo_data_address_get(ep, params[7]); | ||
51 | if (cptr) *cptr = tm->tm_min; | ||
52 | cptr = embryo_data_address_get(ep, params[8]); | ||
53 | t = (double)tm->tm_sec + (((double)timev.tv_usec) / 1000000); | ||
54 | f = (float)t; | ||
55 | if (cptr) *cptr = EMBRYO_FLOAT_TO_CELL(f); | ||
56 | |||
57 | } | ||
58 | return 0; | ||
59 | } | ||
60 | |||
61 | /* functions used by the rest of embryo */ | ||
62 | |||
63 | void | ||
64 | _embryo_time_init(Embryo_Program *ep) | ||
65 | { | ||
66 | embryo_program_native_call_add(ep, "seconds", _embryo_time_seconds); | ||
67 | embryo_program_native_call_add(ep, "date", _embryo_time_date); | ||
68 | } | ||