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
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/
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
15 * The Original Code is the Netscape Portable Runtime (NSPR).
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.
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.
36 * ***** END LICENSE BLOCK ***** */
40 * description: test time and date routines on the Mac
48 #define printf PR_LogPrint
49 extern void SetupMacPrintfLog(char *logFile
);
53 static char *dayOfWeek
[] =
54 { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???" };
55 static char *month
[] =
56 { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
57 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???" };
59 static void printExplodedTime(const PRExplodedTime
*et
) {
61 PRInt32 hourOffset
, minOffset
;
64 /* Print day of the week, month, day, hour, minute, and second */
65 printf( "%s %s %ld %02ld:%02ld:%02ld ",
66 dayOfWeek
[et
->tm_wday
], month
[et
->tm_month
], et
->tm_mday
,
67 et
->tm_hour
, et
->tm_min
, et
->tm_sec
);
70 totalOffset
= et
->tm_params
.tp_gmt_offset
+ et
->tm_params
.tp_dst_offset
;
71 if (totalOffset
== 0) {
75 if (totalOffset
< 0) {
76 totalOffset
= -totalOffset
;
79 hourOffset
= totalOffset
/ 3600;
80 minOffset
= (totalOffset
% 3600) / 60;
81 printf("%s%02ld%02ld ", sign
, hourOffset
, minOffset
);
85 printf("%d", et
->tm_year
);
88 int main(int argc
, char** argv
)
91 PR_Init(PR_USER_THREAD
, PR_PRIORITY_NORMAL
, 0);
95 SetupMacPrintfLog("timemac.log");
99 *************************************************************
101 ** Testing PR_Now(), PR_ExplodeTime, and PR_ImplodeTime
102 ** on the current time
104 *************************************************************
111 printf("*********************************************\n");
113 printf("** Testing PR_Now(), PR_ExplodeTime, and **\n");
114 printf("** PR_ImplodeTime on the current time **\n");
116 printf("*********************************************\n\n");
119 /* First try converting to UTC */
121 PR_ExplodeTime(t1
, PR_GMTParameters
, &et
);
122 if (et
.tm_params
.tp_gmt_offset
|| et
.tm_params
.tp_dst_offset
) {
123 printf("ERROR: UTC has nonzero gmt or dst offset.\n");
126 printf("Current UTC is ");
127 printExplodedTime(&et
);
130 t2
= PR_ImplodeTime(&et
);
132 printf("ERROR: Explode and implode are NOT inverse.\n");
136 /* Next, try converting to local (US Pacific) time */
138 PR_ExplodeTime(t1
, PR_LocalTimeParameters
, &et
);
139 printf("Current local time is ");
140 printExplodedTime(&et
);
142 printf("GMT offset is %ld, DST offset is %ld\n",
143 et
.tm_params
.tp_gmt_offset
, et
.tm_params
.tp_dst_offset
);
144 t2
= PR_ImplodeTime(&et
);
146 printf("ERROR: Explode and implode are NOT inverse.\n");
151 printf("Please examine the results\n");