[TYPO3-core] RFC: bug #7897: Datetime saving across DST switches shifts time

Ernesto Baschny [cron IT] ernst at cron-it.de
Tue Apr 8 16:20:23 CEST 2008


REMINDER #2, this is a particular awful bug that should be fixed before 
RC2. So please review or OBJECT, else I will commit it "as is" on 
wednesday...

Steffen Kamper wrote: on 05.04.2008 21:55:
> REMINDER
> 
> as this is imho a critical bug please test this patch, it's a must fix for 
> final and should be in the next RC.
> 
> thx, vg Steffen
> 
> "Ernesto Baschny [cron IT]" <ernst at cron-it.de> schrieb im Newsbeitrag 
> news:mailman.1.1207133843.5049.typo3-team-core at lists.netfielders.de...
>> This is a SVN patch request.
>>
>> Problem:
>> On fields of type "datetime" and "date", if you set a date in future or
>> past that is in a different DST (daylight saving time) condition than
>> your browser currently is (either you are in DST and the date you want
>> to set is not, or the other way around), the stored date (displayed in
>> the List-view) is different from the date displayed in the BE-edit form.
>>
>> It is shifted by 1 hour or by 1 day, e.g if you are in DST and the date
>> you want to set is not in DST.
>>
>>
>> Solution:
>> When storing and handling the time information in javascript and in
>> outputting it we currently normalize the information to UTC-time. The
>> bug was that we were assuming the the offset to UTC is always the same.
>> This is of course wrong: When client switches to DST the offset to UTC
>> either grows or shrinks by 60 minutes. So to calculate the UTC time, we
>> need to get the "offset to UTC" of the date we are trying to store and
>> not use "today" as a base of the calculation.
>>
>> The change has to be done on server side (server converting stored local
>> time to UTC time) and on client side (javascript converting local input
>> date to UTC time). Attached patch does that.
>>
>>
>> Branches: TYPO3_4-2  (critical bug!!)
>>
>>
>> Bugtracker reference:
>> http://bugs.typo3.org/view.php?id=7897
>>
>>
> 
> 
> --------------------------------------------------------------------------------
> 
> 
>> Index: t3lib/class.t3lib_tceforms.php
>> ===================================================================
>> --- t3lib/class.t3lib_tceforms.php (Revision 3513)
>> +++ t3lib/class.t3lib_tceforms.php (Arbeitskopie)
>> @@ -1113,9 +1113,9 @@
>>  $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){
>> + if ((in_array('date',$evalList) || in_array('datetime',$evalList)) && 
>> $PA['itemFormElValue']>0){
>>  // Add server timezone offset to UTC to our stored date
>> - $PA['itemFormElValue'] += date('Z');
>> + $PA['itemFormElValue'] += date('Z', $PA['itemFormElValue']);
>>  }
>>
>>  $PA['fieldChangeFunc'] = 
>> array_merge(array('typo3form.fieldGet'=>'typo3form.fieldGet('.$paramsList.');'), 
>> $PA['fieldChangeFunc']);
>> Index: t3lib/jsfunc.evalfield.js
>> ===================================================================
>> --- t3lib/jsfunc.evalfield.js (Revision 3513)
>> +++ t3lib/jsfunc.evalfield.js (Arbeitskopie)
>> @@ -49,6 +49,7 @@
>>  this.lastYear = this.getYear(today);
>>  this.lastDate = this.getDate(today);
>>  this.lastTime = this.getTimestamp(today);
>> + this.refDate = today;
>>  this.isInString = '';
>>  this.USmode = 0;
>> }
>> @@ -279,7 +280,10 @@
>>  default:
>>  var index = value.indexOf(' ');
>>  if (index!=-1) {
>> - this.lastTime = this.input("date",value.substr(index,value.length)) + 
>> this.input("time",value.substr(0,index));
>> + var dateVal = this.input("date",value.substr(index,value.length));
>> + // set refDate so that evalFunc_input on time will work with correct DST 
>> information
>> + this.refDate = new Date(dateVal*1000);
>> + this.lastTime = dateVal + this.input("time",value.substr(0,index));
>>  }
>>  }
>>  this.lastTime+=add*24*60*60;
>> @@ -401,7 +405,7 @@
>>  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));
>> + var theTime = new Date(this.getYear(this.refDate), 
>> this.refDate.getUTCMonth(), this.refDate.getUTCDate(), hour, min, 
>> ((type=="timesec")?sec:0));
>>
>>  this.lastTime = this.getTimestamp(theTime);
>>  theTime.setTime((this.lastTime - theTime.getTimezoneOffset()*60)*1000);
>> Index: t3lib/class.t3lib_tcemain.php
>> ===================================================================
>> --- t3lib/class.t3lib_tcemain.php (Revision 3513)
>> +++ t3lib/class.t3lib_tcemain.php (Arbeitskopie)
>> @@ -1971,7 +1971,7 @@
>>  case 'datetime':
>>  $value = intval($value);
>>  if ($value>0) {
>> - $value -= date('Z');
>> + $value -= date('Z', $value);
>>  }
>>  break;
>>  case 'double2':
>>
> 
> 


More information about the TYPO3-team-core mailing list