timezone_tests.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * SpanDSP - a series of DSP components for telephony
  3. *
  4. * timezone_tests.c - Timezone handling for time interpretation
  5. *
  6. * Written by Steve Underwood <steveu@coppice.org>
  7. *
  8. * Copyright (C) 2010 Steve Underwood
  9. *
  10. * All rights reserved.
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU Lesser General Public License version 2.1,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. /*! \page timezone_tests_page Timezone handling tests
  26. \section timezone_tests_page_sec_1 What does it do?
  27. */
  28. #if defined(HAVE_CONFIG_H)
  29. #include "config.h"
  30. #endif
  31. #include <stdlib.h>
  32. #include <inttypes.h>
  33. #include <stdio.h>
  34. #include <string.h>
  35. #include <time.h>
  36. #include "spandsp.h"
  37. int main(int argc, char *argv[])
  38. {
  39. struct tm tms;
  40. struct tm *tmp = &tms;
  41. time_t ltime;
  42. tz_t *tz;
  43. /* Get the current time */
  44. ltime = time(NULL);
  45. /* Compute the local current time now for several localities, based on Posix tz strings */
  46. tz = tz_init(NULL, "GMT0GMT0,M10.5.0,M3.5.0");
  47. tz_localtime(tz, tmp, ltime);
  48. printf("Local time is %02d:%02d:%02d\n", tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  49. printf("Time zone is %s\n", tz_tzname(tz, tmp->tm_isdst));
  50. tz_init(tz, "CST-8CST-8,M10.5.0,M3.5.0");
  51. tz_localtime(tz, tmp, ltime);
  52. printf("Local time is %02d:%02d:%02d\n", tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  53. printf("Time zone is %s\n", tz_tzname(tz, tmp->tm_isdst));
  54. tz_init(tz, "AEST-10AEDT-11,M10.5.0,M3.5.0");
  55. tz_localtime(tz, tmp, ltime);
  56. printf("Local time is %02d:%02d:%02d\n", tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  57. printf("Time zone is %s\n", tz_tzname(tz, tmp->tm_isdst));
  58. tz_free(tz);
  59. return 0;
  60. }
  61. /*- End of function --------------------------------------------------------*/
  62. /*- End of file ------------------------------------------------------------*/