1 /*
2  * $Id: wce_time.h,v 1.2 2006/04/09 16:48:18 mloskot Exp $
3  *
4  * time.h and sys/time.h - time types and functions
5  *
6  * Created by Mateusz Loskot (mateusz@loskot.net)
7  *
8  * Copyright (c) 2006 Taxus SI Ltd.
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining
11  * a copy of this software and associated documentation files (the "Software"),
12  * to deal in the Software without restriction, including without limitation
13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  * and/or sell copies of the Software, and to permit persons to whom
15  * the Software is furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included
18  * in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
26  * THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27  *
28  * MIT License:
29  * http://opensource.org/licenses/mit-license.php
30  *
31  * Contact:
32  * Taxus SI Ltd.
33  * http://www.taxussi.com.pl
34  *
35  */
36 #ifndef WCEEX_TIME_H
37 #define WCEEX_TIME_H 1
38 
39 #if !defined(_WIN32_WCE)
40 # error "Only Winddows CE target is supported!"
41 #endif
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif  /* __cplusplus */
46 
47 /*******************************************************************************
48     Types and macros definition
49 *******************************************************************************/
50 
51 #ifndef _TIME_T_DEFINED
52 typedef long    time_t;		/* time value as number of seconds of the Epoch */
53 #define _TIME_T_DEFINED
54 #endif /* _TIME_T_DEFINED */
55 
56 #ifndef _TM_DEFINED
57 struct tm
58 {
59 	int tm_sec;     /* seconds after the minute - [0,59] */
60 	int tm_min;     /* minutes after the hour - [0,59] */
61 	int tm_hour;	/* hours since midnight - [0,23] */
62 	int tm_mday;	/* day of the month - [1,31] */
63 	int tm_mon;     /* months since January - [0,11] */
64 	int tm_year;	/* years since 1900 */
65 	int tm_wday;	/* days since Sunday - [0,6] */
66 	int tm_yday;	/* days since January 1 - [0,365] */
67 	int tm_isdst;	/* daylight savings time flag */
68 };
69 #define _TM_DEFINED
70 #endif /* _TM_DEFINED */
71 
72 #ifndef _TIMEZONE_DEFINED
73 struct timezone
74 {
75     int tz_minuteswest; /* minutes W of Greenwich */
76     int tz_dsttime;     /* type of dst correction */
77 };
78 #define _TIMEZONE_DEFINED
79 #endif /* _TIMEZONE_DEFINED */
80 
81 /*
82  * Constants used internally by time functions.
83  */
84 
85 #if defined(_MSC_VER) || defined(__BORLANDC__)
86 #define EPOCHFILETIME (116444736000000000i64)
87 #else
88 #define EPOCHFILETIME (116444736000000000LL)
89 #endif
90 
91 /* Epoch base year */
92 #define EPOCH_YEAR 1970
93 
94 /* tm struct members conversion units */
95 #define TM_YEAR_BASE    1900    /* tm_year base year */
96 #define TM_MONTH_MIN    0       /* tm_mon = 0 - January */
97 #define TM_MONTH_MAX    11      /* tm_mon = 11 - December */
98 
99 #define MIN_SEC         60                  /* seconds in a minute */
100 #define HOUR_SEC        3600                /* seconds in an hour */
101 #define DAY_SEC         86400               /* seconds in a day */
102 #define YEAR_SEC        (365 * DAY_SEC)     /* seconds in a year */
103 #define FOUR_YEAR_SEC   (4 * YEAR_SEC + 1)  /* seconds in a 4-year period */
104 
105 /*
106 In every, 400 year period (greg) is an interval of the same
107 number of days: 365 x 400 + 97 = 146097
108 Also, there are 97 leap days in every such 400 years interval
109 */
110 #define LEAP_DAYS_IN_GREG   97
111 #define GREG_YEARS   400
112 #define GREG_DAYS    (365 * GREG_YEARS + LEAP_DAYS_IN_GREG)
113 #define GREG_SECS    (GREG_DAYS * DAY_SEC)
114 
115 /* Checks if given year is a leap year. */
116 #define IS_LEAP_YEAR(year) \
117     (((year) % 4) == 0 && (((year) % 100) != 0 || ((year) % 400) == 0))
118 
119 /*******************************************************************************
120     time.h functions
121 *******************************************************************************/
122 
123 time_t wceex_time(time_t *timer);
124 time_t wceex_mktime(struct tm *tmbuff);
125 time_t wceex_gmmktime(struct tm *tmbuff);
126 
127 struct tm * wceex_localtime(const time_t *timer);
128 struct tm * wceex_gmtime(const time_t *timer);
129 
130 char * wceex_ctime(const time_t *timer);
131 char * wceex_ctime_r(const time_t *timer, char *buf);
132 
133 char * wceex_asctime(const struct tm *tmbuff);
134 char * wceex_asctime_r(const struct tm *tbuff, char *buff);
135 
136 /*******************************************************************************
137     sys/time.h functions
138 *******************************************************************************/
139 
140 int wceex_gettimeofday(struct timeval *tp, struct timezone *tzp);
141 
142 /*******************************************************************************
143     Internal functions prototypes.
144 *******************************************************************************/
145 
146 /* Internal function to get time value from tm struc. */
147 extern time_t __wceex_mktime_utc(struct tm *tmbuff);
148 
149 
150 
151 #ifdef __cplusplus
152 }
153 #endif  /* __cplusplus */
154 
155 #endif /* #ifndef WCEEX_TIME_H */
156 
157