nsprpub/pr/tests/formattm.c

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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

mercurial