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 including weekday. Used for $D in prompt and %DATE% */ 57 LPTSTR 58 GetDateString(VOID) 59 { 60 static TCHAR szDate[32]; 61 SYSTEMTIME t; 62 INT len; 63 GetLocalTime(&t); 64 65 len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &t, _T("ddd"), szDate, ARRAYSIZE(szDate)); 66 szDate[len - 1] = _T(' '); 67 FormatDate(&szDate[len], &t, TRUE); 68 return szDate; 69 } 70 71 /* Return time in hh:mm:ss.xx format. Used for $T in prompt and %TIME% */ 72 LPTSTR 73 GetTimeString(VOID) 74 { 75 static TCHAR szTime[12]; 76 SYSTEMTIME t; 77 GetLocalTime(&t); 78 _stprintf(szTime, _T("%2d%c%02d%c%02d%c%02d"), 79 t.wHour, cTimeSeparator, t.wMinute, cTimeSeparator, 80 t.wSecond, cDecimalSeparator, t.wMilliseconds / 10); 81 return szTime; 82 } 83