changeset 165:d03716228b7f

Use strftime to display time and date on Windows and unix.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 18 Nov 2002 15:24:01 +0000
parents d35771f70bdd
children fb2987817924
files gtk/dw.c win/dw.c
diffstat 2 files changed, 35 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/gtk/dw.c	Sun Nov 17 13:00:37 2002 +0000
+++ b/gtk/dw.c	Mon Nov 18 15:24:01 2002 +0000
@@ -29,8 +29,6 @@
 extern DWResources _resources;
 #endif
 
-char monthlist[][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
-                        "Sep", "Oct", "Nov", "Dec" };
 GdkColor _colors[] =
 {
 	{ 0, 0x0000, 0x0000, 0x0000 },	/* 0  black */
@@ -4119,23 +4117,28 @@
 	}
 	else if(flag & DW_CFA_DATE)
 	{
-		CDATE fdate = *((CDATE *)data);
-
-		if(/*fdate.month > -1 &&*/ fdate.month < 12 && fdate.day > 0 && fdate.year > 0)
-			sprintf(textbuffer, "%s %d, %d", monthlist[fdate.month], fdate.day, fdate.year);
-        else
-			strcpy(textbuffer, "");
+		struct tm curtm;
+		CDATE cdate = *((CDATE *)data);
+
+		curtm.tm_mday = cdate.day;
+		curtm.tm_mon = cdate.month - 1;
+		curtm.tm_year = cdate.year - 1900;
+
+		strftime(textbuffer, 100, "%x", &curtm);
 
 		gtk_clist_set_text(GTK_CLIST(clist), row, column, textbuffer);
 	}
 	else if(flag & DW_CFA_TIME)
 	{
-		CTIME ftime = *((CTIME *)data);
-
-		if(ftime.hours > 12)
-			sprintf(textbuffer, "%d:%s%dpm", ftime.hours - 12, (ftime.minutes < 10) ? "0" : "", ftime.minutes);
-		else
-			sprintf(textbuffer, "%d:%s%dam", ftime.hours ? ftime.hours : 12, (ftime.minutes < 10) ? "0" : "", ftime.minutes);
+		struct tm curtm;
+		CTIME ctime = *((CTIME *)data);
+
+		curtm.tm_hour = ctime.hours;
+		curtm.tm_min = ctime.minutes;
+		curtm.tm_sec = ctime.seconds;
+
+		strftime(textbuffer, 100, "%X", &curtm);
+
 		gtk_clist_set_text(GTK_CLIST(clist), row, column, textbuffer);
 	}
 	DW_MUTEX_UNLOCK;
--- a/win/dw.c	Sun Nov 17 13:00:37 2002 +0000
+++ b/win/dw.c	Mon Nov 18 15:24:01 2002 +0000
@@ -33,9 +33,6 @@
 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
 #endif
 
-char monthlist[][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
-                        "Sep", "Oct", "Nov", "Dec" };
-
 int main(int argc, char *argv[]);
 
 #define ICON_INDEX_LIMIT 200
@@ -5730,23 +5727,29 @@
 	}
 	else if(flags[column] & DW_CFA_DATE)
 	{
-		CDATE fdate = *((CDATE *)data);
-
-		if(fdate.month > -1 && fdate.month < 12 && fdate.day > 0 && fdate.year > 0)
-			sprintf(textbuffer, "%s %d, %d", monthlist[fdate.month], fdate.day, fdate.year);
-        else
-			strcpy(textbuffer, "");
+		struct tm curtm;
+		CDATE cdate = *((CDATE *)data);
+
+		curtm.tm_mday = cdate.day;
+		curtm.tm_mon = cdate.month - 1;
+		curtm.tm_year = cdate.year - 1900;
+
+		strftime(textbuffer, 100, "%x", &curtm);
+
 		lvi.pszText = textbuffer;
 		lvi.cchTextMax = strlen(textbuffer);
 	}
 	else if(flags[column] & DW_CFA_TIME)
 	{
-		CTIME ftime = *((CTIME *)data);
-
-		if(ftime.hours > 12)
-			sprintf(textbuffer, "%d:%s%dpm", ftime.hours - 12, (ftime.minutes < 10) ? "0" : "", ftime.minutes);
-		else
-			sprintf(textbuffer, "%d:%s%dam", ftime.hours ? ftime.hours : 12, (ftime.minutes < 10) ? "0" : "", ftime.minutes);
+		struct tm curtm;
+		CTIME ctime = *((CTIME *)data);
+
+		curtm.tm_hour = ctime.hours;
+		curtm.tm_min = ctime.minutes;
+		curtm.tm_sec = ctime.seconds;
+
+		strftime(textbuffer, 100, "%X", &curtm);
+
 		lvi.pszText = textbuffer;
 		lvi.cchTextMax = strlen(textbuffer);
 	}