VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/include/prtime.h@ 26515

Last change on this file since 26515 was 11551, checked in by vboxsync, 16 years ago

API/xpcom: prefix any C symbols in VBoxXPCOM.so, to avoid namespace pollution. Enabled only on Linux at the moment.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.0 KB
Line 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is the Netscape Portable Runtime (NSPR).
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38/*
39 *----------------------------------------------------------------------
40 *
41 * prtime.h --
42 *
43 * NSPR date and time functions
44 *
45 *-----------------------------------------------------------------------
46 */
47
48#ifndef prtime_h___
49#define prtime_h___
50
51#include "prlong.h"
52
53#ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
54#define PR_Now VBoxNsprPR_Now
55#define PR_ExplodeTime VBoxNsprPR_ExplodeTime
56#define PR_ImplodeTime VBoxNsprPR_ImplodeTime
57#define PR_NormalizeTime VBoxNsprPR_NormalizeTime
58#define PR_LocalTimeParameters VBoxNsprPR_LocalTimeParameters
59#define PR_GMTParameters VBoxNsprPR_GMTParameters
60#define PR_USPacificTimeParameters VBoxNsprPR_USPacificTimeParameters
61#define PR_ParseTimeString VBoxNsprPR_ParseTimeString
62#define PR_FormatTime VBoxNsprPR_FormatTime
63#define PR_FormatTimeUSEnglish VBoxNsprPR_FormatTimeUSEnglish
64#endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
65
66PR_BEGIN_EXTERN_C
67
68/**********************************************************************/
69/************************* TYPES AND CONSTANTS ************************/
70/**********************************************************************/
71
72#define PR_MSEC_PER_SEC 1000UL
73#define PR_USEC_PER_SEC 1000000UL
74#define PR_NSEC_PER_SEC 1000000000UL
75#define PR_USEC_PER_MSEC 1000UL
76#define PR_NSEC_PER_MSEC 1000000UL
77
78/*
79 * PRTime --
80 *
81 * NSPR represents basic time as 64-bit signed integers relative
82 * to midnight (00:00:00), January 1, 1970 Greenwich Mean Time (GMT).
83 * (GMT is also known as Coordinated Universal Time, UTC.)
84 * The units of time are in microseconds. Negative times are allowed
85 * to represent times prior to the January 1970 epoch. Such values are
86 * intended to be exported to other systems or converted to human
87 * readable form.
88 *
89 * Notes on porting: PRTime corresponds to time_t in ANSI C. NSPR 1.0
90 * simply uses PRInt64.
91 */
92
93typedef PRInt64 PRTime;
94
95/*
96 * Time zone and daylight saving time corrections applied to GMT to
97 * obtain the local time of some geographic location
98 */
99
100typedef struct PRTimeParameters {
101 PRInt32 tp_gmt_offset; /* the offset from GMT in seconds */
102 PRInt32 tp_dst_offset; /* contribution of DST in seconds */
103} PRTimeParameters;
104
105/*
106 * PRExplodedTime --
107 *
108 * Time broken down into human-readable components such as year, month,
109 * day, hour, minute, second, and microsecond. Time zone and daylight
110 * saving time corrections may be applied. If they are applied, the
111 * offsets from the GMT must be saved in the 'tm_params' field so that
112 * all the information is available to reconstruct GMT.
113 *
114 * Notes on porting: PRExplodedTime corrresponds to struct tm in
115 * ANSI C, with the following differences:
116 * - an additional field tm_usec;
117 * - replacing tm_isdst by tm_params;
118 * - the month field is spelled tm_month, not tm_mon;
119 * - we use absolute year, AD, not the year since 1900.
120 * The corresponding type in NSPR 1.0 is called PRTime. Below is
121 * a table of date/time type correspondence in the three APIs:
122 * API time since epoch time in components
123 * ANSI C time_t struct tm
124 * NSPR 1.0 PRInt64 PRTime
125 * NSPR 2.0 PRTime PRExplodedTime
126 */
127
128typedef struct PRExplodedTime {
129 PRInt32 tm_usec; /* microseconds past tm_sec (0-99999) */
130 PRInt32 tm_sec; /* seconds past tm_min (0-61, accomodating
131 up to two leap seconds) */
132 PRInt32 tm_min; /* minutes past tm_hour (0-59) */
133 PRInt32 tm_hour; /* hours past tm_day (0-23) */
134 PRInt32 tm_mday; /* days past tm_mon (1-31, note that it
135 starts from 1) */
136 PRInt32 tm_month; /* months past tm_year (0-11, Jan = 0) */
137 PRInt16 tm_year; /* absolute year, AD (note that we do not
138 count from 1900) */
139
140 PRInt8 tm_wday; /* calculated day of the week
141 (0-6, Sun = 0) */
142 PRInt16 tm_yday; /* calculated day of the year
143 (0-365, Jan 1 = 0) */
144
145 PRTimeParameters tm_params; /* time parameters used by conversion */
146} PRExplodedTime;
147
148/*
149 * PRTimeParamFn --
150 *
151 * A function of PRTimeParamFn type returns the time zone and
152 * daylight saving time corrections for some geographic location,
153 * given the current time in GMT. The input argument gmt should
154 * point to a PRExplodedTime that is in GMT, i.e., whose
155 * tm_params contains all 0's.
156 *
157 * For any time zone other than GMT, the computation is intended to
158 * consist of two steps:
159 * - Figure out the time zone correction, tp_gmt_offset. This number
160 * usually depends on the geographic location only. But it may
161 * also depend on the current time. For example, all of China
162 * is one time zone right now. But this situation may change
163 * in the future.
164 * - Figure out the daylight saving time correction, tp_dst_offset.
165 * This number depends on both the geographic location and the
166 * current time. Most of the DST rules are expressed in local
167 * current time. If so, one should apply the time zone correction
168 * to GMT before applying the DST rules.
169 */
170
171typedef PRTimeParameters (PR_CALLBACK *PRTimeParamFn)(const PRExplodedTime *gmt);
172
173/**********************************************************************/
174/****************************** FUNCTIONS *****************************/
175/**********************************************************************/
176
177/*
178 * The PR_Now routine returns the current time relative to the
179 * epoch, midnight, January 1, 1970 UTC. The units of the returned
180 * value are microseconds since the epoch.
181 *
182 * The values returned are not guaranteed to advance in a linear fashion
183 * due to the application of time correction protocols which synchronize
184 * computer clocks to some external time source. Consequently it should
185 * not be depended on for interval timing.
186 *
187 * The implementation is machine dependent.
188 * Cf. time_t time(time_t *tp) in ANSI C.
189 */
190#if defined(HAVE_WATCOM_BUG_2)
191PRTime __pascal __export __loadds
192#else
193NSPR_API(PRTime)
194#endif
195PR_Now(void);
196
197/*
198 * Expand time binding it to time parameters provided by PRTimeParamFn.
199 * The calculation is envisoned to proceed in the following steps:
200 * - From given PRTime, calculate PRExplodedTime in GMT
201 * - Apply the given PRTimeParamFn to the GMT that we just calculated
202 * to obtain PRTimeParameters.
203 * - Add the PRTimeParameters offsets to GMT to get the local time
204 * as PRExplodedTime.
205 */
206
207NSPR_API(void) PR_ExplodeTime(
208 PRTime usecs, PRTimeParamFn params, PRExplodedTime *exploded);
209
210/* Reverse operation of PR_ExplodeTime */
211#if defined(HAVE_WATCOM_BUG_2)
212PRTime __pascal __export __loadds
213#else
214NSPR_API(PRTime)
215#endif
216PR_ImplodeTime(const PRExplodedTime *exploded);
217
218/*
219 * Adjust exploded time to normalize field overflows after manipulation.
220 * Note that the following fields of PRExplodedTime should not be
221 * manipulated:
222 * - tm_month and tm_year: because the number of days in a month and
223 * number of days in a year are not constant, it is ambiguous to
224 * manipulate the month and year fields, although one may be tempted
225 * to. For example, what does "a month from January 31st" mean?
226 * - tm_wday and tm_yday: these fields are calculated by NSPR. Users
227 * should treat them as "read-only".
228 */
229
230NSPR_API(void) PR_NormalizeTime(
231 PRExplodedTime *exploded, PRTimeParamFn params);
232
233/**********************************************************************/
234/*********************** TIME PARAMETER FUNCTIONS *********************/
235/**********************************************************************/
236
237/* Time parameters that suit current host machine */
238NSPR_API(PRTimeParameters) PR_LocalTimeParameters(const PRExplodedTime *gmt);
239
240/* Time parameters that represent Greenwich Mean Time */
241NSPR_API(PRTimeParameters) PR_GMTParameters(const PRExplodedTime *gmt);
242
243/*
244 * Time parameters that represent the US Pacific Time Zone, with the
245 * current daylight saving time rules (for testing only)
246 */
247NSPR_API(PRTimeParameters) PR_USPacificTimeParameters(const PRExplodedTime *gmt);
248
249/*
250 * This parses a time/date string into a PRTime
251 * (microseconds after "1-Jan-1970 00:00:00 GMT").
252 * It returns PR_SUCCESS on success, and PR_FAILURE
253 * if the time/date string can't be parsed.
254 *
255 * Many formats are handled, including:
256 *
257 * 14 Apr 89 03:20:12
258 * 14 Apr 89 03:20 GMT
259 * Fri, 17 Mar 89 4:01:33
260 * Fri, 17 Mar 89 4:01 GMT
261 * Mon Jan 16 16:12 PDT 1989
262 * Mon Jan 16 16:12 +0130 1989
263 * 6 May 1992 16:41-JST (Wednesday)
264 * 22-AUG-1993 10:59:12.82
265 * 22-AUG-1993 10:59pm
266 * 22-AUG-1993 12:59am
267 * 22-AUG-1993 12:59 PM
268 * Friday, August 04, 1995 3:54 PM
269 * 06/21/95 04:24:34 PM
270 * 20/06/95 21:07
271 * 95-06-08 19:32:48 EDT
272 *
273 * If the input string doesn't contain a description of the timezone,
274 * we consult the `default_to_gmt' to decide whether the string should
275 * be interpreted relative to the local time zone (PR_FALSE) or GMT (PR_TRUE).
276 * The correct value for this argument depends on what standard specified
277 * the time string which you are parsing.
278 */
279
280NSPR_API(PRStatus) PR_ParseTimeString (
281 const char *string,
282 PRBool default_to_gmt,
283 PRTime *result);
284
285/*
286 * FIXME: should we also have a formatting function, such as asctime, ctime,
287 * and strftime in standard C library? But this would involve
288 * internationalization issues. Might want to provide a US English version.
289 */
290
291/**********************************************************************/
292/*********************** OLD COMPATIBILITYFUNCTIONS *******************/
293/**********************************************************************/
294#ifndef NO_NSPR_10_SUPPORT
295
296/* Format a time value into a buffer. Same semantics as strftime() */
297NSPR_API(PRUint32) PR_FormatTime(char *buf, int buflen, const char *fmt,
298 const PRExplodedTime *tm);
299
300/* Format a time value into a buffer. Time is always in US English format, regardless
301 * of locale setting.
302 */
303NSPR_API(PRUint32)
304PR_FormatTimeUSEnglish( char* buf, PRUint32 bufSize,
305 const char* format, const PRExplodedTime* tm );
306
307#endif /* NO_NSPR_10_SUPPORT */
308
309PR_END_EXTERN_C
310
311#endif /* prtime_h___ */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette