* Fixed bugs #1697, #1465, #4849, #5183: Datetime input fields and timezone shift bug
authorErnesto Baschny <ernst@cron-it.de>
Thu, 22 Nov 2007 15:58:42 +0000 (15:58 +0000)
committerErnesto Baschny <ernst@cron-it.de>
Thu, 22 Nov 2007 15:58:42 +0000 (15:58 +0000)
* Fixed: The click-checkbox to set the current date/time did not work on fields with eval year, time and timesec.
* Fixed: Setting a field of eval "timesec" as a label of a table would show an integer instead of the hh:mm:ss string

git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@2752 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_befunc.php
t3lib/class.t3lib_tceforms.php
t3lib/jsfunc.evalfield.js
typo3/jsfunc.tbe_editor.js

index fe6ff77..755b32a 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-11-22  Ernesto Baschny  <ernst@cron-it.de>
+
+       * Fixed bugs #1697, #1465, #4849, #5183: Datetime input fields and timezone shift bug
+       * Fixed: The click-checkbox to set the current date/time did not work on fields with eval year, time and timesec.
+       * Fixed: Setting a field of eval "timesec" as a label of a table would show an integer instead of the hh:mm:ss string
+
 2007-11-22  Bernhard Kraft  <kraftb@kraftb.at>
 
        * Added hooks #6738: Hooks for Web>List module which allow modification/addition/removal of icons for each table and its records
index 97ef22d..a163492 100755 (executable)
@@ -1488,13 +1488,17 @@ class t3lib_BEfunc      {
         * Usage: 1 (class t3lib_BEfunc)
         *
         * @param       integer         Time stamp, seconds
+        * @param       boolean         Output hh:mm:ss. If false: hh:mm
         * @return      string          Formatted time
         */
-       function time($value)   {
+       function time($value, $withSeconds = TRUE)      {
                $hh = floor($value/3600);
                $min = floor(($value-$hh*3600)/60);
                $sec = $value-$hh*3600-$min*60;
-               $l = sprintf('%02d',$hh).':'.sprintf('%02d',$min).':'.sprintf('%02d',$sec);
+               $l = sprintf('%02d',$hh).':'.sprintf('%02d',$min);
+               if ($withSeconds)       {
+                       $l .= ':'.sprintf('%02d',$sec);
+               }
                return $l;
        }
 
@@ -2079,6 +2083,8 @@ class t3lib_BEfunc        {
                                                if (t3lib_div::inList($theColConf['eval'],'date'))      {
                                                        $l = t3lib_BEfunc::date($value).' ('.(time()-$value>0?'-':'').t3lib_BEfunc::calcAge(abs(time()-$value), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears')).')';
                                                } elseif (t3lib_div::inList($theColConf['eval'],'time'))        {
+                                                       $l = t3lib_BEfunc::time($value, FALSE);
+                                               } elseif (t3lib_div::inList($theColConf['eval'],'timesec'))     {
                                                        $l = t3lib_BEfunc::time($value);
                                                } elseif (t3lib_div::inList($theColConf['eval'],'datetime'))    {
                                                        $l = t3lib_BEfunc::datetime($value);
index 0ca4f0d..f661e19 100755 (executable)
@@ -1112,13 +1112,22 @@ class t3lib_TCEforms    {
                $paramsList = "'".$PA['itemFormElName']."','".implode(',',$evalList)."','".trim($config['is_in'])."',".(isset($config['checkbox'])?1:0).",'".$config['checkbox']."'";
                if (isset($config['checkbox'])) {
                                // Setting default "click-checkbox" values for eval types "date" and "datetime":
-                       $thisMidnight = mktime(0,0,0);
-                       $checkSetValue = in_array('date',$evalList) ? $thisMidnight : '';
-                       $checkSetValue = in_array('datetime',$evalList) ? time() : $checkSetValue;
-
+                       $thisMidnight = gmmktime(0,0,0);
+                       if (in_array('date',$evalList)) {
+                               $checkSetValue = $thisMidnight;
+                       } elseif (in_array('datetime',$evalList))       {
+                               $checkSetValue = time();
+                       } elseif (in_array('year',$evalList))   {
+                               $checkSetValue = gmdate('Y');
+                       }
                        $cOnClick = 'typo3form.fieldGet('.$paramsList.',1,\''.$checkSetValue.'\');'.implode('',$PA['fieldChangeFunc']);
                        $item.='<input type="checkbox"'.$this->insertDefStyle('check').' name="'.$PA['itemFormElName'].'_cb" onclick="'.htmlspecialchars($cOnClick).'" />';
                }
+               if((in_array('date',$evalList) || in_array('datetime',$evalList)) && $PA['itemFormElValue']>0){
+                               // Add server timezone offset to UTC to our stored date
+                       $hoursOffset = date('O',$PA['itemFormElValue'])/100;
+                       $PA['itemFormElValue'] += ($hoursOffset*60*60);
+               }
 
                $PA['fieldChangeFunc'] = array_merge(array('typo3form.fieldGet'=>'typo3form.fieldGet('.$paramsList.');'), $PA['fieldChangeFunc']);
                $mLgd = ($config['max']?$config['max']:256);
index 2b55704..41cf7ce 100755 (executable)
@@ -34,6 +34,9 @@ function evalFunc()   {
        this.getSecs = evalFunc_getSecs;
        this.getYear = evalFunc_getYear;
        this.getTimeSecs = evalFunc_getTimeSecs;
+       this.getTime = evalFunc_getTime;
+       this.getDate = evalFunc_getDate;
+       this.getTimestamp = evalFunc_getTimestamp;
        this.caseSwitch = evalFunc_caseSwitch;
        this.evalObjValue = evalFunc_evalObjValue;
        this.outputObjValue = evalFunc_outputObjValue;
@@ -44,8 +47,8 @@ function evalFunc()   {
        this.btrim = evalFunc_btrim;
        var today = new Date();
        this.lastYear = this.getYear(today);
-       this.lastDate = this.getSecs(today);
-       this.lastTime = this.getTimeSecs(today);
+       this.lastDate = this.getDate(today);
+       this.lastTime = this.getTimestamp(today);
        this.isInString = '';
        this.USmode = 0;
 }
@@ -245,7 +248,7 @@ function evalFunc_input(type,inVal) {
                return this.parseDouble(inVal);
        }
 
-       var today = new Date()
+       var today = new Date();
        var add=0;
        var value = this.ltrim(inVal);
        var values = new evalFunc_split(value);
@@ -261,8 +264,6 @@ function evalFunc_input(type,inVal) {
                                case "d":
                                case "t":
                                case "n":
-                                       var theTime = new Date(this.getYear(today), today.getMonth(), today.getDate(), today.getHours(), today.getMinutes());
-                                       this.lastDate = this.getSecs(theTime)
                                        if (values.valPol[1])   {
                                                add = this.pol(values.valPol[1],this.parseInt(values.values[1]));
                                        }
@@ -276,20 +277,17 @@ function evalFunc_input(type,inVal)       {
                                default:
                                        var index = value.indexOf(' ');
                                        if (index!=-1)  {
-                                               var theSecs = this.input("date",value.substr(index,value.length)) + this.input("time",value.substr(0,index));
-                                               this.lastDate = theSecs;
+                                               this.lastTime = this.input("date",value.substr(index,value.length)) + this.input("time",value.substr(0,index));
                                        }
                        }
-                       this.lastDate+=add*24*60*60;
-                       return this.lastDate;
+                       this.lastTime+=add*24*60*60;
+                       return this.lastTime;
                break;
                case "year":
                        switch (theCmd) {
                                case "d":
                                case "t":
                                case "n":
-                                       var theTime = today;
-                                       this.lastYear = this.getYear(theTime);
                                        if (values.valPol[1])   {
                                                add = this.pol(values.valPol[1],this.parseInt(values.values[1]));
                                        }
@@ -305,11 +303,13 @@ function evalFunc_input(type,inVal)       {
                                                add = this.pol(values.valPol[2],this.parseInt(values.values[2]));
                                        }
                                        var year = (values.values[1])?this.parseInt(values.values[1]):this.getYear(today);
-                                               if (  (year>=0&&year<38) || (year>=70&&year<100) || (year>=1970&&year<2038)     )       {
-                                                       if (year<100)   {
-                                                               year = (year<38) ? year+=2000 : year+=1900;
-                                                       }
-                                               } else {year = this.getYear(today);}
+                                       if (  (year>=0&&year<38) || (year>=70&&year<100) || (year>=1970&&year<2038)     )       {
+                                               if (year<100)   {
+                                                       year = (year<38) ? year+=2000 : year+=1900;
+                                               }
+                                       } else {
+                                               year = this.getYear(today);
+                                       }
                                        this.lastYear = year
                        }
                        this.lastYear+=add;
@@ -320,8 +320,6 @@ function evalFunc_input(type,inVal) {
                                case "d":
                                case "t":
                                case "n":
-                                       var theTime = new Date(this.getYear(today), today.getMonth(), today.getDate());
-                                       this.lastDate = this.getSecs(theTime);
                                        if (values.valPol[1])   {
                                                add = this.pol(values.valPol[1],this.parseInt(values.values[1]));
                                        }
@@ -346,23 +344,22 @@ function evalFunc_input(type,inVal)       {
                                        }
 
                                        var year = (values.values[3])?this.parseInt(values.values[3]):this.getYear(today);
-                                               if (  (year>=0&&year<38) || (year>=70&&year<100) || (year>=1970&&year<2038)     )       {
-                                                       if (year<100)   {
-                                                               year = (year<38) ? year+=2000 : year+=1900;
-                                                       }
-                                               } else {year = this.getYear(today);}
-                                       var month = (values.values[this.USmode?1:2])?this.parseInt(values.values[this.USmode?1:2]):today.getMonth()+1;
-                                               if (month > 12) {month=12;}
-                                               if (month < 1)  {month=1;}
-                                       var day = (values.values[this.USmode?2:1])?this.parseInt(values.values[this.USmode?2:1]):today.getDate();
-                                               if (day > 31)   {day=31;}
-                                               if (day < 1)    {day=1;}
-                                       if (''+day+'-'+month+'-'+year == "1-1-1970")    {
-                                               var theTime = new Date();  theTime.setTime(0);
+                                       if ( (year>=0&&year<38) || (year>=70&&year<100) || (year>=1970&&year<2038) )    {
+                                               if (year<100)   {
+                                                       year = (year<38) ? year+=2000 : year+=1900;
+                                               }
                                        } else {
-                                               var theTime = new Date(parseInt(year), parseInt(month)-1, parseInt(day));
+                                               year = this.getYear(today);
                                        }
-                                       this.lastDate = this.getSecs(theTime)
+                                       var month = (values.values[this.USmode?1:2])?this.parseInt(values.values[this.USmode?1:2]):today.getUTCMonth()+1;
+                                       var day = (values.values[this.USmode?2:1])?this.parseInt(values.values[this.USmode?2:1]):today.getUTCDate();
+
+                                       var theTime = new Date(parseInt(year), parseInt(month)-1, parseInt(day));
+
+                                               // Substract timezone offset from client
+                                       this.lastDate = this.getTimestamp(theTime);
+                                       theTime.setTime((this.lastDate - theTime.getTimezoneOffset()*60)*1000);
+                                       this.lastDate = this.getTimestamp(theTime);
                        }
                        this.lastDate+=add*24*60*60;
                        if (this.lastDate<0) {this.lastDate=0;}
@@ -374,8 +371,6 @@ function evalFunc_input(type,inVal) {
                                case "d":
                                case "t":
                                case "n":
-                                       var theTime = new Date(this.getYear(today), today.getMonth(), today.getDate(), today.getHours(), today.getMinutes(), ((type=="timesec")?today.getSeconds():0));
-                                       this.lastTime = this.getTimeSecs(theTime);
                                        if (values.valPol[1])   {
                                                add = this.pol(values.valPol[1],this.parseInt(values.values[1]));
                                        }
@@ -398,14 +393,18 @@ function evalFunc_input(type,inVal)       {
                                                var temp = values.values[1];
                                                values = new evalFunc_splitSingle(temp);
                                        }
-                                       var sec = (values.values[3])?this.parseInt(values.values[3]):today.getSeconds();
-                                               if (sec > 59)   {sec=59;}
-                                       var min = (values.values[2])?this.parseInt(values.values[2]):today.getMinutes();
-                                               if (min > 59)   {min=59;}
-                                       var hour = (values.values[1])?this.parseInt(values.values[1]):today.getHours();
-                                               if (hour > 23)  {hour=23;}
-                                       var theTime = new Date(this.getYear(today), today.getMonth(), today.getDate(), hour, min, ((type=="timesec")?sec:0));
-                                       this.lastTime = this.getTimeSecs(theTime)
+                                       var sec = (values.values[3])?this.parseInt(values.values[3]):today.getUTCSeconds();
+                                       if (sec > 59)   {sec=59;}
+                                       var min = (values.values[2])?this.parseInt(values.values[2]):today.getUTCMinutes();
+                                       if (min > 59)   {min=59;}
+                                       var hour = (values.values[1])?this.parseInt(values.values[1]):today.getUTCHours();
+                                       if (hour > 23)  {hour=23;}
+
+                                       var theTime = new Date(this.getYear(today), today.getUTCMonth(), today.getUTCDate(), hour, min, ((type=="timesec")?sec:0));
+
+                                       this.lastTime = this.getTimestamp(theTime);
+                                       theTime.setTime((this.lastTime - theTime.getTimezoneOffset()*60)*1000);
+                                       this.lastTime = this.getTime(theTime);
                        }
                        this.lastTime+=add*60;
                        if (this.lastTime<0) {this.lastTime+=24*60*60;}
@@ -420,28 +419,24 @@ function evalFunc_output(type,value,FObj) {
        switch (type)   {
                case "date":
                        if (!parseInt(value))   {return '';}
-                       var theTime = new Date();
-                       theTime.setTime(value*1000);
+                       var theTime = new Date(parseInt(value) * 1000);
                        if (this.USmode)        {
-                               theString = (theTime.getMonth()+1)+'-'+theTime.getDate()+'-'+this.getYear(theTime);
+                               theString = (theTime.getUTCMonth()+1)+'-'+theTime.getUTCDate()+'-'+this.getYear(theTime);
                        } else {
-                               theString = theTime.getDate()+'-'+(theTime.getMonth()+1)+'-'+this.getYear(theTime);
+                               theString = theTime.getUTCDate()+'-'+(theTime.getUTCMonth()+1)+'-'+this.getYear(theTime);
                        }
                break;
                case "datetime":
                        if (!parseInt(value))   {return '';}
-                       var theTime = new Date();
-                       theTime.setTime(value*1000);
-                       theString = this.output("time",this.getTimeSecs(theTime))+' '+this.output("date",value);
+                       theString = this.output("time",value)+' '+this.output("date",value);
                break;
                case "time":
                case "timesec":
                        if (!parseInt(value))   {return '';}
-                       var theTime = new Date();
-                       theTime.setTime(value*1000);
-                       var h = Math.floor(value/3600);
-                       var m = Math.floor((value-h*3600)/60);
-                       var s = Math.floor(value-h*3600-m*60);
+                       var theTime = new Date(parseInt(value) * 1000);
+                       var h = theTime.getUTCHours();
+                       var m = theTime.getUTCMinutes();
+                       var s = theTime.getUTCSeconds();
                        theString = h+':'+((m<10)?'0':'')+m + ((type=="timesec")?':'+((s<10)?'0':'')+s:'');
                break;
                case "password":
@@ -456,14 +451,23 @@ function evalFunc_output(type,value,FObj) {
        return theString;
 }
 function evalFunc_getSecs(timeObj)     {
-       return Math.round(timeObj.getTime()/1000);
+       return Math.round(timeObj.getUTCSeconds()/1000);
+}
+// Seconds since midnight:
+function evalFunc_getTime(timeObj)     {
+       return timeObj.getUTCHours()*60*60+timeObj.getUTCMinutes()*60+Math.round(timeObj.getUTCSeconds()/1000);
 }
 function evalFunc_getYear(timeObj)     {
-       return (timeObj.getYear()>200) ? timeObj.getYear() : (timeObj.getYear()+1900);
+       return timeObj.getUTCFullYear();
 }
+// Seconds since midnight with client timezone offset:
 function evalFunc_getTimeSecs(timeObj) {
        return timeObj.getHours()*60*60+timeObj.getMinutes()*60+timeObj.getSeconds();
 }
+function evalFunc_getDate(timeObj)     {
+       var theTime = new Date(this.getYear(timeObj), timeObj.getUTCMonth(), timeObj.getUTCDate());
+       return this.getTimestamp(theTime);
+}
 function evalFunc_dummy (evallist,is_in,checkbox,checkboxValue) {
        this.evallist = evallist;
        this.is_in = is_in;
@@ -483,4 +487,6 @@ function evalFunc_splitStr(theStr1, delim, index) {
        if(ePos == -1)  {ePos = theStr.length;}
        return (theStr.substring(sPos+lengthOfDelim,ePos));
 }
-
+function evalFunc_getTimestamp(timeObj)        {
+       return Date.parse(timeObj)/1000;
+}
\ No newline at end of file
index 67f78f3..d0e1fcf 100755 (executable)
@@ -444,6 +444,18 @@ var typo3form = {
                        var theFObj = new evalFunc_dummy (evallist,is_in, checkbox, checkboxValue);
                        if (checkbox_off)       {
                                if (document[TBE_EDITOR.formname][theField+"_cb"].checked)      {
+                                       var split = evallist.split(',');
+                                       for (var i = 0; split.length > i; i++) {
+                                               var el = split[i].replace(/ /g, '');
+                                               if (el == 'datetime' || el == 'date')   {
+                                                       var now = new Date();
+                                                       checkSetValue = Date.parse(now)/1000 - now.getTimezoneOffset()*60;
+                                                       break;
+                                               } else if (el == 'time' || el == 'timesec')     {
+                                                       checkSetValue = evalFunc_getTimeSecs(new Date());
+                                                       break;
+                                               }
+                                       }
                                        document[TBE_EDITOR.formname][theField].value=checkSetValue;
                                } else {
                                        document[TBE_EDITOR.formname][theField].value=checkboxValue;