X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3f4a0c5be34be837210768501c13dbcff81e533c..5ea6dbbfff67d1dfad08044ab721ba56425ef6e1:/src/common/time.cpp diff --git a/src/common/time.cpp b/src/common/time.cpp index 71ad2fac3a..74018b0079 100644 --- a/src/common/time.cpp +++ b/src/common/time.cpp @@ -34,23 +34,45 @@ seconds since January 1, 1901, GMT. #include "wx/utils.h" #include "wx/intl.h" -#include "wx/ioswrap.h" - -#if wxUSE_IOSTREAMH - #include -#else - #include +#if wxUSE_STD_IOSTREAM + #include "wx/ioswrap.h" + #if wxUSE_IOSTREAMH + #include + #else + #include + #endif #endif #include +#include -#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxTime, wxObject) + + +#ifndef WX_TIMEZONE + #define WX_TIMEZONE _timezone #endif +extern long wxGetUTCTime(void); +bool wxGetTZandDST(long *timeZone, int *dstObserved) +{ + time_t now; + struct tm *tm; + + now = time((time_t *) NULL); + + if (now != (time_t)-1) + { + tm = localtime(&now); + + if ((tm) && (tm->tm_isdst > 0)) + *dstObserved = 1; + } + *timeZone = WX_TIMEZONE; + + return TRUE; +} -extern bool wxGetLocalTime(long *timeZone, int *dstObserved); -extern long wxGetCurrentTime(void); static long TIME_ZONE; /* seconds west of GMT */ static int DST_OBSERVED; /* flags U.S. daylight saving time observed */ @@ -58,7 +80,7 @@ static int DST_OBSERVED; /* flags U.S. daylight saving time observed */ static bool wxTimeInitialized = FALSE; wxTime::tFormat wxTime::Format = wxTime::wx12h; -wxTime::tPrecision wxTime::Precision = wxTime::wxStdMinSec; +wxTime::tPrecision wxTime::Precision = wxTime::wxStdMinSec; static const unsigned long seconds_in_day = 24*60*60L; static const wxDate refDate(1,1,1901); @@ -72,7 +94,7 @@ wxTime wxTime::GetLocalTime(const wxDate& date, hourTy h, minuteTy m, secondTy s { if (!wxTimeInitialized) { - wxGetLocalTime(&TIME_ZONE, &DST_OBSERVED); + wxGetTZandDST(&TIME_ZONE, &DST_OBSERVED); wxTimeInitialized = TRUE; } /* @@ -97,10 +119,10 @@ wxTime::wxTime() { if (!wxTimeInitialized) { - wxGetLocalTime(&TIME_ZONE, &DST_OBSERVED); + wxGetTZandDST(&TIME_ZONE, &DST_OBSERVED); wxTimeInitialized = TRUE; } - sec = wxGetCurrentTime(); + sec = wxGetUTCTime(); #ifdef __SALFORDC__ sec += (unsigned long) 2177452800; /* seconds from 1/1/01 to 1/1/70 */ #else @@ -116,7 +138,7 @@ wxTime::wxTime(hourTy h, minuteTy m, secondTy s, bool dst) { if (!wxTimeInitialized) { - wxGetLocalTime(&TIME_ZONE, &DST_OBSERVED); + wxGetTZandDST(&TIME_ZONE, &DST_OBSERVED); wxTimeInitialized = TRUE; } @@ -132,7 +154,7 @@ wxTime::wxTime(const wxDate& date, hourTy h, minuteTy m, secondTy s, bool dst) { if (!wxTimeInitialized) { - wxGetLocalTime(&TIME_ZONE, &DST_OBSERVED); + wxGetTZandDST(&TIME_ZONE, &DST_OBSERVED); wxTimeInitialized = TRUE; } sec = GetLocalTime(date,h,m,s).sec-3600; @@ -319,7 +341,7 @@ wxTime wxTime::Min(const wxTime& t) const } #ifndef __SALFORDC__ -wxTime::operator char *(void) +wxTime::operator wxChar *(void) { return FormatTime(); } @@ -332,8 +354,8 @@ void wxTime::SetFormat(const wxTime::tFormat lFormat, wxTime::Precision = lPrecision; } -char *wxTime::FormatTime() const { - static char timeBuf[30]; +wxChar *wxTime::FormatTime() const { + static wxChar timeBuf[30]; unsigned hh(GetHour()); switch (Format) { @@ -346,18 +368,18 @@ char *wxTime::FormatTime() const { switch (Precision) { case wxStdMinSec: - sprintf(timeBuf,"%2d:%02d:%02d",hh,GetMinute(),GetSecond()); + wxSprintf(timeBuf,wxT("%2d:%02d:%02d"),hh,GetMinute(),GetSecond()); break; case wxStdMin: - sprintf(timeBuf,"%2d:%02d",hh,GetMinute()); + wxSprintf(timeBuf,wxT("%2d:%02d"),hh,GetMinute()); break; } if (Format == wx12h) if (GetHour() <= 12) - strcat(timeBuf,_("am")); + wxStrcat(timeBuf,_("am")); else - strcat(timeBuf,_("pm")); + wxStrcat(timeBuf,_("pm")); return timeBuf; }