backout 29799f914cab, Bug 917642 - [Helix] Please update the helix blobs
[gecko.git] / nsprpub / pr / tests / formattm.c
blob88b9fdf215fc3de9813537f5a79c6620ca8563ac
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/. */
6 /* A test program for PR_FormatTime and PR_FormatTimeUSEnglish */
8 #include "prtime.h"
10 #include <stdio.h>
12 int main(int argc, char **argv)
14 char buffer[256];
15 char small_buffer[8];
16 PRTime now;
17 PRExplodedTime tod;
19 now = PR_Now();
20 PR_ExplodeTime(now, PR_LocalTimeParameters, &tod);
22 if (PR_FormatTime(buffer, sizeof(buffer),
23 "%a %b %d %H:%M:%S %Z %Y", &tod) != 0) {
24 printf("%s\n", buffer);
25 } else {
26 fprintf(stderr, "PR_FormatTime(buffer) failed\n");
27 return 1;
30 small_buffer[0] = '?';
31 if (PR_FormatTime(small_buffer, sizeof(small_buffer),
32 "%a %b %d %H:%M:%S %Z %Y", &tod) == 0) {
33 if (small_buffer[0] != '\0') {
34 fprintf(stderr, "PR_FormatTime(small_buffer) did not output "
35 "an empty string on failure\n");
36 return 1;
38 printf("%s\n", small_buffer);
39 } else {
40 fprintf(stderr, "PR_FormatTime(small_buffer) succeeded "
41 "unexpectedly\n");
42 return 1;
45 (void)PR_FormatTimeUSEnglish(buffer, sizeof(buffer),
46 "%a %b %d %H:%M:%S %Z %Y", &tod);
47 printf("%s\n", buffer);
49 return 0;