VirtualBox

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

Last change on this file since 102178 was 102178, checked in by vboxsync, 11 months ago

libs/xpcom: Remove more unused code, bugref:10545

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.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#endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
59
60PR_BEGIN_EXTERN_C
61
62/**********************************************************************/
63/************************* TYPES AND CONSTANTS ************************/
64/**********************************************************************/
65
66#define PR_MSEC_PER_SEC 1000UL
67#define PR_USEC_PER_SEC 1000000UL
68#define PR_NSEC_PER_SEC 1000000000UL
69#define PR_USEC_PER_MSEC 1000UL
70#define PR_NSEC_PER_MSEC 1000000UL
71
72/*
73 * PRTime --
74 *
75 * NSPR represents basic time as 64-bit signed integers relative
76 * to midnight (00:00:00), January 1, 1970 Greenwich Mean Time (GMT).
77 * (GMT is also known as Coordinated Universal Time, UTC.)
78 * The units of time are in microseconds. Negative times are allowed
79 * to represent times prior to the January 1970 epoch. Such values are
80 * intended to be exported to other systems or converted to human
81 * readable form.
82 *
83 * Notes on porting: PRTime corresponds to time_t in ANSI C. NSPR 1.0
84 * simply uses PRInt64.
85 */
86
87typedef PRInt64 PRTime;
88
89/*
90 * Time zone and daylight saving time corrections applied to GMT to
91 * obtain the local time of some geographic location
92 */
93
94typedef struct PRTimeParameters {
95 PRInt32 tp_gmt_offset; /* the offset from GMT in seconds */
96 PRInt32 tp_dst_offset; /* contribution of DST in seconds */
97} PRTimeParameters;
98
99/*
100 * PRExplodedTime --
101 *
102 * Time broken down into human-readable components such as year, month,
103 * day, hour, minute, second, and microsecond. Time zone and daylight
104 * saving time corrections may be applied. If they are applied, the
105 * offsets from the GMT must be saved in the 'tm_params' field so that
106 * all the information is available to reconstruct GMT.
107 *
108 * Notes on porting: PRExplodedTime corrresponds to struct tm in
109 * ANSI C, with the following differences:
110 * - an additional field tm_usec;
111 * - replacing tm_isdst by tm_params;
112 * - the month field is spelled tm_month, not tm_mon;
113 * - we use absolute year, AD, not the year since 1900.
114 * The corresponding type in NSPR 1.0 is called PRTime. Below is
115 * a table of date/time type correspondence in the three APIs:
116 * API time since epoch time in components
117 * ANSI C time_t struct tm
118 * NSPR 1.0 PRInt64 PRTime
119 * NSPR 2.0 PRTime PRExplodedTime
120 */
121
122typedef struct PRExplodedTime {
123 PRInt32 tm_usec; /* microseconds past tm_sec (0-99999) */
124 PRInt32 tm_sec; /* seconds past tm_min (0-61, accomodating
125 up to two leap seconds) */
126 PRInt32 tm_min; /* minutes past tm_hour (0-59) */
127 PRInt32 tm_hour; /* hours past tm_day (0-23) */
128 PRInt32 tm_mday; /* days past tm_mon (1-31, note that it
129 starts from 1) */
130 PRInt32 tm_month; /* months past tm_year (0-11, Jan = 0) */
131 PRInt16 tm_year; /* absolute year, AD (note that we do not
132 count from 1900) */
133
134 PRInt8 tm_wday; /* calculated day of the week
135 (0-6, Sun = 0) */
136 PRInt16 tm_yday; /* calculated day of the year
137 (0-365, Jan 1 = 0) */
138
139 PRTimeParameters tm_params; /* time parameters used by conversion */
140} PRExplodedTime;
141
142/*
143 * PRTimeParamFn --
144 *
145 * A function of PRTimeParamFn type returns the time zone and
146 * daylight saving time corrections for some geographic location,
147 * given the current time in GMT. The input argument gmt should
148 * point to a PRExplodedTime that is in GMT, i.e., whose
149 * tm_params contains all 0's.
150 *
151 * For any time zone other than GMT, the computation is intended to
152 * consist of two steps:
153 * - Figure out the time zone correction, tp_gmt_offset. This number
154 * usually depends on the geographic location only. But it may
155 * also depend on the current time. For example, all of China
156 * is one time zone right now. But this situation may change
157 * in the future.
158 * - Figure out the daylight saving time correction, tp_dst_offset.
159 * This number depends on both the geographic location and the
160 * current time. Most of the DST rules are expressed in local
161 * current time. If so, one should apply the time zone correction
162 * to GMT before applying the DST rules.
163 */
164
165typedef PRTimeParameters (PR_CALLBACK *PRTimeParamFn)(const PRExplodedTime *gmt);
166
167/**********************************************************************/
168/****************************** FUNCTIONS *****************************/
169/**********************************************************************/
170
171/*
172 * The PR_Now routine returns the current time relative to the
173 * epoch, midnight, January 1, 1970 UTC. The units of the returned
174 * value are microseconds since the epoch.
175 *
176 * The values returned are not guaranteed to advance in a linear fashion
177 * due to the application of time correction protocols which synchronize
178 * computer clocks to some external time source. Consequently it should
179 * not be depended on for interval timing.
180 *
181 * The implementation is machine dependent.
182 * Cf. time_t time(time_t *tp) in ANSI C.
183 */
184#if defined(HAVE_WATCOM_BUG_2)
185PRTime __pascal __export __loadds
186#else
187NSPR_API(PRTime)
188#endif
189PR_Now(void);
190
191/*
192 * Expand time binding it to time parameters provided by PRTimeParamFn.
193 * The calculation is envisoned to proceed in the following steps:
194 * - From given PRTime, calculate PRExplodedTime in GMT
195 * - Apply the given PRTimeParamFn to the GMT that we just calculated
196 * to obtain PRTimeParameters.
197 * - Add the PRTimeParameters offsets to GMT to get the local time
198 * as PRExplodedTime.
199 */
200
201NSPR_API(void) PR_ExplodeTime(
202 PRTime usecs, PRTimeParamFn params, PRExplodedTime *exploded);
203
204/* Reverse operation of PR_ExplodeTime */
205#if defined(HAVE_WATCOM_BUG_2)
206PRTime __pascal __export __loadds
207#else
208NSPR_API(PRTime)
209#endif
210PR_ImplodeTime(const PRExplodedTime *exploded);
211
212/*
213 * Adjust exploded time to normalize field overflows after manipulation.
214 * Note that the following fields of PRExplodedTime should not be
215 * manipulated:
216 * - tm_month and tm_year: because the number of days in a month and
217 * number of days in a year are not constant, it is ambiguous to
218 * manipulate the month and year fields, although one may be tempted
219 * to. For example, what does "a month from January 31st" mean?
220 * - tm_wday and tm_yday: these fields are calculated by NSPR. Users
221 * should treat them as "read-only".
222 */
223
224NSPR_API(void) PR_NormalizeTime(
225 PRExplodedTime *exploded, PRTimeParamFn params);
226
227PR_END_EXTERN_C
228
229#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