Horde_ActiveSync_Device::normalizePoomContactsDates PHP Méthode

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.
    public function normalizePoomContactsDates($date, $toEas = false)
    {
        switch (Horde_String::lower($this->clientType)) {
            case self::TYPE_WP:
            case 'wp8':
                // Legacy. Remove in H6.
            // Legacy. Remove in H6.
            case 'wp':
                // Legacy. Remove in H6.
                if ($toEas) {
                    return new Horde_Date($date->format('Y-m-d'), 'UTC');
                } else {
                    $date = new Horde_Date($date->format('Y-m-d'));
                    return $date->setTimezone('UTC');
                }
            case self::TYPE_ANDROID:
                // Need to protect against clients that don't send the actual Android
                // version in the OS field.
                if (stripos($this->deviceType, 'samsung') === 0) {
                    // Samsung's native Contacts app works differently than stock
                    // Android, always sending as 00:00:00
                    if ($toEas) {
                        return new Horde_Date($date->format('Y-m-d'), 'UTC');
                    }
                    $date = new Horde_Date($date->format('Y-m-d'));
                    return $date->setTimezone('UTC');
                }
                if ($this->getMajorVersion() >= 4 && $this->getMajorVersion() <= 10) {
                    if ($toEas) {
                        return new Horde_Date($date->format('Y-m-d 08:00:00'), 'UTC');
                    } else {
                        $date = new Horde_Date($date->format('Y-m-d'));
                        return $date->setTimezone('UTC');
                    }
                } else {
                    // POOMCONTACTS:BIRTHDAY not really supported in early Android
                    // versions. Return as is.
                    return $date;
                }
            case self::TYPE_IPAD:
            case self::TYPE_IPHONE:
            case self::TYPE_IPOD:
                if ($this->getMajorVersion() >= 5) {
                    // iOS >= 5 handles it correctly more or less.
                    if ($toEas) {
                        return new Horde_Date($date->format('Y-m-d 00:00:00'));
                    } else {
                        return $date;
                    }
                } else {
                    if ($toEas) {
                        return new Horde_Date($date->format('Y-m-d'), 'UTC');
                    } else {
                        return new Horde_Date($date->format('Y-m-d'));
                    }
                }
            case self::TYPE_NINE:
                if ($toEas) {
                    return new Horde_Date($date->format('Y-m-d 00:00:00'), 'UTC');
                } else {
                    return $date;
                }
            case self::TYPE_BLACKBERRY:
                if ($toEas) {
                    return new Horde_Date($date->format('Y-m-d 11:00:00'), 'UTC');
                } else {
                    $date = new Horde_Date($date->format('Y-m-d'));
                    return $date->setTimezone('UTC');
                }
            case self::TYPE_TOUCHDOWN:
            case self::TYPE_UNKNOWN:
            default:
                return $date;
        }
    }

Usage Example

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);
 }
All Usage Examples Of Horde_ActiveSync_Device::normalizePoomContactsDates