diff options
author | hobbs <hobbs> | 2002-04-22 22:41:46 (GMT) |
---|---|---|
committer | hobbs <hobbs> | 2002-04-22 22:41:46 (GMT) |
commit | ae8818e783ef033c3aace0b9b7cb1cc4c8b68ae0 (patch) | |
tree | 614cb4f6866af5c95c83ff5e0cbe7da3c544659e | |
parent | f53cd80c45d6ec6c944e55a1fc5f2702cfcf94be (diff) | |
download | tcl-ae8818e783ef033c3aace0b9b7cb1cc4c8b68ae0.zip tcl-ae8818e783ef033c3aace0b9b7cb1cc4c8b68ae0.tar.gz tcl-ae8818e783ef033c3aace0b9b7cb1cc4c8b68ae0.tar.bz2 |
* doc/clock.n:
* compat/strftime.c (_fmt): change strftime to correctly handle
localized %c, %x and %X on Windows. Added some notes about how
the other values could be further localized.
-rw-r--r-- | compat/strftime.c | 63 | ||||
-rw-r--r-- | doc/clock.n | 19 |
2 files changed, 69 insertions, 13 deletions
diff --git a/compat/strftime.c b/compat/strftime.c index a2199a5..52a7fa1 100644 --- a/compat/strftime.c +++ b/compat/strftime.c @@ -8,7 +8,7 @@ * source. See the copyright notice below for details on redistribution * restrictions. The "license.terms" file does not apply to this file. * - * RCS: @(#) $Id: strftime.c,v 1.8 2001/11/23 01:26:30 das Exp $ + * RCS: @(#) $Id: strftime.c,v 1.9 2002/04/22 22:41:46 hobbs Exp $ */ /* @@ -45,7 +45,7 @@ */ #if defined(LIBC_SCCS) -static char *rcsid = "$Id: strftime.c,v 1.8 2001/11/23 01:26:30 das Exp $"; +static char *rcsid = "$Id: strftime.c,v 1.9 2002/04/22 22:41:46 hobbs Exp $"; #endif /* LIBC_SCCS */ #include <time.h> @@ -68,7 +68,13 @@ typedef struct { const char *t_fmt; const char *t_fmt_ampm; } _TimeLocale; - + +/* + * This is the C locale default. On Windows, if we wanted to make this + * localized, we would use GetLocaleInfo to get the correct values. + * It may be acceptable to do localization of month/day names, as the + * numerical values would be considered the locale-independent versions. + */ static const _TimeLocale _DefaultTimeLocale = { { @@ -144,6 +150,20 @@ _fmt(format, t) const char *format; const struct tm *t; { +#ifdef WIN32 +#define BUF_SIZ 256 + TCHAR buf[BUF_SIZ]; + SYSTEMTIME syst = { + t->tm_year + 1900, + t->tm_mon + 1, + t->tm_wday, + t->tm_mday, + t->tm_hour, + t->tm_min, + t->tm_sec, + 0, + }; +#endif for (; *format; ++format) { if (*format == '%') { ++format; @@ -188,10 +208,6 @@ _fmt(format, t) 2, '0')) return(0); continue; - case 'c': - if (!_fmt(_CurrentTimeLocale->d_t_fmt, t)) - return(0); - continue; case 'D': if (!_fmt("%m/%d/%y", t)) return(0); @@ -307,6 +323,38 @@ _fmt(format, t) if (!_conv(t->tm_wday, 1, '0')) return(0); continue; +#ifdef WIN32 + /* + * To properly handle the localized time routines on Windows, + * we must make use of the special localized calls. + */ + case 'c': + if (!GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, + &syst, NULL, buf, BUF_SIZ) || !_add(buf) + || !_add(" ")) { + return(0); + } + /* + * %c is created with LONGDATE + " " + TIME on Windows, + * so continue to %X case here. + */ + case 'X': + if (!GetTimeFormat(LOCALE_USER_DEFAULT, 0, + &syst, NULL, buf, BUF_SIZ) || !_add(buf)) { + return(0); + } + continue; + case 'x': + if (!GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, + &syst, NULL, buf, BUF_SIZ) || !_add(buf)) { + return(0); + } + continue; +#else + case 'c': + if (!_fmt(_CurrentTimeLocale->d_t_fmt, t)) + return(0); + continue; case 'x': if (!_fmt(_CurrentTimeLocale->d_fmt, t)) return(0); @@ -315,6 +363,7 @@ _fmt(format, t) if (!_fmt(_CurrentTimeLocale->t_fmt, t)) return(0); continue; +#endif case 'y': if (!_conv((t->tm_year + TM_YEAR_BASE) % 100, 2, '0')) diff --git a/doc/clock.n b/doc/clock.n index bcf1bdf..e609e3c 100644 --- a/doc/clock.n +++ b/doc/clock.n @@ -2,6 +2,7 @@ '\" Copyright (c) 1992-1995 Karl Lehenbauer and Mark Diekhans. '\" Copyright (c) 1995-1997 Sun Microsystems, Inc. '\" Copyright (c) 1998-1999 Scriptics Corporation +'\" Copyright (c) 2002 ActiveState Corporation '\" '\" This documentation is derived from the time and date facilities of '\" TclX, by Mark Diekhans and Karl Lehenbauer. @@ -9,10 +10,10 @@ '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: clock.n,v 1.10 2001/02/18 19:05:24 kennykb Exp $ +'\" RCS: @(#) $Id: clock.n,v 1.11 2002/04/22 22:41:46 hobbs Exp $ '\" .so man.macros -.TH clock n 8.3 Tcl "Tcl Built-In Commands" +.TH clock n 8.4 Tcl "Tcl Built-In Commands" .BS '\" Note: do not modify the .SH NAME line immediately below! .SH NAME @@ -63,7 +64,9 @@ Full month name. .VS 8.4 .IP \fB%c\fR Locale specific date and time. The format for date and time -in the default "C" locale is "%a %b %d %H:%M:%S %Y". +in the default "C" locale on Unix/Mac is "%a %b %d %H:%M:%S %Y". +On Windows, this value is the locale specific long date and time, as +specified in the Regional Options control panel settings. .IP \fB%C\fR First two digits of the four-digit year (19 or 20). .VE 8.4 @@ -136,10 +139,14 @@ Week of year (00 - 52), Monday is the first day of the week. .VS 8.4 .IP \fB%x\fR Locale specific date format. The format for a date in the default "C" -locale is "%m/%d/%y". +locale for Unix/Mac is "%m/%d/%y". +On Windows, this value is the locale specific short date format, as +specified in the Regional Options control panel settings. .IP \fB%X\fR Locale specific 24-hour time format. The format for a -24-hour time in the default "C" locale is "%H:%M:%S". +24-hour time in the default "C" locale for Unix/Mac is "%H:%M:%S". +On Windows, this value is the locale specific time format, as +specified in the Regional Options control panel settings. .VE 8.4 .IP \fB%y\fR Year without century (00 - 99). @@ -177,7 +184,7 @@ Time zone name. .VE 8.4 .RS If the \fB\-format\fR argument is not specified, the format string -"\fB%a %b %d %H:%M:%S %Z %Y\fR" is used. If the \fB\-gmt\fR argument +\fB"%a %b %d %H:%M:%S %Z %Y"\fR is used. If the \fB\-gmt\fR argument is present the next argument must be a boolean which if true specifies that the time will be formatted as Greenwich Mean Time. If false then the local timezone will be used as defined by the operating |