X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c30aaf75f0571d18abee4068c36df0a7f07842cb..e1ee679c2e3f48bc4f2607e35033ed5505ed6665:/src/common/date.cpp diff --git a/src/common/date.cpp b/src/common/date.cpp index e3e808ee5c..5d89d60e25 100644 --- a/src/common/date.cpp +++ b/src/common/date.cpp @@ -23,38 +23,33 @@ #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif -#include "wx/setup.h" - #if wxUSE_TIMEDATE #include "wx/date.h" -#include +#include "wx/intl.h" #include #include #include -#if wxUSE_IOSTREAMH -#include -#else -#include -#endif +#include "wx/ioswrap.h" #include #include #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 + 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 )