]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/date.cpp
1. corrected (but the fix is ugly) the multiple def button problem
[wxWidgets.git] / src / common / date.cpp
index 04d7fdbcb90120bd82848f54b975c474a23ee12d..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 wxChar *dayname[] = {
-    _T("Sunday"), _T("Monday"), _T("Tuesday"), _T("Wednesday"),
-    _T("Thursday"), _T("Friday"), _T("Saturday")
+    wxT("Sunday"), wxT("Monday"), wxT("Tuesday"), wxT("Wednesday"),
+    wxT("Thursday"), wxT("Friday"), wxT("Saturday")
 };
 
 static const wxChar *mname[] = {
-    _T("January"), _T("February"), _T("March"), _T("April"), _T("May"), _T("June"),
-    _T("July"), _T("August"), _T("September"), _T("October"), _T("November"), _T("December")
+    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 };
@@ -94,7 +88,7 @@ wxDate::wxDate (const wxString& dat)
 {
     DisplayFormat=wxMDY;
     DisplayOptions='\0';
-    if (wxStrcmp(dat, _T("TODAY")) == 0 || wxStrcmp(dat, _T("today")) == 0)
+    if (wxStrcmp(dat, wxT("TODAY")) == 0 || wxStrcmp(dat, wxT("today")) == 0)
     {
         // Sets the current date
         Set();
@@ -102,12 +96,12 @@ wxDate::wxDate (const wxString& dat)
     else
     {
         wxChar buf[100];
-        wxStrcpy(buf, WXSTRINGCAST dat);
+        wxStrcpy(buf, dat);
 
-        wxChar *save_ptr, *token = wxStrtok(buf,_T("/-"),&save_ptr);
+        wxChar *save_ptr, *token = wxStrtok(buf,wxT("/-"),&save_ptr);
         month = wxAtoi(token);
-        day   = wxAtoi(wxStrtok((wxChar *) NULL,_T("/-"),&save_ptr));
-        year  = wxAtoi(wxStrtok((wxChar *) NULL,_T(" "),&save_ptr));
+        day   = wxAtoi(wxStrtok((wxChar *) NULL,wxT("/-"),&save_ptr));
+        year  = wxAtoi(wxStrtok((wxChar *) NULL,wxT(" "),&save_ptr));
     }
 
     mdy_to_julian ();
@@ -137,7 +131,7 @@ void wxDate::operator = (const wxString& dat)
 {
     DisplayFormat=wxMDY;
     DisplayOptions='\0';
-    if (wxStrcmp(dat, _T("TODAY")) == 0 || wxStrcmp(dat, _T("today")) == 0)
+    if (wxStrcmp(dat, wxT("TODAY")) == 0 || wxStrcmp(dat, wxT("today")) == 0)
     {
         // Sets the current date
         Set();
@@ -145,12 +139,12 @@ void wxDate::operator = (const wxString& dat)
     else
     {
         wxChar buf[100];
-        wxStrcpy(buf, WXSTRINGCAST dat);
+        wxStrcpy(buf, dat);
 
-        wxChar *save_ptr, *token = wxStrtok(buf,_T("/-"),&save_ptr);
+        wxChar *save_ptr, *token = wxStrtok(buf,wxT("/-"),&save_ptr);
         month = wxAtoi(token);
-        day   = wxAtoi(wxStrtok((wxChar *) NULL,_T("/-"),&save_ptr));
-        year  = wxAtoi(wxStrtok((wxChar *) NULL,_T(" "),&save_ptr));
+        day   = wxAtoi(wxStrtok((wxChar *) NULL,wxT("/-"),&save_ptr));
+        year  = wxAtoi(wxStrtok((wxChar *) NULL,wxT(" "),&save_ptr));
     }
 
     mdy_to_julian ();
@@ -276,6 +270,9 @@ bool WXDLLEXPORT operator != (const wxDate &dt1, const wxDate &dt2)
     return ( dt1.julian != dt2.julian );
 }
 
+
+#if wxUSE_STD_IOSTREAM
+
 ////////////////////////////////////////////////////////////////
 // Ostream operations
 ////////////////////////////////////////////////////////////////
@@ -285,13 +282,19 @@ ostream WXDLLEXPORT & operator << (ostream &os, const wxDate &dt)
     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 ()
@@ -356,7 +359,7 @@ wxString wxDate::FormatDate (int type) const
                 wxStrcpy(buf, _("invalid day"));
             else
                 wxStrncpy( buf, wxGetTranslation(dayname[day_of_week-1]),
-                          (DisplayOptions & wxDATE_ABBR) ? ABBR_LENGTH : 9);
+               (DisplayOptions & wxDATE_ABBR) ? ABBR_LENGTH : 9);
             return wxString(buf);
 
         case wxMONTH:
@@ -364,7 +367,7 @@ wxString wxDate::FormatDate (int type) const
                 wxStrcpy(buf, _("invalid month"));
             else
                 wxStrncpy( buf, wxGetTranslation(mname[month-1]),
-                          (DisplayOptions & wxDATE_ABBR) ? ABBR_LENGTH : 9);
+               (DisplayOptions & wxDATE_ABBR) ? ABBR_LENGTH : 9);
             return wxString(buf);
 
         case wxFULL:
@@ -375,12 +378,12 @@ wxString wxDate::FormatDate (int type) const
                 return wxString(buf);
             }
             wxStrncpy( buf, wxGetTranslation(dayname[day_of_week-1]),
-                      (DisplayOptions & wxDATE_ABBR) ? ABBR_LENGTH : 9);
-            wxStrcat( buf, _T(", "));
+               (DisplayOptions & wxDATE_ABBR) ? ABBR_LENGTH : 9);
+            wxStrcat( buf, wxT(", "));
             wxStrncat( buf, wxGetTranslation(mname[month-1]),
-                      (DisplayOptions & wxDATE_ABBR) ? ABBR_LENGTH : 9);
-            wxStrcat( buf, _T(" "));
-            wxSprintf( buf+wxStrlen(buf), _T("%d, %d"), day, abs(year) );
+               (DisplayOptions & wxDATE_ABBR) ? ABBR_LENGTH : 9);
+            wxStrcat( buf, wxT(" "));
+            wxSprintf( buf+wxStrlen(buf), wxT("%d, %d"), day, abs(year) );
             if (year < 0)
                 wxStrcat(buf,_(" B.C."));
             return wxString(buf);
@@ -392,10 +395,10 @@ wxString wxDate::FormatDate (int type) const
                 wxStrcpy(buf, _("invalid date"));
                 return wxString(buf);
             }
-            wxSprintf(buf,_T("%d "),  day);
+            wxSprintf(buf,wxT("%d "),  day);
             wxStrncat(buf, wxGetTranslation(mname[month-1]),
                     (DisplayOptions & wxDATE_ABBR) ? ABBR_LENGTH : 9);
-            wxSprintf( buf+wxStrlen(buf), _T(" %d"), abs(year) );
+            wxSprintf( buf+wxStrlen(buf), wxT(" %d"), abs(year) );
             if (year < 0)
                 wxStrcat(buf, _(" B.C."));
             return wxString(buf);
@@ -405,13 +408,13 @@ wxString wxDate::FormatDate (int type) const
             if (day==0 || month==0 || year==0)
                 wxStrcpy(buf, _("invalid date"));
             else
-                wxSprintf( buf+wxStrlen(buf), _T("%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(_T(""));
+    return wxString(wxT(""));
 }
 
 void wxDate::SetFormat( int format )