[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE_3_3_BRANCH: kdelibs/kjs
From:       Pascal Létourneau <pletourn () globetrotter ! net>
Date:       2004-09-30 15:36:55
Message-ID: 20040930153655.08C1F9922 () office ! kde ! org
[Download RAW message or body]

CVS commit by pletourn: 

Fix new Date("01 Jan 2004 10:00")
Fix Date.setUTC*()
Fix Date.UTC()
CCMAIL:78717-done@bugs.kde.org


  M +23 -19    date_object.cpp   1.80.2.2
  M +1 -1      date_object.h   1.22.6.1


--- kdelibs/kjs/date_object.h  #1.22:1.22.6.1
@@ -123,5 +123,5 @@ namespace KJS {
   double KRFCDate_parseDate(const UString &_date);
   Value timeClip(const Value &t);
-  int local_timeoffset();
+  Number makeTime(struct tm *t, int milli, bool utc);
 
 } // namespace

--- kdelibs/kjs/date_object.cpp  #1.80.2.1:1.80.2.2
@@ -380,6 +380,5 @@ Value DateProtoFuncImp::call(ExecState *
       id == SetMinutes || id == SetHours || id == SetDate ||
       id == SetMonth || id == SetFullYear ) {
-    t->tm_isdst = -1; // reset DST
-    result = Number(mktime(t) * 1000.0 + ms);
+    result = makeTime(t, ms, utc);
     thisObj.setInternalValue(result);
   }
@@ -462,5 +461,5 @@ Object DateObjectImp::construct(ExecStat
     t.tm_isdst = -1;
     int ms = (numArgs >= 7) ? args[6].toInt32(exec) : 0;
-    value = Number(mktime(&t) * 1000.0 + ms);
+    value = makeTime(&t, ms, false);
   }
 
@@ -522,5 +521,5 @@ Value DateObjectFuncImp::call(ExecState 
     t.tm_sec = (n >= 6) ? args[5].toInt32(exec) : 0;
     int ms = (n >= 7) ? args[6].toInt32(exec) : 0;
-    return Number(mktime(&t) * 1000.0 + ms);
+    return makeTime(&t, ms, true);
   }
 }
@@ -594,17 +593,19 @@ static const struct {
 };
 
-int KJS::local_timeoffset()
+Number KJS::makeTime(struct tm *t, int ms, bool utc)
 {
-     static int local_offset = -1;
-
-     if ( local_offset != -1 ) return local_offset;
-
-     time_t local = time(0);
-     struct tm* tm_local = gmtime(&local);
-     local_offset = local-mktime(tm_local);
-     if(tm_local->tm_isdst)
-       local_offset += 3600;
+    int utcOffset;
+    if (utc) {
+        time_t zero = 0;
+        struct tm t3;
+        localtime_r(&zero, &t3);
+        utcOffset = t3.tm_gmtoff;
+        t->tm_isdst = t3.tm_isdst;
+    } else {
+        utcOffset = 0;
+        t->tm_isdst = -1;
+    }
 
-     return local_offset;
+    return Number( ( mktime(t) + utcOffset ) * 1000.0 + ms );
 }
 
@@ -863,5 +864,5 @@ double KJS::KRFCDate_parseDate(const USt
         return invalidDate;
 
-     if (!have_time && !have_tz) {
+     if (!have_tz) {
        // fall back to midnight, local timezone
        struct tm t;
@@ -871,10 +872,13 @@ double KJS::KRFCDate_parseDate(const USt
        t.tm_year = year - 1900;
        t.tm_isdst = -1;
+       if (have_time) {
+         t.tm_sec = second;
+         t.tm_min = minute;
+         t.tm_hour = hour;
+       }
+            
        return mktime(&t);
      }
 
-     if(!have_tz)
-       offset = local_timeoffset();
-     else
        offset *= 60;
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic