]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/date.cpp
wxDataObejct and related changes (won't compile right now)
[wxWidgets.git] / src / common / date.cpp
index e3e808ee5c7733fbf861dbae5ead813e76b315bc..5d89d60e25096bf96f8514387faf1a265a6c739f 100644 (file)
 #include "wx/wxprec.h"
 
 #ifdef __BORLANDC__
-#pragma hdrstop
+  #pragma hdrstop
 #endif
 
-#include "wx/setup.h"
-
 #if wxUSE_TIMEDATE
 
 #include "wx/date.h"
-#include <wx/intl.h>
+#include "wx/intl.h"
 
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 
-#if wxUSE_IOSTREAMH
-#include <iostream.h>
-#else
-#include <iostream>
-#endif
+#include "wx/ioswrap.h"
 
 #include <time.h>
 #include <string.h>
 
 #define ABBR_LENGTH 3
 
-static const char *dayname[] = {
-    "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
+static const wxChar *dayname[] = {
+    wxT("Sunday"), wxT("Monday"), wxT("Tuesday"), wxT("Wednesday"),
+    wxT("Thursday"), wxT("Friday"), wxT("Saturday")
 };
 
-static const char *mname[] = {
-    "January", "February", "March", "April", "May", "June", "July", "August",
-    "September", "October", "November", "December"
+static const wxChar *mname[] = {
+    wxT("January"), wxT("February"), wxT("March"), wxT("April"), wxT("May"), wxT("June"),
+    wxT("July"), wxT("August"), wxT("September"), wxT("October"), wxT("November"), wxT("December")
 };
 
 static int GauDays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
@@ -93,20 +88,20 @@ wxDate::wxDate (const wxString& dat)
 {
     DisplayFormat=wxMDY;
     DisplayOptions='\0';
-    if (strcmp(dat, "TODAY") == 0 || strcmp(dat, "today") == 0)
+    if (wxStrcmp(dat, wxT("TODAY")) == 0 || wxStrcmp(dat, wxT("today")) == 0)
     {
         // Sets the current date
         Set();
     }
     else
     {
-        char buf[100];
-        strcpy(buf, (char *) (const char *)dat);
+        wxChar buf[100];
+        wxStrcpy(buf, dat);
 
-        char *token = strtok(buf,"/-");
-        month = atoi(token);
-        day   = atoi(strtok((char *) NULL,"/-"));
-        year  = atoi(strtok((char *) NULL," "));
+        wxChar *save_ptr, *token = wxStrtok(buf,wxT("/-"),&save_ptr);
+        month = wxAtoi(token);
+        day   = wxAtoi(wxStrtok((wxChar *) NULL,wxT("/-"),&save_ptr));
+        year  = wxAtoi(wxStrtok((wxChar *) NULL,wxT(" "),&save_ptr));
     }
 
     mdy_to_julian ();
@@ -136,20 +131,20 @@ void wxDate::operator = (const wxString& dat)
 {
     DisplayFormat=wxMDY;
     DisplayOptions='\0';
-    if (strcmp(dat, "TODAY") == 0 || strcmp(dat, "today") == 0)
+    if (wxStrcmp(dat, wxT("TODAY")) == 0 || wxStrcmp(dat, wxT("today")) == 0)
     {
         // Sets the current date
         Set();
     }
     else
     {
-        char buf[100];
-        strcpy(buf, (char *)(const char *)dat);
+        wxChar buf[100];
+        wxStrcpy(buf, dat);
 
-        char *token = strtok(buf,"/-");
-        month = atoi(token);
-        day   = atoi(strtok((char *) NULL,"/-"));
-        year  = atoi(strtok((char *) NULL," "));
+        wxChar *save_ptr, *token = wxStrtok(buf,wxT("/-"),&save_ptr);
+        month = wxAtoi(token);
+        day   = wxAtoi(wxStrtok((wxChar *) NULL,wxT("/-"),&save_ptr));
+        year  = wxAtoi(wxStrtok((wxChar *) NULL,wxT(" "),&save_ptr));
     }
 
     mdy_to_julian ();
@@ -275,22 +270,31 @@ bool WXDLLEXPORT operator != (const wxDate &dt1, const wxDate &dt2)
     return ( dt1.julian != dt2.julian );
 }
 
+
+#if wxUSE_STD_IOSTREAM
+
 ////////////////////////////////////////////////////////////////
 // Ostream operations
 ////////////////////////////////////////////////////////////////
 
 ostream WXDLLEXPORT & operator << (ostream &os, const wxDate &dt)
 {
-    return os << (const char *) dt.FormatDate();
+    return os << dt.FormatDate().mb_str();
 }
 
+#endif
+
 //////////////////////////////////////////////////////////////
 // Conversion routines
 //////////////////////////////////////////////////////////////
 
 void wxDate::julian_to_wday (void)
 {
+    // Correction by Peter Stadel <peters@jetcity.com>
+    day_of_week = (int)((julian - 2) % 7L);
+/*
     day_of_week = (int) ((julian + 2) % 7 + 1);
+*/
 }
 
 void wxDate::julian_to_mdy ()
@@ -345,72 +349,72 @@ wxString wxDate::FormatDate (int type) const
     if (actualType == -1)
         actualType = DisplayFormat;
 
-    char buf[40];
+    wxChar buf[40];
 
     memset( buf, '\0', sizeof(buf) );
     switch ( actualType )
     {
         case wxDAY:
             if ( (day_of_week < 1) || (day_of_week > 7) )
-                strcpy(buf, _("invalid day"));
+                wxStrcpy(buf, _("invalid day"));
             else
-                strncpy( buf, _(dayname[day_of_week-1]),
-                        (DisplayOptions & wxDATE_ABBR) ? ABBR_LENGTH : 9);
+                wxStrncpy( buf, wxGetTranslation(dayname[day_of_week-1]),
+               (DisplayOptions & wxDATE_ABBR) ? ABBR_LENGTH : 9);
             return wxString(buf);
 
         case wxMONTH:
             if ( (month < 1) || (month > 12) )
-                strcpy(buf, _("invalid month"));
+                wxStrcpy(buf, _("invalid month"));
             else
-                strncpy( buf, _(mname[month-1]),
-                        (DisplayOptions & wxDATE_ABBR) ? ABBR_LENGTH : 9);
+                wxStrncpy( buf, wxGetTranslation(mname[month-1]),
+               (DisplayOptions & wxDATE_ABBR) ? ABBR_LENGTH : 9);
             return wxString(buf);
 
         case wxFULL:
             if ( (month < 1) || (month > 12) || (day_of_week < 0) ||
                     (day_of_week > 7) )
             {
-                strcpy(buf, _("invalid date"));
+                wxStrcpy(buf, _("invalid date"));
                 return wxString(buf);
             }
-            strncpy( buf, _(dayname[day_of_week-1]),
-                    (DisplayOptions & wxDATE_ABBR) ? ABBR_LENGTH : 9);
-            strcat( buf, ", ");
-            strncat( buf, _(mname[month-1]),
-                    (DisplayOptions & wxDATE_ABBR) ? ABBR_LENGTH : 9);
-            strcat( buf, " ");
-            sprintf( buf+strlen(buf), "%d, %d", day, abs(year) );
+            wxStrncpy( buf, wxGetTranslation(dayname[day_of_week-1]),
+               (DisplayOptions & wxDATE_ABBR) ? ABBR_LENGTH : 9);
+            wxStrcat( buf, wxT(", "));
+            wxStrncat( buf, wxGetTranslation(mname[month-1]),
+               (DisplayOptions & wxDATE_ABBR) ? ABBR_LENGTH : 9);
+            wxStrcat( buf, wxT(" "));
+            wxSprintf( buf+wxStrlen(buf), wxT("%d, %d"), day, abs(year) );
             if (year < 0)
-                strcat(buf,_(" B.C."));
+                wxStrcat(buf,_(" B.C."));
             return wxString(buf);
 
         case wxEUROPEAN:
             if ( (month < 1) || (month > 12) || (day_of_week < 0) ||
                     (day_of_week > 7) )
             {
-                strcpy(buf, _("invalid date"));
+                wxStrcpy(buf, _("invalid date"));
                 return wxString(buf);
             }
-            sprintf(buf,"%d ",  day);
-            strncat(buf, _(mname[month-1]),
+            wxSprintf(buf,wxT("%d "),  day);
+            wxStrncat(buf, wxGetTranslation(mname[month-1]),
                     (DisplayOptions & wxDATE_ABBR) ? ABBR_LENGTH : 9);
-            sprintf( buf+strlen(buf), " %d", abs(year) );
+            wxSprintf( buf+wxStrlen(buf), wxT(" %d"), abs(year) );
             if (year < 0)
-                strcat(buf, _(" B.C."));
+                wxStrcat(buf, _(" B.C."));
             return wxString(buf);
 
         case wxMDY:
         default:
             if (day==0 || month==0 || year==0)
-                strcpy(buf, _("invalid date"));
+                wxStrcpy(buf, _("invalid date"));
             else
-                sprintf( buf+strlen(buf), "%1d/%1d/%02d", month, day,
-                        (DisplayOptions & wxNO_CENTURY) && (abs(year) > 1899)
-                        ? (abs(year) - (abs(year) / 100 * 100))
-                        : (abs(year))  );
+                wxSprintf( buf+wxStrlen(buf), wxT("%1d/%1d/%02d"), month, day,
+               (DisplayOptions & wxNO_CENTURY) && (abs(year) > 1899)
+               ? (abs(year) - (abs(year) / 100 * 100))
+               : (abs(year))  );
             return wxString(buf);
     }
-    return wxString("");
+    return wxString(wxT(""));
 }
 
 void wxDate::SetFormat( int format )