Debian Codegraph @

nsprpub/pr/tests/formattm.c

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 /* A test program for PR_FormatTime and PR_FormatTimeUSEnglish */
7
8 #include "prtime.h"
9
10 #include <stdio.h>
11
12 int main(int argc, char** argv) {
13 char buffer[256];
14 char small_buffer[8];
15 PRTime now;
16 PRExplodedTime tod;
17
18 now = PR_Now();
19 PR_ExplodeTime(now, PR_LocalTimeParameters, &tod);
20
21 if (PR_FormatTime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Z %Y", &tod) !=
22 0) {
23 printf("%s\n", buffer);
24 } else {
25 fprintf(stderr, "PR_FormatTime(buffer) failed\n");
26 return 1;
27 }
28
29 small_buffer[0] = '?';
30 if (PR_FormatTime(small_buffer, sizeof(small_buffer),
31 "%a %b %d %H:%M:%S %Z %Y", &tod) == 0) {
32 if (small_buffer[0] != '\0') {
33 fprintf(stderr,
34 "PR_FormatTime(small_buffer) did not output "
35 "an empty string on failure\n");
36 return 1;
37 }
38 printf("%s\n", small_buffer);
39 } else {
40 fprintf(stderr,
41 "PR_FormatTime(small_buffer) succeeded "
42 "unexpectedly\n");
43 return 1;
44 }
45
46 (void)PR_FormatTimeUSEnglish(buffer, sizeof(buffer),
47 "%a %b %d %H:%M:%S %Z %Y", &tod);
48 printf("%s\n", buffer);
49
50 return 0;
51 }