You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

186 lines
6.1 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: examples/c/util/example.c.util.getcurrenttime/example.c.util.getcurrenttime.c
  3. *
  4. * Purpose: Implementation file for the example.c.util.getcurrenttime project.
  5. *
  6. * Created: 30th August 2008
  7. * Updated: 27th December 2010
  8. *
  9. * Status: Wizard-generated
  10. *
  11. * License: (Licensed under the Synesis Software Open License)
  12. *
  13. * Copyright (c) 2008-2010, Synesis Software Pty Ltd.
  14. * All rights reserved.
  15. *
  16. * www: http://www.synesis.com.au/software
  17. *
  18. * ////////////////////////////////////////////////////////////////////// */
  19. /* Pantheios Header Files */
  20. #include <pantheios/pantheios.h>
  21. #include <pantheios/util/time/currenttime.h>
  22. /* STLSoft Header Files */
  23. #include <stlsoft/stlsoft.h>
  24. #include <platformstl/platformstl.h>
  25. #if defined(PLATFORMSTL_OS_IS_WINDOWS)
  26. # include <winstl/error/error_functions.h>
  27. #endif /* OS */
  28. /* Standard C Header Files */
  29. #include <errno.h>
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #if defined(_MSC_VER) && \
  34. defined(_DEBUG)
  35. # include <crtdbg.h>
  36. #endif /* _MSC_VER) && _DEBUG */
  37. /* ////////////////////////////////////////////////////////////////////// */
  38. int main(int argc, char** argv)
  39. {
  40. STLSOFT_SUPPRESS_UNUSED(argc);
  41. STLSOFT_SUPPRESS_UNUSED(argv);
  42. /* Using local time with the default representation for the platform */
  43. {
  44. PAN_CHAR_T buff[101];
  45. pan_beutil_time_t tm;
  46. size_t n;
  47. tm.capacity = STLSOFT_NUM_ELEMENTS(buff);
  48. tm.len = 0;
  49. tm.str = &buff[0];
  50. tm.strftimeFmt = NULL;
  51. n = pantheios_util_getCurrentTime(&tm, 0);
  52. printf("time with 0 flags: %.*s\n", (int)n, buff);
  53. }
  54. /* Using the current user time, with UNIX format */
  55. {
  56. PAN_CHAR_T buff[101];
  57. pan_beutil_time_t tm;
  58. int flags = 0
  59. | PANTHEIOS_GETCURRENTTIME_F_USE_UNIX_FORMAT
  60. ;
  61. size_t n;
  62. tm.capacity = STLSOFT_NUM_ELEMENTS(buff);
  63. tm.len = 0;
  64. tm.str = &buff[0];
  65. tm.strftimeFmt = NULL;
  66. n = pantheios_util_getCurrentTime(&tm, flags);
  67. printf("time, with UNIX format: %.*s\n", (int)n, buff);
  68. }
  69. /* Using system time with the default representation for the platform */
  70. {
  71. PAN_CHAR_T buff[101];
  72. pan_beutil_time_t tm;
  73. int flags = 0
  74. | PANTHEIOS_GETCURRENTTIME_F_USE_SYSTEM_TIME
  75. ;
  76. size_t n;
  77. tm.capacity = STLSOFT_NUM_ELEMENTS(buff);
  78. tm.len = 0;
  79. tm.str = &buff[0];
  80. tm.strftimeFmt = NULL;
  81. n = pantheios_util_getCurrentTime(&tm, flags);
  82. printf("time, using system time: %.*s\n", (int)n, buff);
  83. }
  84. /* Using local time with the default representation for the platform, favouring speed */
  85. {
  86. PAN_CHAR_T buff[101];
  87. pan_beutil_time_t tm;
  88. int flags = 0
  89. | PANTHEIOS_GETCURRENTTIME_F_USE_SYSTEM_TIME
  90. | PANTHEIOS_GETCURRENTTIME_F_FAVOUR_SPEED
  91. ;
  92. size_t n;
  93. tm.capacity = STLSOFT_NUM_ELEMENTS(buff);
  94. tm.len = 0;
  95. tm.str = &buff[0];
  96. tm.strftimeFmt = NULL;
  97. n = pantheios_util_getCurrentTime(&tm, flags);
  98. printf("time, using system time, favouring speed: %.*s\n", (int)n, buff);
  99. }
  100. /* Using local time with the default representation for the platform, favouring accuracy */
  101. {
  102. PAN_CHAR_T buff[101];
  103. pan_beutil_time_t tm;
  104. int flags = 0
  105. | PANTHEIOS_GETCURRENTTIME_F_USE_SYSTEM_TIME
  106. | PANTHEIOS_GETCURRENTTIME_F_FAVOUR_ACCURACY
  107. ;
  108. size_t n;
  109. tm.capacity = STLSOFT_NUM_ELEMENTS(buff);
  110. tm.len = 0;
  111. tm.str = &buff[0];
  112. tm.strftimeFmt = NULL;
  113. n = pantheios_util_getCurrentTime(&tm, flags);
  114. printf("time, using system time, favouring accuracy: %.*s\n", (int)n, buff);
  115. }
  116. /* Using local time with the default representation for the platform, microsecond resolution, favouring speed */
  117. {
  118. PAN_CHAR_T buff[101];
  119. pan_beutil_time_t tm;
  120. int flags = 0
  121. | PANTHEIOS_GETCURRENTTIME_F_TIME_RES_MICROSECS
  122. | PANTHEIOS_GETCURRENTTIME_F_FAVOUR_SPEED
  123. ;
  124. size_t n;
  125. tm.capacity = STLSOFT_NUM_ELEMENTS(buff);
  126. tm.len = 0;
  127. tm.str = &buff[0];
  128. tm.strftimeFmt = NULL;
  129. n = pantheios_util_getCurrentTime(&tm, flags);
  130. printf("time, showing microseconds, favouring speed: %.*s\n", (int)n, buff);
  131. }
  132. /* Using local time with the default representation for the platform, microsecond resolution, favouring accuracy */
  133. {
  134. PAN_CHAR_T buff[101];
  135. pan_beutil_time_t tm;
  136. int flags = 0
  137. | PANTHEIOS_GETCURRENTTIME_F_TIME_RES_MICROSECS
  138. | PANTHEIOS_GETCURRENTTIME_F_FAVOUR_ACCURACY
  139. ;
  140. size_t n;
  141. tm.capacity = STLSOFT_NUM_ELEMENTS(buff);
  142. tm.len = 0;
  143. tm.str = &buff[0];
  144. tm.strftimeFmt = NULL;
  145. n = pantheios_util_getCurrentTime(&tm, flags);
  146. printf("time, showing microseconds, favouring accuracy: %.*s\n", (int)n, buff);
  147. }
  148. return EXIT_SUCCESS;
  149. }
  150. /* ///////////////////////////// end of file //////////////////////////// */