normalizePoomContactsDates() public méthode

WP: Devices seem to send the birthdays at the entered date, with a time of 00:00:00 UTC during standard time and with 01:00:00 UTC during DST if the client's configured timezone observes it. No idea what purpose this serves since no timezone data is transmitted for birthday values. iOS: Seems different based on version. iOS 5+, at least seems to send the birthday as midnight at the entered date in the device's timezone then converted to UTC. Some minor issues with offsets being off an hour or two for some timezones though. iOS < 5 sends the birthday time part as the time the birthday was entered/edited on the device, converted to UTC, so it can't be trusted at all. The best we can do here is transform the date to midnight on date_default_timezone() converted to UTC. Android: For contacts originating on the SERVER, the following is true: Stock 4.3 Takes the down-synched bday value which is assumed to be UTC, does some magic to it (converts to milliseconds, creates a gregorian calendar object, then converts to YYYY-MM-DD). When sending the bday value up, it sends it up as-is. No conversion to/from UTC or local is done. Stock 4.4.x does the above, but before sending the bday value, validates that it's in a correct format for sending to the server. This really only affects date data originally entered on the device for non-stock android clients. There is some strange bit of code in Android that adds 1 to the DAY_OF_MONTH when HOUR_OF_DAY >= 12 in an attempt to "fix" birthday handling for GMT+n users. See: https://android.googlesource.com/platform/packages/apps/Exchange/+/32daacdd71b9de8fd5e3f59c37934e3e4a9fa972%5E!/exchange2/src/com/android/exchange/adapter/ContactsSyncAdapter.java Not sure what to make of it, or why it's not just converted to local tz when displaying but this probably breaks birthday handling for people in a few timezones. For contacts originating on the CLIENT, the datetime is sent as 08:00:00 UTC, and this seems to be regardless of the timezone set in the Android system. Given all of this, it makes sense to me to ALWAYS send birthday data as occuring at 08:00:00 UTC for *native* Android clients. BB 10+ expects it at 11:00:00 UTC
public normalizePoomContactsDates ( Horde_Date $date, boolean $toEas = false ) : Horde_Date
$date Horde_Date The date. This should normally be in the local timezone if encoding the date for the client. If decoding the date from the client, it will normally be in UTC.
$toEas boolean Convert from local to device if true. DEFAULT: false
Résultat Horde_Date The date of the birthday/anniversary, with any fixes applied for the current device. The timezone set in the object will depend on the client detected, and whether the date is being encoding or decoding.
Exemple #1
0
 public function testPoomContactsDate()
 {
     $tz = date_default_timezone_get();
     date_default_timezone_set('America/New_York');
     $state = $this->getMockSkipConstructor('Horde_ActiveSync_State_Base');
     // WindowsPhone.
     $fixture = array('deviceType' => 'windowsphone');
     $device = new Horde_ActiveSync_Device($state, $fixture);
     $date = new Horde_Date('2003-09-24', 'UTC');
     $bday = $device->normalizePoomContactsDates($date);
     $this->assertEquals('2003-09-24 00:00:00', (string) $bday);
     $this->assertEquals('America/New_York', $bday->timezone);
     // Android
     date_default_timezone_set('Pacific/Honolulu');
     $fixture = array('deviceType' => 'android', 'userAgent' => 'Android/4.3.1-EAS-1.3');
     $device = new Horde_ActiveSync_Device($state, $fixture);
     $date = new Horde_Date('2003-09-24 08:00:00', 'UTC');
     $bday = $device->normalizePoomContactsDates($date);
     $this->assertEquals('2003-09-24 00:00:00', (string) $bday);
     $this->assertEquals('Pacific/Honolulu', $bday->timezone);
     date_default_timezone_set($tz);
 }
Exemple #2
0
 public function testPoomContactsDate()
 {
     $tz = date_default_timezone_get();
     date_default_timezone_set('America/New_York');
     $state = $this->getMockSkipConstructor('Horde_ActiveSync_State_Base');
     // WindowsPhone.
     $fixture = array('deviceType' => 'windowsphone');
     $device = new Horde_ActiveSync_Device($state, $fixture);
     $date = new Horde_Date('2003-09-24', 'UTC');
     $bday = $device->normalizePoomContactsDates($date);
     $this->assertEquals('2003-09-24', $bday->setTimezone('America/New_York')->format('Y-m-d'));
     // iOS (Sends as 00:00:00 localtime converted to UTC).
     $fixture = array('deviceType' => 'iPhone', 'userAgent' => 'Apple-iPhone4C1/1002.329', 'properties' => array(Horde_ActiveSync_Device::OS => 'iOS 6.1.3 10B329'));
     $device = new Horde_ActiveSync_Device($state, $fixture);
     $date = new Horde_Date('1970-03-20');
     $bday = $device->normalizePoomContactsDates($date, true);
     $this->assertEquals('1970-03-20 00:00:00', (string) $bday);
     $date = new Horde_Date('1970-03-20T05:00:00.000Z');
     $bday = $device->normalizePoomContactsDates($date);
     $this->assertEquals('1970-03-20 00:00:00', (string) $bday->setTimezone('America/New_York'));
     // Try a positive UTC offset timezone
     date_default_timezone_set('Europe/Berlin');
     $fixture = array('deviceType' => 'iPhone', 'userAgent' => 'Apple-iPhone4C1/1104.201', 'properties' => array(Horde_ActiveSync_Device::OS => 'iOS 7.1.1 11D201'));
     $device = new Horde_ActiveSync_Device($state, $fixture);
     $date = new Horde_Date('1966-07-22T23:00:00.000Z');
     $bday = $device->normalizePoomContactsDates($date);
     $bday->setTimezone(date_default_timezone_get());
     $this->assertEquals('1966-07-23', $bday->format('Y-m-d'));
     // Android
     date_default_timezone_set('Pacific/Honolulu');
     $fixture = array('deviceType' => 'android', 'userAgent' => 'Android/4.3.1-EAS-1.3');
     $device = new Horde_ActiveSync_Device($state, $fixture);
     $date = new Horde_Date('2003-09-24 08:00:00', 'UTC');
     $bday = $device->normalizePoomContactsDates($date);
     $this->assertEquals('2003-09-24', $bday->setTimezone('Pacific/Honolulu')->format('Y-m-d'));
     // Note 3
     date_default_timezone_set('America/Chicago');
     $fixture = array('deviceType' => 'SAMSUNGSMN900V', 'userAgent' => 'SAMSUNG-SM-N900V/101.403', 'properties' => array(Horde_ActiveSync_Device::OS => 'Android'));
     $device = new Horde_ActiveSync_Device($state, $fixture);
     $date = new Horde_Date('1970-03-20');
     $bday = $device->normalizePoomContactsDates($date, true);
     $this->assertEquals('1970-03-20 00:00:00', (string) $bday);
     $fixture = array('deviceType' => 'Android', 'userAgent' => 'hltevzw/KOT49H', 'properties' => array(Horde_ActiveSync_Device::OS => 'Android 4.4.2.N900VVRUCNC4'));
     $device = new Horde_ActiveSync_Device($state, $fixture);
     $device->id = '6E696E656331393035333833303331';
     $date = new Horde_Date('1970-03-20');
     $bday = $device->normalizePoomContactsDates($date, true);
     $this->assertEquals('1970-03-20 00:00:00', (string) $bday);
     date_default_timezone_set($tz);
 }