OSDN Git Service

Fix Issue 94 Commit log showing incorrect timestamps
authorColin Law <colin@clanlaw.org.uk>
Sun, 7 Jun 2009 09:03:33 +0000 (10:03 +0100)
committerFrank Li <lznuaa@gmail.com>
Sun, 7 Jun 2009 10:12:14 +0000 (18:12 +0800)
Problem shows when local time is using daylight savings

src/Git/GitRev.cpp

index 59a9d79..31a38ad 100644 (file)
@@ -193,32 +193,31 @@ CTime GitRev::ConverFromString(CString input)
        // pick up date from string\r
        try\r
        {\r
-               CTime tm(_wtoi(input.Mid(0,4)),\r
+               COleDateTime tm(_wtoi(input.Mid(0,4)),\r
                                 _wtoi(input.Mid(5,2)),\r
                                 _wtoi(input.Mid(8,2)),\r
                                 _wtoi(input.Mid(11,2)),\r
                                 _wtoi(input.Mid(14,2)),\r
-                                _wtoi(input.Mid(17,2)),\r
-                                0);\r
-               if(tm.GetTime()<=1)\r
+                                _wtoi(input.Mid(17,2)));\r
+               if( tm.GetStatus() != COleDateTime::valid )\r
                        return CTime();//Error parsing time-string\r
 \r
                // pick up utc offset\r
                CString sign = input.Mid(20,1);         // + or -\r
                int hoursOffset =  _wtoi(input.Mid(21,2));\r
                int minsOffset = _wtoi(input.Mid(23,2));\r
+               // convert to a fraction of a day\r
+               double offset = (hoursOffset*60 + minsOffset) / 1440.0;         // 1440 mins = 1 day\r
                if ( sign == "-" )\r
                {\r
-                       hoursOffset = -hoursOffset;\r
-                       minsOffset = -minsOffset;\r
+                       offset = -offset;\r
                }\r
-               // make a timespan object with this value\r
-               CTimeSpan offset( 0, hoursOffset, minsOffset, 0 );\r
                // we have to subtract this from the time given to get UTC\r
                tm -= offset;\r
-               // get local timezone\r
+               // get utc time as a SYSTEMTIME\r
                SYSTEMTIME sysTime;\r
                tm.GetAsSystemTime( sysTime );\r
+               // and convert to users local time\r
                SYSTEMTIME local;\r
                if ( SystemTimeToTzSpecificLocalTime( &m_TimeZone, &sysTime, &local ) )\r
                {\r
@@ -226,10 +225,10 @@ CTime GitRev::ConverFromString(CString input)
                }\r
                else\r
                {\r
-                       ASSERT(false);\r
+                       ASSERT(false);  // this should not happen but leave time in utc if it does\r
                }\r
-               tm = CTime( sysTime, 0 );\r
-               return tm;\r
+               // convert to CTime and return\r
+               return CTime( sysTime, -1 );;\r
        }\r
        catch(CException* e)\r
        {\r