2. small wxDateTime bug fixed
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5121 
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
     // time. Using the functions below, it may be converted to another time
     // zone (for example, the Unix epoch is wxDateTime(1, Jan, 1970).ToGMT())
     //
     // time. Using the functions below, it may be converted to another time
     // zone (for example, the Unix epoch is wxDateTime(1, Jan, 1970).ToGMT())
     //
+    // these functions try to handle DST internally, but there is no magical
+    // way to know all rules for it in all countries in the world, so if the
+    // program can handle it itself (or doesn't want to handle it at all for
+    // whatever reason), the DST handling can be disabled with noDST.
+    //
     // Converting to the local time zone doesn't do anything.
     // ------------------------------------------------------------------------
 
         // transform to any given timezone
     // Converting to the local time zone doesn't do anything.
     // ------------------------------------------------------------------------
 
         // transform to any given timezone
-    inline wxDateTime ToTimezone(const TimeZone& tz) const;
-    wxDateTime& MakeTimezone(const TimeZone& tz);
+    inline wxDateTime ToTimezone(const TimeZone& tz, bool noDST = FALSE) const;
+    wxDateTime& MakeTimezone(const TimeZone& tz, bool noDST = FALSE);
-    wxDateTime ToGMT() const { return ToTimezone(GMT0); }
-    wxDateTime& MakeGMT() { return MakeTimezone(GMT0); }
+    wxDateTime ToGMT(bool noDST = FALSE) const { return ToTimezone(GMT0, noDST); }
+    wxDateTime& MakeGMT(bool noDST = FALSE) { return MakeTimezone(GMT0, noDST); }
 
         // is daylight savings time in effect at this moment according to the
         // rules of the specified country?
 
         // is daylight savings time in effect at this moment according to the
         // rules of the specified country?
 
 // wxDateTime and timezones
 // ----------------------------------------------------------------------------
 
 // wxDateTime and timezones
 // ----------------------------------------------------------------------------
 
-wxDateTime wxDateTime::ToTimezone(const wxDateTime::TimeZone& tz) const
+wxDateTime wxDateTime::ToTimezone(const wxDateTime::TimeZone& tz,
+                                  bool noDST) const
-    return wxDateTime(*this).MakeTimezone(tz);
+    return wxDateTime(*this).MakeTimezone(tz, noDST);
 }
 
 // ----------------------------------------------------------------------------
 }
 
 // ----------------------------------------------------------------------------
 
 
 #include <limits.h>     // for LONG_MAX
 
 
 #include <limits.h>     // for LONG_MAX
 
-//#define wxUSE_LONGLONG_WX 1 // for testing (VZ)
+// #define wxUSE_LONGLONG_WX 1 // for testing (VZ)
 
 // ----------------------------------------------------------------------------
 // decide upon which class we will use
 
 // ----------------------------------------------------------------------------
 // decide upon which class we will use
 
 #endif // TEST_MIME
 
 #ifdef TEST_TIME
 #endif // TEST_MIME
 
 #ifdef TEST_TIME
     {
     TestTimeSet();
     TestTimeStatic();
     {
     TestTimeSet();
     TestTimeStatic();
     TestTimeWDays();
     TestTimeWNumber();
     TestTimeParse();
     TestTimeWDays();
     TestTimeWNumber();
     TestTimeParse();
 #endif // TEST_TIME
 
     wxUninitialize();
 #endif // TEST_TIME
 
     wxUninitialize();
 
 
         dt += wxTimeSpan::Hours(1);
 
 
         dt += wxTimeSpan::Hours(1);
 
+        // disable DST tests because it could result in an infinite recursion!
+        dt.MakeGMT(TRUE);
     }
     else switch ( country )
     {
     }
     else switch ( country )
     {
 
         dt += wxTimeSpan::Hours(1);
 
 
         dt += wxTimeSpan::Hours(1);
 
+        // disable DST tests because it could result in an infinite recursion!
+        dt.MakeGMT(TRUE);
     }
     else switch ( country )
     {
     }
     else switch ( country )
     {
 
 wxDateTime::wxDateTime_t wxDateTime::GetWeekOfYear(const TimeZone& tz) const
 {
 
 wxDateTime::wxDateTime_t wxDateTime::GetWeekOfYear(const TimeZone& tz) const
 {
     // the first week of the year is the one which contains Jan, 4 (according
     // to ISO standard rule), so the year day N0 = 4 + 7*W always lies in the
     // week W+1. As any day N = 7*W + 4 + (N - 4)%7, it lies in the same week
     // the first week of the year is the one which contains Jan, 4 (according
     // to ISO standard rule), so the year day N0 = 4 + 7*W always lies in the
     // week W+1. As any day N = 7*W + 4 + (N - 4)%7, it lies in the same week
-#else // this seems to be a bit simpler and I believe is also correct
+#else // 0
+    // an attempt at doing it simpler - but this doesn't quite work...
     return (WeekDay)((GetDayOfYear(tz) - (GetWeekDay(tz) - 1 + 7) % 7 + 7) / 7);
 #endif // 0/1
 }
     return (WeekDay)((GetDayOfYear(tz) - (GetWeekDay(tz) - 1 + 7) % 7 + 7) / 7);
 #endif // 0/1
 }
-wxDateTime& wxDateTime::MakeTimezone(const TimeZone& tz)
+wxDateTime& wxDateTime::MakeTimezone(const TimeZone& tz, bool noDST)
 {
     int secDiff = GetTimeZone() + tz.GetOffset();
 
 {
     int secDiff = GetTimeZone() + tz.GetOffset();
 
-    // we need to know whether DST is or not in effect for this date
-    if ( IsDST() == 1 )
+    // we need to know whether DST is or not in effect for this date unless
+    // the test disabled by the caller
+    if ( !noDST && (IsDST() == 1) )
     {
         // FIXME we assume that the DST is always shifted by 1 hour
         secDiff -= 3600;
     {
         // FIXME we assume that the DST is always shifted by 1 hour
         secDiff -= 3600;
 
                     // this is the format which corresponds to ctime() output
                     // and strptime("%c") should parse it, so try it first
 
                     // this is the format which corresponds to ctime() output
                     // and strptime("%c") should parse it, so try it first
-                    static const wxChar *fmtCtime = _T("%a %b %e %H:%M:%S %Y");
+                    static const wxChar *fmtCtime = _T("%a %b %d %H:%M:%S %Y");
 
                     const wxChar *result = dt.ParseFormat(input, fmtCtime);
                     if ( !result )
 
                     const wxChar *result = dt.ParseFormat(input, fmtCtime);
                     if ( !result )
+                    wxString fmtDate, fmtDateAlt;
                     if ( IsWestEuropeanCountry(GetCountry()) ||
                          GetCountry() == Russia )
                     {
                         fmtDate = _T("%d/%m/%y");
                     if ( IsWestEuropeanCountry(GetCountry()) ||
                          GetCountry() == Russia )
                     {
                         fmtDate = _T("%d/%m/%y");
+                        fmtDateAlt = _T("%m/%d/%y");
                     }
                     else // assume USA
                     {
                         fmtDate = _T("%m/%d/%y");
                     }
                     else // assume USA
                     {
                         fmtDate = _T("%m/%d/%y");
+                        fmtDateAlt = _T("%d/%m/%y");
                     }
 
                     const wxChar *result = dt.ParseFormat(input, fmtDate);
                     }
 
                     const wxChar *result = dt.ParseFormat(input, fmtDate);
+
+                    if ( !result )
+                    {
+                        // ok, be nice and try another one
+                        result = dt.ParseFormat(input, fmtDateAlt);
+                    }
+
                     if ( !result )
                     {
                         // bad luck
                     if ( !result )
                     {
                         // bad luck
 
 #include "wx/longlong.h"
 
 #include <memory.h>     // for memset()
 #include "wx/longlong.h"
 
 #include <memory.h>     // for memset()
+#include <math.h>       // for fabs()
 
 // ============================================================================
 // implementation
 
 // ============================================================================
 // implementation
 
 #endif // wxUSE_LONGLONG_NATIVE
 
 
 #endif // wxUSE_LONGLONG_NATIVE
 
+// ============================================================================
+// wxLongLongWx: emulation of 'long long' using 2 longs
+// ============================================================================
+
+// assignment
+wxLongLongWx& wxLongLongWx::Assign(double d)
+{
+    if ( fabs(d) <= LONG_MAX )
+    {
+        m_hi = d < 0 ? 1 << (8*sizeof(long) - 1) : 0l;
+        m_lo = (long)d;
+    }
+    else
+    {
+        wxFAIL_MSG(_T("TODO"));       
+    }
+
+    return *this;
+}
+
 wxLongLongWx wxLongLongWx::operator<<(int shift) const
 {
     if (shift == 0)
 wxLongLongWx wxLongLongWx::operator<<(int shift) const
 {
     if (shift == 0)