nsprpub/pr/tests/formattm.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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)
    13 {
    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;
    28     }
    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;
    37         }
    38         printf("%s\n", small_buffer);
    39     } else {
    40         fprintf(stderr, "PR_FormatTime(small_buffer) succeeded "
    41                         "unexpectedly\n");
    42         return 1;
    43     }
    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;
    50 }

mercurial