08
Oct
08

Multi Time-Zone Fix for Ext.form.DateField

When testing the multi time-zone capabilities of Tine 2.0 I came across an interesting problem with the Ext.form.DateField.

The basic form handling in Extjs in like this.

  1. Render the from (e.g. the contact edit dialog).
  2. Get a Ext.data.Record (e.g. representing a contact).
  3. Update the form with the record data: All form properties having a corresponding property in the record will be set/updated.
  4. The user does his changes in the form (e.g. updating the name).
  5. Update the record from the form values: All record properties having a corresponding property in the form will be updated with the form data.

The last step always copies all the form values into the record, regardless of which properties actually got changes by the user. Normally this is no problem, as the value only changes if the user relay did changes. But the implementation of the DateField has a problem in a multi time-zone environment.

Imagine I myself update my birthday in my contact record. This is 1979/06/05. In fact this means by birthday was from 1979/06/05 00:00:00 to 1979/06/05 23:59:59 in the time-zone Europe/Berlin.

So what Tine 2.0 stores in its database is: 1979/06/04 22:00:00 UTC cause Europe/Berlin is UTC+2 when daylight saving time is active. This means in UTC my birthday was from 1979/06/04 22:00:00 to 1979/06/05 21:59:59.

Unfortunately the Ext.dateField has no clue about time-zones or time-shifts. It just deals with dates, e.g. (Y-m-d).

So when my contact record gets updated from someone living in UTC time-zone, the DateField gets filled with 1979/06/04 22:00:00 (step 3). When user changes something and saves changes (step 4) it just return 1979/06/04 (step 5) even though the user didn’t actually change my birthday.

As result, the Tine 2.0 server sees a change in the birthday property from

1979/06/04 22:00:00 UTC to 1979/06/05 00:00:00 UTC which is obviously wrong, as this is not my correct birthday!

As a quick fix for the Ext.form.DateField we now preserve the time when the user does not change the date field. This is the fix I added to our Ext fixes code. Note, you need to include this after the Extjs library, but before your application code.

  1. /**
  2.  * fix timezone handling for date picker
  3.  *
  4.  * The getValue function always returns 00:00:00 as time. So if a form
  5.  * got filled with a date like 2008-10-01T21:00:00 the form returns
  6.  * 2008-10-01T00:00:00 although the user did not change the fieled.
  7.  *
  8.  * In a multi timezone context this is fatal! When a user in a certain
  9.  * timezone set a date (just a date and no time information), this
  10.  * means in his timezone the time range from 2008-10-01T00:00:00
  11.  * to 2008-10-01T23:59:59. _BUT_ for an other user sitting in a
  12.  * different timezone it means e.g. the time range from
  13.  * 2008-10-01T02:00:00 to 2008-10-02T21:59:59.
  14.  *
  15.  * So on the one hand we need to make shure, that the date picker
  16.  * only returns changed datetime information when the user did a
  17.  * change.
  18.  */
  19.  
  20. /**
  21.  * @private
  22.  */
  23. Ext.form.DateField.prototype.setValue = function(date){
  24.     // preserv original datetime information
  25.     this.fullDateTime = date;
  26.     Ext.form.DateField.superclass.setValue.call(this,
  27.     this.formatDate(this.parseDate(date)));
  28. };
  29.  
  30. /**
  31.  * @private
  32.  */
  33.     Ext.form.DateField.prototype.getValue = function(){
  34.     //var value = this.parseDate(Ext.form.DateField.superclass.getValue.call(this));
  35.  
  36.     // return the value that was set (has time information when unchanged in client)
  37.     // and not just the date part!
  38.     value =  this.fullDateTime;
  39.     return value || "";
  40. };

0 Responses to “Multi Time-Zone Fix for Ext.form.DateField”


  1. No Comments

Leave a Reply