Source code of Windows XP (NT5)
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.

138 lines
3.7 KiB

  1. /* Time and date stuff */
  2. /* NOTE: Date & time input routines work only if SS == DS */
  3. #include "windows.h"
  4. #include <port1632.h>
  5. #include "date.h"
  6. CHAR chSepDate = '/'; /* Separator character for date string */
  7. CHAR chSepTime = ':'; /* Separator character for time string */
  8. CHAR sz1159[9] = "AM"; /* Time string suffix for morning hours */
  9. CHAR sz2359[9] = "PM"; /* Time string suffix for afternoon */
  10. INT iYearOffset = 0; /* Japanese year offset */
  11. INT iDate = 0; /* short date format code */
  12. BOOL f24Time = FALSE; /* True if military time, else False */
  13. BOOL fLZero = FALSE; /* True iff date values get leading zeros */
  14. HANDLE hinstTimeDate;
  15. INT cchTimeMax; /* Size of time string */
  16. INT cchLongDateMax;
  17. CHAR * FAR APIENTRY Int2Ascii();
  18. CHAR * APIENTRY Ascii2Int();
  19. CHAR * APIENTRY SkipSep();
  20. INT FAR APIENTRY GetTimeString(PDOSTIME pdt, CHAR *pch, WORD format)
  21. {
  22. CHAR *pchSave = pch;
  23. CHAR *szAMPM;
  24. INT h;
  25. szAMPM = NULL;
  26. h = pdt->hour;
  27. if (!f24Time) { /* want 12 hour clock */
  28. if (h >= 12) { /* PM */
  29. h -= 12;
  30. szAMPM = sz2359;
  31. } else {
  32. szAMPM = sz1159;
  33. }
  34. if (h == 0)
  35. h = 12;
  36. }
  37. pch = Int2Ascii(h, pch, fLZero || (format & GTS_LEADINGZEROS));
  38. *pch++ = chSepTime;
  39. pch = Int2Ascii(pdt->minutes, pch, TRUE);
  40. #ifdef DISABLE
  41. if (format & (GTS_SECONDS | GTS_HUNDREDTHS)) {
  42. *pch++ = chSepTime;
  43. pch = Int2Ascii(pdt->seconds, pch, TRUE);
  44. }
  45. if (format & GTS_HUNDREDTHS) {
  46. *pch++ = chSepTime;
  47. pch = Int2Ascii(pdt->hundredths, pch, TRUE);
  48. }
  49. #endif
  50. if (szAMPM) {
  51. *pch++ = ' ';
  52. while (*szAMPM != 0)
  53. *pch++ = *szAMPM++;
  54. }
  55. if ((format & GTS_LEADINGSPACE) && *pchSave == '0')
  56. *pchSave = ' ';
  57. *pch = 0;
  58. return(int)(pch - pchSave);
  59. }
  60. INT FAR APIENTRY GetDateString(PDOSDATE pdd, CHAR *pch, WORD format)
  61. {
  62. CHAR *pchSave = pch;
  63. CHAR *szMonth;
  64. INT i1, i2, i3;
  65. BOOL fLZeroSave;
  66. LANGID PrimaryLangID = PRIMARYLANGID(GetSystemDefaultLangID());
  67. if ((PrimaryLangID == LANG_JAPANESE) || (PrimaryLangID == LANG_KOREAN))
  68. {
  69. pdd->year = pdd->year - iYearOffset;
  70. if (format != GDS_LONG)
  71. pdd->year %= 100;
  72. }
  73. else
  74. {
  75. pdd->year = (pdd->year - iYearOffset) % 100;
  76. }
  77. i1 = pdd->month; /* assume mdy */
  78. i2 = pdd->day;
  79. i3 = pdd->year;
  80. if (iDate != 0) {
  81. i1 = pdd->day; /* dmy or ymd */
  82. i2 = pdd->month;
  83. if (iDate == 2) { /* ymd */
  84. i1 = pdd->year;
  85. i3 = pdd->day;
  86. }
  87. }
  88. if ((iDate == 2) && (format == GDS_LONG) &&
  89. ((PrimaryLangID == LANG_JAPANESE) || (PrimaryLangID == LANG_KOREAN)))
  90. {
  91. pch = Int2Ascii(i1/100, pch, fLZero);
  92. pch = Int2Ascii(i1%100, pch, TRUE);
  93. }
  94. else
  95. {
  96. pch = Int2Ascii(i1, pch, fLZero);
  97. }
  98. *pch++ = chSepDate;
  99. pch = Int2Ascii(i2, pch, fLZero);
  100. *pch++ = chSepDate;
  101. if ((iDate != 2) && (format == GDS_LONG) &&
  102. ((PrimaryLangID == LANG_JAPANESE) || (PrimaryLangID == LANG_KOREAN)))
  103. {
  104. pch = Int2Ascii(i3/100, pch, fLZero);
  105. pch = Int2Ascii(i3%100, pch, TRUE);
  106. }
  107. else
  108. {
  109. pch = Int2Ascii(i3, pch, fLZero);
  110. }
  111. *pch = 0;
  112. return(int)(pch - pchSave);
  113. }
  114. CHAR * FAR APIENTRY Int2Ascii(val, pch, fLeadingZeros)
  115. register INT val;
  116. register CHAR *pch;
  117. BOOL fLeadingZeros;
  118. {
  119. INT tens;
  120. if ((tens = val / 10) != 0 || fLeadingZeros) {
  121. *pch++ = tens + '0';
  122. }
  123. *pch++ = (val % 10) + '0';
  124. return(pch);
  125. }