1 /********************************************************************/
2 /*                                                                  */
3 /*  s7   Seed7 interpreter                                          */
4 /*  Copyright (C) 1990 - 2000  Thomas Mertes                        */
5 /*                                                                  */
6 /*  This program is free software; you can redistribute it and/or   */
7 /*  modify it under the terms of the GNU General Public License as  */
8 /*  published by the Free Software Foundation; either version 2 of  */
9 /*  the License, or (at your option) any later version.             */
10 /*                                                                  */
11 /*  This program is distributed in the hope that it will be useful, */
12 /*  but WITHOUT ANY WARRANTY; without even the implied warranty of  */
13 /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   */
14 /*  GNU General Public License for more details.                    */
15 /*                                                                  */
16 /*  You should have received a copy of the GNU General Public       */
17 /*  License along with this program; if not, write to the           */
18 /*  Free Software Foundation, Inc., 51 Franklin Street,             */
19 /*  Fifth Floor, Boston, MA  02110-1301, USA.                       */
20 /*                                                                  */
21 /*  Module: Library                                                 */
22 /*  File: seed7/src/timlib.c                                        */
23 /*  Changes: 1992, 1993, 1994  Thomas Mertes                        */
24 /*  Content: All primitive actions to do time operations.           */
25 /*                                                                  */
26 /********************************************************************/
27 
28 #define LOG_FUNCTIONS 0
29 #define VERBOSE_EXCEPTIONS 0
30 
31 #include "version.h"
32 
33 #include "stdlib.h"
34 #include "stdio.h"
35 #include "time.h"
36 
37 #include "common.h"
38 #include "data.h"
39 #include "syvarutl.h"
40 #include "objutl.h"
41 #include "runerr.h"
42 #include "tim_rtl.h"
43 #include "tim_drv.h"
44 
45 #undef EXTERN
46 #define EXTERN
47 #include "timlib.h"
48 
49 
50 
51 /**
52  *  Wait until the given time is reached
53  *  @param time_zone/arg_8 Difference to UTC in minutes
54  *                         (for UTC+1 it is 60). The time_zone includes
55  *                         the effect of a daylight saving time.
56  */
tim_await(listType arguments)57 objectType tim_await (listType arguments)
58 
59   { /* tim_await */
60     isit_int(arg_1(arguments));
61     isit_int(arg_2(arguments));
62     isit_int(arg_3(arguments));
63     isit_int(arg_4(arguments));
64     isit_int(arg_5(arguments));
65     isit_int(arg_6(arguments));
66     isit_int(arg_7(arguments));
67     isit_int(arg_8(arguments));
68     logFunction(printf("tim_await(" F_D(04) "-" F_D(02) "-" F_D(02) " "
69                                     F_D(02) ":" F_D(02) ":" F_D(02) "."
70                                     F_D(06) ", " FMT_D ")\n",
71                        take_int(arg_1(arguments)),
72                        take_int(arg_2(arguments)),
73                        take_int(arg_3(arguments)),
74                        take_int(arg_4(arguments)),
75                        take_int(arg_5(arguments)),
76                        take_int(arg_6(arguments)),
77                        take_int(arg_7(arguments)),
78                        take_int(arg_8(arguments))););
79     timAwait(take_int(arg_1(arguments)),
80              take_int(arg_2(arguments)),
81              take_int(arg_3(arguments)),
82              take_int(arg_4(arguments)),
83              take_int(arg_5(arguments)),
84              take_int(arg_6(arguments)),
85              take_int(arg_7(arguments)),
86              take_int(arg_8(arguments)));
87     logFunction(printf("tim_await -->\n"););
88     return SYS_EMPTY_OBJECT;
89   } /* tim_await */
90 
91 
92 
93 /**
94  *  Convert a timestamp into a time from the local time zone.
95  *  The timestamp is expressed in seconds since the Unix Epoch.
96  *  The Unix Epoch (1970-01-01 00:00:00 UTC) corresponds to 0.
97  *  @return the local time that corresponds to the timestamp.
98  */
tim_from_timestamp(listType arguments)99 objectType tim_from_timestamp (listType arguments)
100 
101   {
102     boolType is_dst;
103 
104   /* tim_from_timestamp */
105     isit_int(arg_1(arguments));
106     isit_int(arg_2(arguments));
107     isit_int(arg_3(arguments));
108     isit_int(arg_4(arguments));
109     isit_int(arg_5(arguments));
110     isit_int(arg_6(arguments));
111     isit_int(arg_7(arguments));
112     isit_int(arg_8(arguments));
113     isit_int(arg_9(arguments));
114     isit_bool(arg_10(arguments));
115     timFromIntTimestamp(arg_1(arguments)->value.intValue,
116                        &arg_2(arguments)->value.intValue,
117                        &arg_3(arguments)->value.intValue,
118                        &arg_4(arguments)->value.intValue,
119                        &arg_5(arguments)->value.intValue,
120                        &arg_6(arguments)->value.intValue,
121                        &arg_7(arguments)->value.intValue,
122                        &arg_8(arguments)->value.intValue,
123                        &arg_9(arguments)->value.intValue,
124                        &is_dst);
125     if (is_dst) {
126       arg_10(arguments)->value.objValue = SYS_TRUE_OBJECT;
127     } else {
128       arg_10(arguments)->value.objValue = SYS_FALSE_OBJECT;
129     } /* if */
130 /*  fprintf(stderr, "timestamp %10ld  %04ld-%02ld-%02ld %02ld:%02ld:%02ld %7ld\n",
131         arg_1(arguments)->value.intValue,
132         arg_2(arguments)->value.intValue,
133         arg_3(arguments)->value.intValue,
134         arg_4(arguments)->value.intValue,
135         arg_5(arguments)->value.intValue,
136         arg_6(arguments)->value.intValue,
137         arg_7(arguments)->value.intValue,
138         arg_8(arguments)->value.intValue); */
139     return SYS_EMPTY_OBJECT;
140   } /* tim_from_timestamp */
141 
142 
143 
144 /**
145  *  Determine the current local time.
146  *  @param time_zone/arg_8 Difference to UTC in minutes
147  *                         (for UTC+1 it is 60). The time_zone includes
148  *                         the effect of a daylight saving time.
149  *  @param is_dst/arg_9 Is TRUE, if a daylight saving time is
150  *                      currently in effect.
151  */
tim_now(listType arguments)152 objectType tim_now (listType arguments)
153 
154   {
155     boolType is_dst;
156 
157   /* tim_now */
158     isit_int(arg_1(arguments));
159     isit_int(arg_2(arguments));
160     isit_int(arg_3(arguments));
161     isit_int(arg_4(arguments));
162     isit_int(arg_5(arguments));
163     isit_int(arg_6(arguments));
164     isit_int(arg_7(arguments));
165     isit_int(arg_8(arguments));
166     isit_bool(arg_9(arguments));
167     timNow(&arg_1(arguments)->value.intValue,
168            &arg_2(arguments)->value.intValue,
169            &arg_3(arguments)->value.intValue,
170            &arg_4(arguments)->value.intValue,
171            &arg_5(arguments)->value.intValue,
172            &arg_6(arguments)->value.intValue,
173            &arg_7(arguments)->value.intValue,
174            &arg_8(arguments)->value.intValue,
175            &is_dst);
176     if (is_dst) {
177       arg_9(arguments)->value.objValue = SYS_TRUE_OBJECT;
178     } else {
179       arg_9(arguments)->value.objValue = SYS_FALSE_OBJECT;
180     } /* if */
181 /*  fprintf(stderr, "now      %04ld-%02ld-%02ld %02ld:%02ld:%02ld %7ld\n",
182         arg_1(arguments)->value.intValue,
183         arg_2(arguments)->value.intValue,
184         arg_3(arguments)->value.intValue,
185         arg_4(arguments)->value.intValue,
186         arg_5(arguments)->value.intValue,
187         arg_6(arguments)->value.intValue,
188         arg_7(arguments)->value.intValue); */
189     return SYS_EMPTY_OBJECT;
190   } /* tim_now */
191 
192 
193 
194 /**
195  *  Sets timeZone and daylightSavingTime for a given time.
196  *  @return the time in the local time zone.
197  */
tim_set_local_tz(listType arguments)198 objectType tim_set_local_tz (listType arguments)
199 
200   {
201     boolType is_dst;
202 
203   /* tim_set_local_tz */
204     isit_int(arg_1(arguments));
205     isit_int(arg_2(arguments));
206     isit_int(arg_3(arguments));
207     isit_int(arg_4(arguments));
208     isit_int(arg_5(arguments));
209     isit_int(arg_6(arguments));
210     isit_int(arg_7(arguments));
211     isit_bool(arg_8(arguments));
212     timSetLocalTZ(take_int(arg_1(arguments)),
213                   take_int(arg_2(arguments)),
214                   take_int(arg_3(arguments)),
215                   take_int(arg_4(arguments)),
216                   take_int(arg_5(arguments)),
217                   take_int(arg_6(arguments)),
218                   &arg_7(arguments)->value.intValue,
219                   &is_dst);
220     if (is_dst) {
221       arg_8(arguments)->value.objValue = SYS_TRUE_OBJECT;
222     } else {
223       arg_8(arguments)->value.objValue = SYS_FALSE_OBJECT;
224     } /* if */
225 /*  fprintf(stderr, "tim_set_local_tz %04ld-%02ld-%02ld %02ld:%02ld:%02ld %7ld %d\n",
226         take_int(arg_1(arguments)),
227         take_int(arg_2(arguments)),
228         take_int(arg_3(arguments)),
229         take_int(arg_4(arguments)),
230         take_int(arg_5(arguments)),
231         take_int(arg_6(arguments)),
232         take_int(arg_7(arguments)),
233         is_dst); */
234     return SYS_EMPTY_OBJECT;
235   } /* tim_set_local_tz */
236