formattm.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. /* A test program for PR_FormatTime and PR_FormatTimeUSEnglish */
  6. #include "prtime.h"
  7. #include <stdio.h>
  8. int main(int argc, char **argv)
  9. {
  10. char buffer[256];
  11. char small_buffer[8];
  12. PRTime now;
  13. PRExplodedTime tod;
  14. now = PR_Now();
  15. PR_ExplodeTime(now, PR_LocalTimeParameters, &tod);
  16. if (PR_FormatTime(buffer, sizeof(buffer),
  17. "%a %b %d %H:%M:%S %Z %Y", &tod) != 0) {
  18. printf("%s\n", buffer);
  19. } else {
  20. fprintf(stderr, "PR_FormatTime(buffer) failed\n");
  21. return 1;
  22. }
  23. small_buffer[0] = '?';
  24. if (PR_FormatTime(small_buffer, sizeof(small_buffer),
  25. "%a %b %d %H:%M:%S %Z %Y", &tod) == 0) {
  26. if (small_buffer[0] != '\0') {
  27. fprintf(stderr, "PR_FormatTime(small_buffer) did not output "
  28. "an empty string on failure\n");
  29. return 1;
  30. }
  31. printf("%s\n", small_buffer);
  32. } else {
  33. fprintf(stderr, "PR_FormatTime(small_buffer) succeeded "
  34. "unexpectedly\n");
  35. return 1;
  36. }
  37. (void)PR_FormatTimeUSEnglish(buffer, sizeof(buffer),
  38. "%a %b %d %H:%M:%S %Z %Y", &tod);
  39. printf("%s\n", buffer);
  40. return 0;
  41. }