1 /* 2 * LOCALE.C - locale handling. 3 * 4 * 5 * History: 6 * 7 * 09-Jan-1999 (Eric Kohl) 8 * Started. 9 * 10 * 20-Jan-1999 (Eric Kohl) 11 * Unicode safe! 12 */ 13 14 #include "precomp.h" 15 16 TCHAR cDateSeparator; 17 TCHAR cTimeSeparator; 18 TCHAR cThousandSeparator; 19 TCHAR cDecimalSeparator; 20 INT nDateFormat; 21 INT nTimeFormat; 22 INT nNumberGroups; 23 24 25 VOID InitLocale(VOID) 26 { 27 TCHAR szBuffer[256]; 28 29 /* date settings */ 30 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDATE, szBuffer, ARRAYSIZE(szBuffer)); 31 cDateSeparator = szBuffer[0]; 32 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IDATE | LOCALE_RETURN_NUMBER, (LPTSTR)&nDateFormat, sizeof(nDateFormat) / sizeof(TCHAR)); 33 34 /* time settings */ 35 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STIME, szBuffer, ARRAYSIZE(szBuffer)); 36 cTimeSeparator = szBuffer[0]; 37 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ITIME | LOCALE_RETURN_NUMBER, (LPTSTR)&nTimeFormat, sizeof(nTimeFormat) / sizeof(TCHAR)); 38 39 /* number settings */ 40 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, szBuffer, ARRAYSIZE(szBuffer)); 41 cThousandSeparator = szBuffer[0]; 42 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, szBuffer, ARRAYSIZE(szBuffer)); 43 cDecimalSeparator = szBuffer[0]; 44 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SGROUPING, szBuffer, ARRAYSIZE(szBuffer)); 45 nNumberGroups = _ttoi(szBuffer); 46 #if 0 47 /* days of week */ 48 for (i = 0; i < 7; i++) 49 { 50 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVDAYNAME1 + i, szBuffer, ARRAYSIZE(szBuffer)); 51 _tcscpy(aszDayNames[(i+1)%7], szBuffer); /* little hack */ 52 } 53 #endif 54 } 55 56 /* Return date string without weekday. Used for $D in prompt and %DATE% */ 57 LPTSTR 58 GetDateString(VOID) 59 { 60 static TCHAR szDate[32]; 61 SYSTEMTIME t; 62 63 GetLocalTime(&t); 64 GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &t, NULL, szDate, ARRAYSIZE(szDate)); 65 return szDate; 66 } 67 68 /* Return time in H:mm:ss.SS format. Used for $T in prompt and %TIME% */ 69 LPTSTR 70 GetTimeString(VOID) 71 { 72 static TCHAR szTime[12]; 73 SYSTEMTIME t; 74 GetLocalTime(&t); 75 _stprintf(szTime, _T("%2d%c%02d%c%02d%c%02d"), 76 t.wHour, cTimeSeparator, t.wMinute, cTimeSeparator, 77 t.wSecond, cDecimalSeparator, t.wMilliseconds / 10); 78 return szTime; 79 } 80