Quellcode durchsuchen

[ZF-4383] Zend_Date:

new feature: locale aware handling of concated date and time strings (f.e. 10.Feb.2009 10:24:00)

 - added DateTime pattern (Zend_Locale_Data)
 - added getDateTime (Zend_Locale_Format)
 - added Zend_Date::DATETIME, ::DATETIME_FULL, ::DATETIME_LONG, ::DATETIME_MEDIUM, ::DATETIME_SHORT to all methods

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@16561 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas vor 16 Jahren
Ursprung
Commit
ce7b60196f

+ 36 - 0
documentation/manual/en/module_specs/Zend_Date-Constants.xml

@@ -671,6 +671,42 @@
                         <entry><emphasis>14:53</emphasis>
                         </entry>
                     </row>
+                    <row>
+                        <entry><emphasis>Zend_Date::DATETIME</emphasis>
+                        </entry>
+                        <entry>Standard date with time (string, localized, default value).</entry>
+                        <entry>2009-02-13T14:53:27+01:00</entry>
+                        <entry><emphasis>13.02.2009 14:53:27</emphasis>
+                        </entry>
+                    </row>
+                    <row>
+                        <entry>Zend_Date::DATETIME_FULL</entry>
+                        <entry>Complete date with time (string, localized, complete)</entry>
+                        <entry>2009-02-13T14:53:27+01:00</entry>
+                        <entry><emphasis>Friday, 13. February 2009 14:53 Uhr CET</emphasis>
+                        </entry>
+                    </row>
+                    <row>
+                        <entry>Zend_Date::DATETIME_LONG</entry>
+                        <entry>Long date with time (string, localized, long)</entry>
+                        <entry>2009-02-13T14:53:27+01:00</entry>
+                        <entry><emphasis>13. February 2009 14:53:27 CET</emphasis>
+                        </entry>
+                    </row>
+                    <row>
+                        <entry>Zend_Date::DATETIME_MEDIUM</entry>
+                        <entry>Normal date (string, localized, normal)</entry>
+                        <entry>2009-02-13T14:53:27+01:00</entry>
+                        <entry><emphasis>13.02.2009 14:53:27</emphasis>
+                        </entry>
+                    </row>
+                    <row>
+                        <entry>Zend_Date::DATETIME_SHORT</entry>
+                        <entry>Abbreviated Date (string, localized, abbreviated)</entry>
+                        <entry>2009-02-13T14:53:27+01:00</entry>
+                        <entry><emphasis>13.02.09 14:53</emphasis>
+                        </entry>
+                    </row>
                 </tbody>
             </tgroup>
         </table>

+ 168 - 4
library/Zend/Date.php

@@ -105,6 +105,11 @@ class Zend_Date extends Zend_Date_DateObject
     const TIME_LONG         = 'TTTT';
     const TIME_MEDIUM       = 'TTT';
     const TIME_SHORT        = 'TT';
+    const DATETIME          = 'K';
+    const DATETIME_FULL     = 'KKKKK';
+    const DATETIME_LONG     = 'KKKK';
+    const DATETIME_MEDIUM   = 'KKK';
+    const DATETIME_SHORT    = 'KK';
     const ATOM              = 'OOO';
     const COOKIE            = 'CCC';
     const RFC_822           = 'R';
@@ -813,6 +818,26 @@ class Zend_Date extends Zend_Date_DateObject
                 return $this->_toToken(Zend_Locale_Data::getContent($locale, 'time', 'short'), $locale);
                 break;
 
+            case self::DATETIME :
+                return $this->_toToken(Zend_Locale_Format::getDateTimeFormat($locale), $locale);
+                break;
+
+            case self::DATETIME_FULL :
+                return $this->_toToken(Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'full')), $locale);
+                break;
+
+            case self::DATETIME_LONG :
+                return $this->_toToken(Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'long')), $locale);
+                break;
+
+            case self::DATETIME_MEDIUM :
+                return $this->_toToken(Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'medium')), $locale);
+                break;
+
+            case self::DATETIME_SHORT :
+                return $this->_toToken(Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'short')), $locale);
+                break;
+
             case self::ATOM :
                 return 'Y\-m\-d\TH\:i\:sP';
                 break;
@@ -2153,8 +2178,13 @@ class Zend_Date extends Zend_Date_DateObject
                         $day   = 1;
                         $year  = 1970;
                     }
-                    return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], 0,       $month, $day, $year, true),
-                                                 $this->mktime($hour,           $minute,           $second, $month, $day, $year, true), false);
+
+                    if (!isset($parsed['second'])) {
+                        $parsed['second'] = 0;
+                    }
+
+                    return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $month, $day, $year, true),
+                                                 $this->mktime($hour,           $minute,           $second,           $month, $day, $year, true), false);
                 } catch (Zend_Locale_Exception $e) {
                     require_once 'Zend/Date/Exception.php';
                     throw new Zend_Date_Exception($e->getMessage(), $date);
@@ -2204,8 +2234,127 @@ class Zend_Date extends Zend_Date_DateObject
                         $day   = 1;
                         $year  = 1970;
                     }
-                    return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], 0,       $month, $day, $year, true),
-                                                 $this->mktime($hour,           $minute,           $second, $month, $day, $year, true), false);
+
+                    if (!isset($parsed['second'])) {
+                        $parsed['second'] = 0;
+                    }
+
+                    return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $month, $day, $year, true),
+                                                 $this->mktime($hour,           $minute,           $second,           $month, $day, $year, true), false);
+                } catch (Zend_Locale_Exception $e) {
+                    require_once 'Zend/Date/Exception.php';
+                    throw new Zend_Date_Exception($e->getMessage(), $date);
+                }
+                break;
+
+            case self::DATETIME:
+                try {
+                    $parsed = Zend_Locale_Format::getDateTime($date, array('locale' => $locale, 'format_type' => 'iso', 'fix_date' => true));
+                    if (($calc == 'set') || ($calc == 'cmp')) {
+                        --$parsed['month'];
+                        --$month;
+                        --$parsed['day'];
+                        --$day;
+                        $parsed['year'] -= 1970;
+                        $year  -= 1970;
+                    }
+                    return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true),
+                                                 $this->mktime($hour,           $minute,           $second,           1 + $month,           1 + $day,           1970 + $year,           true), $hour);
+                } catch (Zend_Locale_Exception $e) {
+                    require_once 'Zend/Date/Exception.php';
+                    throw new Zend_Date_Exception($e->getMessage(), $date);
+                }
+                break;
+
+            case self::DATETIME_FULL:
+                try {
+                    $format = Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'full'));
+                    $parsed = Zend_Locale_Format::getDateTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
+
+                    if (($calc == 'set') || ($calc == 'cmp')) {
+                        --$parsed['month'];
+                        --$month;
+                        --$parsed['day'];
+                        --$day;
+                        $parsed['year'] -= 1970;
+                        $year  -= 1970;
+                    }
+
+                    if (!isset($parsed['second'])) {
+                        $parsed['second'] = 0;
+                    }
+
+                    return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true),
+                                                 $this->mktime($hour,           $minute,           $second,           1 + $month,           1 + $day,           1970 + $year,           true), $hour);
+                } catch (Zend_Locale_Exception $e) {
+                    require_once 'Zend/Date/Exception.php';
+                    throw new Zend_Date_Exception($e->getMessage(), $date);
+                }
+                break;
+
+            case self::DATETIME_LONG:
+                try {
+                    $format = Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'long'));
+                    $parsed = Zend_Locale_Format::getDateTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
+
+                    if (($calc == 'set') || ($calc == 'cmp')){
+                        --$parsed['month'];
+                        --$month;
+                        --$parsed['day'];
+                        --$day;
+                        $parsed['year'] -= 1970;
+                        $year  -= 1970;
+                    }
+                    return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true),
+                                                 $this->mktime($hour,           $minute,           $second,           1 + $month,           1 + $day,           1970 + $year,           true), $hour);
+                } catch (Zend_Locale_Exception $e) {
+                    require_once 'Zend/Date/Exception.php';
+                    throw new Zend_Date_Exception($e->getMessage(), $date);
+                }
+                break;
+
+            case self::DATETIME_MEDIUM:
+                try {
+                    $format = Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'medium'));
+                    $parsed = Zend_Locale_Format::getDateTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
+                    if (($calc == 'set') || ($calc == 'cmp')) {
+                        --$parsed['month'];
+                        --$month;
+                        --$parsed['day'];
+                        --$day;
+                        $parsed['year'] -= 1970;
+                        $year  -= 1970;
+                    }
+                    return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true),
+                                                 $this->mktime($hour,           $minute,           $second,           1 + $month,           1 + $day,           1970 + $year,           true), $hour);
+                } catch (Zend_Locale_Exception $e) {
+                    require_once 'Zend/Date/Exception.php';
+                    throw new Zend_Date_Exception($e->getMessage(), $date);
+                }
+                break;
+
+            case self::DATETIME_SHORT:
+                try {
+                    $format = Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'short'));
+                    $parsed = Zend_Locale_Format::getDateTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
+
+                    $parsed['year'] = self::getFullYear($parsed['year']);
+
+                    if (($calc == 'set') || ($calc == 'cmp')) {
+                        --$parsed['month'];
+                        --$month;
+                        --$parsed['day'];
+                        --$day;
+                        $parsed['year'] -= 1970;
+                        $year  -= 1970;
+                    }
+
+                    if (!isset($parsed['second'])) {
+                        $parsed['second'] = 0;
+                    }
+
+                    return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true),
+                                                 $this->mktime($hour,           $minute,           $second,           1 + $month,           1 + $day,           1970 + $year,           true), $hour);
                 } catch (Zend_Locale_Exception $e) {
                     require_once 'Zend/Date/Exception.php';
                     throw new Zend_Date_Exception($e->getMessage(), $date);
@@ -4544,6 +4693,21 @@ class Zend_Date extends Zend_Date_DateObject
             case self::TIME_SHORT :
                 return Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'short'));
                 break;
+            case self::DATETIME :
+                return Zend_Locale_Data::getContent($locale, 'datetime');
+                break;
+            case self::DATETIME_FULL :
+                return Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'full'));
+                break;
+            case self::DATETIME_LONG :
+                return Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'long'));
+                break;
+            case self::DATETIME_MEDIUM :
+                return Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'medium'));
+                break;
+            case self::DATETIME_SHORT :
+                return Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'short'));
+                break;
             case self::ATOM :
             case self::RFC_3339 :
             case self::W3C :

+ 1 - 1
library/Zend/Date/DateObject.php

@@ -664,7 +664,7 @@ abstract class Zend_Date_DateObject {
 
         // 32bit timestamp
         if (abs($timestamp) <= 0x7FFFFFFF) {
-            return @getdate($timestamp);
+            return @getdate((int) $timestamp);
         }
 
         if (isset(self::$_cache)) {

+ 25 - 5
library/Zend/Locale/Data.php

@@ -519,10 +519,26 @@ class Zend_Locale_Data
                 if (empty($value)) {
                     $value = "gregorian";
                 }
-                $temp  = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/dateTimeFormatLength[@type=\'full\']/dateTimeFormat/pattern', '', 'full');
-                $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/dateTimeFormatLength[@type=\'long\']/dateTimeFormat/pattern', '', 'long');
-                $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/dateTimeFormatLength[@type=\'medium\']/dateTimeFormat/pattern', '', 'medium');
-                $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/dateTimeFormatLength[@type=\'short\']/dateTimeFormat/pattern', '', 'short');
+
+                $timefull = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'full\']/timeFormat/pattern', '', 'full');
+                $timelong = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'long\']/timeFormat/pattern', '', 'long');
+                $timemedi = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'medium\']/timeFormat/pattern', '', 'medi');
+                $timeshor = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'short\']/timeFormat/pattern', '', 'shor');
+
+                $datefull = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'full\']/dateFormat/pattern', '', 'full');
+                $datelong = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'long\']/dateFormat/pattern', '', 'long');
+                $datemedi = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'medium\']/dateFormat/pattern', '', 'medi');
+                $dateshor = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'short\']/dateFormat/pattern', '', 'shor');
+
+                $full = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/dateTimeFormatLength[@type=\'full\']/dateTimeFormat/pattern', '', 'full');
+                $long = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/dateTimeFormatLength[@type=\'long\']/dateTimeFormat/pattern', '', 'long');
+                $medi = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/dateTimeFormatLength[@type=\'medium\']/dateTimeFormat/pattern', '', 'medi');
+                $shor = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/dateTimeFormatLength[@type=\'short\']/dateTimeFormat/pattern', '', 'shor');
+
+                $temp['full']   = str_replace(array('{0}', '{1}'), array($timefull['full'], $datefull['full']), $full['full']);
+                $temp['long']   = str_replace(array('{0}', '{1}'), array($timelong['long'], $datelong['long']), $long['long']);
+                $temp['medium'] = str_replace(array('{0}', '{1}'), array($timemedi['medi'], $datemedi['medi']), $medi['medi']);
+                $temp['short']  = str_replace(array('{0}', '{1}'), array($timeshor['shor'], $dateshor['shor']), $shor['shor']);
                 break;
 
             case 'dateitem':
@@ -1067,7 +1083,11 @@ class Zend_Locale_Data
                     $temp = $value;
                     $value = array("gregorian", $temp);
                 }
-                $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dateTimeFormats/dateTimeFormatLength[@type=\'' . $value[1] . '\']/dateTimeFormat/pattern', '', 'pattern');
+
+                $date     = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dateFormats/dateFormatLength[@type=\'' . $value[1] . '\']/dateFormat/pattern', '', 'pattern');
+                $time     = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/timeFormats/timeFormatLength[@type=\'' . $value[1] . '\']/timeFormat/pattern', '', 'pattern');
+                $datetime = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dateTimeFormats/dateTimeFormatLength[@type=\'' . $value[1] . '\']/dateTimeFormat/pattern', '', 'pattern');
+                $temp = str_replace(array('{0}', '{1}'), array(current($time), current($date)), current($datetime));
                 break;
 
             case 'dateitem':

+ 38 - 0
library/Zend/Locale/Format.php

@@ -1171,4 +1171,42 @@ class Zend_Locale_Format
         }
         return self::_parseDate($time, $options);
     }
+
+    /**
+     * Returns the default datetime format for $locale.
+     *
+     * @param  string|Zend_Locale  $locale  OPTIONAL Locale of $number, possibly in string form (e.g. 'de_AT')
+     * @return string  format
+     */
+    public static function getDateTimeFormat($locale = null)
+    {
+        $format = Zend_Locale_Data::getContent($locale, 'datetime');
+        if (empty($format)) {
+            require_once 'Zend/Locale/Exception.php';
+            throw new Zend_Locale_Exception("failed to receive data from locale $locale");
+        }
+        return $format;
+    }
+
+    /**
+     * Returns an array with 'year', 'month', 'day', 'hour', 'minute', and 'second' elements
+     * extracted from $datetime according to the order described in $format.  For a format of 'd.M.y H:m:s',
+     * and an input of 10.05.1985 11:20:55, getDateTime() would return:
+     * array ('year' => 1985, 'month' => 5, 'day' => 10, 'hour' => 11, 'minute' => 20, 'second' => 55)
+     * The optional $locale parameter may be used to help extract times from strings
+     * containing both a time and a day or month name.
+     *
+     * @param   string  $datetime DateTime string
+     * @param   array   $options  Options: format_type, fix_date, locale, date_format. See {@link setOptions()} for details.
+     * @return  array             Possible array members: day, month, year, hour, minute, second, fixed, format
+     */
+    public static function getDateTime($datetime, array $options = array())
+    {
+        $options = self::_checkOptions($options) + self::$_options;
+        if (empty($options['date_format'])) {
+            $options['format_type'] = 'iso';
+            $options['date_format'] = self::getDateTimeFormat($options['locale']);
+        }
+        return self::_parseDate($datetime, $options);
+    }
 }

+ 131 - 1
tests/Zend/DateTest.php

@@ -528,6 +528,11 @@ class Zend_DateTest extends PHPUnit_Framework_TestCase
         $this->assertFalse(           $date->toValue(Zend_Date::TIME_LONG        ));
         $this->assertFalse(           $date->toValue(Zend_Date::TIME_MEDIUM      ));
         $this->assertFalse(           $date->toValue(Zend_Date::TIME_SHORT       ));
+        $this->assertFalse(           $date->toValue(Zend_Date::DATETIME         ));
+        $this->assertFalse(           $date->toValue(Zend_Date::DATETIME_FULL    ));
+        $this->assertFalse(           $date->toValue(Zend_Date::DATETIME_LONG    ));
+        $this->assertFalse(           $date->toValue(Zend_Date::DATETIME_MEDIUM  ));
+        $this->assertFalse(           $date->toValue(Zend_Date::DATETIME_SHORT   ));
         $this->assertFalse(           $date->toValue(Zend_Date::ATOM             ));
         $this->assertFalse(           $date->toValue(Zend_Date::COOKIE           ));
         $this->assertFalse(           $date->toValue(Zend_Date::RFC_822          ));
@@ -592,6 +597,11 @@ class Zend_DateTest extends PHPUnit_Framework_TestCase
         $this->assertFalse(           $date->toValue(Zend_Date::TIME_LONG        ));
         $this->assertFalse(           $date->toValue(Zend_Date::TIME_MEDIUM      ));
         $this->assertFalse(           $date->toValue(Zend_Date::TIME_SHORT       ));
+        $this->assertFalse(           $date->toValue(Zend_Date::DATETIME         ));
+        $this->assertFalse(           $date->toValue(Zend_Date::DATETIME_FULL    ));
+        $this->assertFalse(           $date->toValue(Zend_Date::DATETIME_LONG    ));
+        $this->assertFalse(           $date->toValue(Zend_Date::DATETIME_MEDIUM  ));
+        $this->assertFalse(           $date->toValue(Zend_Date::DATETIME_SHORT   ));
         $this->assertFalse(           $date->toValue(Zend_Date::ATOM             ));
         $this->assertFalse(           $date->toValue(Zend_Date::COOKIE           ));
         $this->assertFalse(           $date->toValue(Zend_Date::RFC_822          ));
@@ -666,6 +676,11 @@ class Zend_DateTest extends PHPUnit_Framework_TestCase
         $this->assertSame(                   '23:31:30 UTC', $date->get(Zend_Date::TIME_LONG        ));
         $this->assertSame(                       '23:31:30', $date->get(Zend_Date::TIME_MEDIUM      ));
         $this->assertSame(                          '23:31', $date->get(Zend_Date::TIME_SHORT       ));
+        $this->assertSame(            '13.02.2009 23:31:30', $date->get(Zend_Date::DATETIME         ));
+        $this->assertSame('Freitag, 13. Februar 2009 23:31:30 UTC', $date->get(Zend_Date::DATETIME_FULL    ));
+        $this->assertSame(  '13. Februar 2009 23:31:30 UTC', $date->get(Zend_Date::DATETIME_LONG    ));
+        $this->assertSame(            '13.02.2009 23:31:30', $date->get(Zend_Date::DATETIME_MEDIUM  ));
+        $this->assertSame(                 '13.02.09 23:31', $date->get(Zend_Date::DATETIME_SHORT   ));
         $this->assertSame(      '2009-02-13T23:31:30+00:00', $date->get(Zend_Date::ATOM             ));
         $this->assertSame( 'Friday, 13-Feb-09 23:31:30 UTC', $date->get(Zend_Date::COOKIE           ));
         $this->assertSame(  'Fri, 13 Feb 09 23:31:30 +0000', $date->get(Zend_Date::RFC_822          ));
@@ -730,6 +745,11 @@ class Zend_DateTest extends PHPUnit_Framework_TestCase
         $this->assertSame(                   '23:31:30 UTC', $date->get(Zend_Date::TIME_LONG,         'es'));
         $this->assertSame(                       '23:31:30', $date->get(Zend_Date::TIME_MEDIUM,       'es'));
         $this->assertSame(                          '23:31', $date->get(Zend_Date::TIME_SHORT,        'es'));
+        $this->assertSame(            '13/02/2009 23:31:30', $date->get(Zend_Date::DATETIME,          'es'));
+        $this->assertSame('viernes 13 de febrero de 2009 23:31:30 UTC', $date->get(Zend_Date::DATETIME_FULL, 'es'));
+        $this->assertSame('13 de febrero de 2009 23:31:30 UTC', $date->get(Zend_Date::DATETIME_LONG,  'es'));
+        $this->assertSame(            '13/02/2009 23:31:30', $date->get(Zend_Date::DATETIME_MEDIUM,   'es'));
+        $this->assertSame(                 '13/02/09 23:31', $date->get(Zend_Date::DATETIME_SHORT,    'es'));
         $this->assertSame(      '2009-02-13T23:31:30+00:00', $date->get(Zend_Date::ATOM,              'es'));
         $this->assertSame( 'Friday, 13-Feb-09 23:31:30 UTC', $date->get(Zend_Date::COOKIE,            'es'));
         $this->assertSame(  'Fri, 13 Feb 09 23:31:30 +0000', $date->get(Zend_Date::RFC_822,           'es'));
@@ -796,6 +816,11 @@ class Zend_DateTest extends PHPUnit_Framework_TestCase
         $this->assertSame(                                '04:31:30 MVT', $date->get(Zend_Date::TIME_LONG        ));
         $this->assertSame(                                    '04:31:30', $date->get(Zend_Date::TIME_MEDIUM      ));
         $this->assertSame(                                       '04:31', $date->get(Zend_Date::TIME_SHORT       ));
+        $this->assertSame(                         '14.02.2009 04:31:30', $date->get(Zend_Date::DATETIME         ));
+        $this->assertSame('Samstag, 14. Februar 2009 04:31:30 Indian/Maldives', $date->get(Zend_Date::DATETIME_FULL    ));
+        $this->assertSame(               '14. Februar 2009 04:31:30 MVT', $date->get(Zend_Date::DATETIME_LONG    ));
+        $this->assertSame(                         '14.02.2009 04:31:30', $date->get(Zend_Date::DATETIME_MEDIUM  ));
+        $this->assertSame(                              '14.02.09 04:31', $date->get(Zend_Date::DATETIME_SHORT   ));
         $this->assertSame(                   '2009-02-14T04:31:30+05:00', $date->get(Zend_Date::ATOM             ));
         $this->assertSame('Saturday, 14-Feb-09 04:31:30 Indian/Maldives', $date->get(Zend_Date::COOKIE           ));
         $this->assertSame(               'Sat, 14 Feb 09 04:31:30 +0500', $date->get(Zend_Date::RFC_822          ));
@@ -2113,7 +2138,7 @@ class Zend_DateTest extends PHPUnit_Framework_TestCase
             // success
         }
         $date->set($d2, Zend_Date::TIME_FULL);
-        $this->assertSame('2009-02-14T04:36:00+05:00', $date->get(Zend_Date::W3C));
+        $this->assertSame('2009-02-14T04:36:50+05:00', $date->get(Zend_Date::W3C));
         $date->set(1234567890);
         $date->set('15:26 Uhr CET', Zend_Date::TIME_FULL);
         $this->assertSame('2009-02-14T15:26:00+05:00', $date->get(Zend_Date::W3C));
@@ -2160,6 +2185,71 @@ class Zend_DateTest extends PHPUnit_Framework_TestCase
 
         $date->set(1234567890);
         try {
+            $date->set('noday', Zend_Date::DATETIME);
+            $this->fail();
+        } catch (Zend_Date_Exception $e) {
+            // success
+        }
+        $date->set($d2, Zend_Date::DATETIME);
+        $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Zend_Date::W3C));
+        $date->set(1234567890);
+        $date->set('14.02.2009 15:26:03', Zend_Date::DATETIME);
+        $this->assertSame('2009-02-14T15:26:03+05:00', $date->get(Zend_Date::W3C));
+
+        $date->set(1234567890);
+        try {
+            $date->set('noday', Zend_Date::DATETIME_FULL);
+            $this->fail();
+        } catch (Zend_Date_Exception $e) {
+            // success
+        }
+        $date->set($d2, Zend_Date::DATETIME_FULL);
+        $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Zend_Date::W3C));
+        $date->set(1234567890);
+        $date->set('Samstag, 14. Februar 2009 15:26 Uhr CET', Zend_Date::DATETIME_FULL);
+        $this->assertSame('2009-02-14T15:26:00+05:00', $date->get(Zend_Date::W3C));
+
+        $date->set(1234567890);
+        try {
+            $date->set('noday', Zend_Date::DATETIME_LONG);
+            $this->fail();
+        } catch (Zend_Date_Exception $e) {
+            // success
+        }
+        $date->set($d2, Zend_Date::DATETIME_LONG);
+        $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Zend_Date::W3C));
+        $date->set(1234567890);
+        $date->set('14. Februar 2009 15:26:03 CET', Zend_Date::DATETIME_LONG);
+        $this->assertSame('2009-02-14T15:26:03+05:00', $date->get(Zend_Date::W3C));
+
+        $date->set(1234567890);
+        try {
+            $date->set('noday', Zend_Date::DATETIME_MEDIUM);
+            $this->fail();
+        } catch (Zend_Date_Exception $e) {
+            // success
+        }
+        $date->set($d2, Zend_Date::DATETIME_MEDIUM);
+        $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Zend_Date::W3C));
+        $date->set(1234567890);
+        $date->set('14.02.2009 15:26:31', Zend_Date::DATETIME_MEDIUM);
+        $this->assertSame('2009-02-14T15:26:31+05:00', $date->get(Zend_Date::W3C));
+
+        $date->set(1234567890);
+        try {
+            $date->set('noday', Zend_Date::DATETIME_SHORT);
+            $this->fail();
+        } catch (Zend_Date_Exception $e) {
+            // success
+        }
+        $date->set($d2, Zend_Date::DATETIME_SHORT);
+        $this->assertSame('2002-01-04T04:36:00+05:00', $date->get(Zend_Date::W3C));
+        $date->set(1234567890);
+        $date->set('14.02.09 15:26', Zend_Date::DATETIME_SHORT);
+        $this->assertSame('2009-02-14T15:26:00+05:00', $date->get(Zend_Date::W3C));
+
+        $date->set(1234567890);
+        try {
             $date->set('noday', Zend_Date::ATOM);
             $this->fail();
         } catch (Zend_Date_Exception $e) {
@@ -2638,6 +2728,26 @@ class Zend_DateTest extends PHPUnit_Framework_TestCase
         $this->assertSame('2002-01-04T14:41:50+05:00', $date->get(Zend_Date::W3C));
 
         $date->set($d2);
+        $date->add('10.02.0005 10:05:05', Zend_Date::DATETIME);
+        $this->assertSame('2007-03-14T14:41:55+05:00', $date->get(Zend_Date::W3C));
+
+        $date->set($d2);
+        $date->add('Samstag, 10. Februar 0005 10:05 Uhr CET', Zend_Date::DATETIME_FULL);
+        $this->assertSame('2007-03-14T14:41:50+05:00', $date->get(Zend_Date::W3C));
+
+        $date->set($d2);
+        $date->add('10. Februar 0005 10:05:05 CET', Zend_Date::DATETIME_LONG);
+        $this->assertSame('2007-03-14T14:41:55+05:00', $date->get(Zend_Date::W3C));
+
+        $date->set($d2);
+        $date->add('10.02.0005 10:05:05', Zend_Date::DATETIME_MEDIUM);
+        $this->assertSame('2007-03-14T14:41:55+05:00', $date->get(Zend_Date::W3C));
+
+        $date->set($d2);
+        $date->add('10.02.05 10:05', Zend_Date::DATETIME_SHORT);
+        $this->assertSame('4007-03-14T14:41:50+05:00', $date->get(Zend_Date::W3C));
+
+        $date->set($d2);
         $date->add('1000-01-02T20:05:12+05:00', Zend_Date::ATOM);
         $this->assertSame('3002-02-08T00:42:02+05:00', $date->get(Zend_Date::W3C));
 
@@ -3016,6 +3126,26 @@ class Zend_DateTest extends PHPUnit_Framework_TestCase
         $this->assertSame('2002-01-03T18:31:50+05:00', $date->get(Zend_Date::W3C));
 
         $date->set($d2);
+        $date->sub('10.02.0005 10:05:05', Zend_Date::DATETIME);
+        $this->assertSame('1996-10-26T18:31:45+05:00', $date->get(Zend_Date::W3C));
+
+        $date->set($d2);
+        $date->sub('Samstag, 10. Februar 0005 10:05 Uhr CET', Zend_Date::DATETIME_FULL);
+        $this->assertSame('1996-10-26T18:31:50+05:00', $date->get(Zend_Date::W3C));
+
+        $date->set($d2);
+        $date->sub('10. Februar 0005 10:05:05 CET', Zend_Date::DATETIME_LONG);
+        $this->assertSame('1996-10-26T18:31:45+05:00', $date->get(Zend_Date::W3C));
+
+        $date->set($d2);
+        $date->sub('10.02.0005 10:05:05', Zend_Date::DATETIME_MEDIUM);
+        $this->assertSame('1996-10-26T18:31:45+05:00', $date->get(Zend_Date::W3C));
+
+        $date->set($d2);
+        $date->sub('10.02.05 10:05', Zend_Date::DATETIME_SHORT);
+        $this->assertSame('-4-10-28T18:31:50+05:00', $date->get(Zend_Date::W3C));
+
+        $date->set($d2);
         $date->sub('1000-01-02T20:05:12+05:00', Zend_Date::ATOM);
         $this->assertSame('1001-11-25T08:31:38+05:00', $date->get(Zend_Date::W3C));
 

+ 10 - 10
tests/Zend/Locale/DataTest.php

@@ -657,27 +657,27 @@ class Zend_Locale_DataTest extends PHPUnit_Framework_TestCase
     {
         $value = Zend_Locale_Data::getList('de_AT', 'datetime');
         $result = array(
-            'full' => '{1} {0}',
-            'long' => '{1} {0}',
-            'medium' => '{1} {0}',
-            'short' => '{1} {0}'
+            'full' => 'EEEE, dd. MMMM y HH:mm:ss zzzz',
+            'long' => 'dd. MMMM y HH:mm:ss z',
+            'medium' => 'dd.MM.yyyy HH:mm:ss',
+            'short' => 'dd.MM.yy HH:mm'
         );
         $this->assertEquals($result, $value);
 
         $value = Zend_Locale_Data::getList('de_AT', 'datetime', 'gregorian');
         $result = array(
-            'full' => '{1} {0}',
-            'long' => '{1} {0}',
-            'medium' => '{1} {0}',
-            'short' => '{1} {0}'
+            'full' => 'EEEE, dd. MMMM y HH:mm:ss zzzz',
+            'long' => 'dd. MMMM y HH:mm:ss z',
+            'medium' => 'dd.MM.yyyy HH:mm:ss',
+            'short' => 'dd.MM.yy HH:mm'
         );
         $this->assertEquals($result, $value);
 
         $value = Zend_Locale_Data::getContent('de_AT', 'datetime', 'full');
-        $this->assertEquals("{1} {0}", $value);
+        $this->assertEquals("EEEE, dd. MMMM y HH:mm:ss zzzz", $value);
 
         $value = Zend_Locale_Data::getContent('de_AT', 'datetime', array('gregorian', 'long'));
-        $this->assertEquals("{1} {0}", $value);
+        $this->assertEquals("dd. MMMM y HH:mm:ss z", $value);
     }
 
     /**

+ 60 - 2
tests/Zend/Locale/FormatTest.php

@@ -581,7 +581,6 @@ class Zend_Locale_FormatTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(2007, $value['year'] );
     }
 
-
     /**
      * test getTime
      * expected array
@@ -634,7 +633,6 @@ class Zend_Locale_FormatTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(55, $value['second']);
     }
 
-
     /**
      * test isDate
      * expected boolean
@@ -960,4 +958,64 @@ class Zend_Locale_FormatTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(9.72,   Zend_Locale_Format::getFloat(9.72));
         $this->assertEquals('14,23',   Zend_Locale_Format::toNumber(14.2278, array('precision' => 2, 'locale' => 'pt_PT')));
     }
+
+    /**
+     * Tests getDateTime
+     */
+    public function testgetDateTime()
+    {
+        try {
+            $value = Zend_Locale_Format::getDateTime('no content');
+            $this->fail("exception expected");
+        } catch (Zend_Locale_Exception $e) {
+            // success
+        }
+
+        $this->assertTrue(is_array(Zend_Locale_Format::getDateTime('10.11.2006 13:14:55', array('date_format' => 'dd.MM.yyyy HH:mm:ss'))));
+        $options = array('date_format' => 'dd.MM.yy h:mm:ss a', 'locale' => 'en');
+        $this->assertTrue(is_array(Zend_Locale_Format::getDateTime('15.10.09 11:14:55 am', $options)));
+        $this->assertTrue(is_array(Zend_Locale_Format::getDateTime('15.10.09 12:14:55 am', $options)));
+        $this->assertTrue(is_array(Zend_Locale_Format::getDateTime('15.10.09 11:14:55 pm', $options)));
+        $this->assertTrue(is_array(Zend_Locale_Format::getDateTime('15.10.09 12:14:55 pm', $options)));
+
+        try {
+            $value = Zend_Locale_Format::getDateTime('15.10.09 13:14:55', array('date_format' => 'nocontent'));
+            $this->fail("exception expected");
+        } catch (Zend_Locale_Exception $e) {
+            // success
+        }
+
+        try {
+            $value = Zend_Locale_Format::getDateTime('15.10.09 13:14:55', array('date_format' => 'ZZZZ'));
+            $this->fail("exception expected");
+        } catch (Zend_Locale_Exception $e) {
+            // success
+        }
+
+        $value = Zend_Locale_Format::getDateTime('15.10.09 13:14:55', array('date_format' => 'dd.MM.yy HH:mm:ss.x'));
+        $this->assertEquals(15, $value['day']  );
+        $this->assertEquals(10, $value['month']);
+        $this->assertEquals(2009, $value['year']);
+        $this->assertEquals(13, $value['hour']  );
+        $this->assertEquals(14, $value['minute']);
+        $this->assertEquals(55, $value['second']);
+
+        $this->assertEquals(8, count(Zend_Locale_Format::getDateTime('15.10.09 13:14:55', array('date_format' => 'dd.MM.yy HH:mm:ss'))));
+
+        $value = Zend_Locale_Format::getDateTime('15.10.09 13:14:55', array('date_format' => 'dd.MM.yy HH:mm:ss'));
+        $this->assertEquals(15, $value['day']  );
+        $this->assertEquals(10, $value['month']);
+        $this->assertEquals(2009, $value['year']);
+        $this->assertEquals(13, $value['hour']  );
+        $this->assertEquals(14, $value['minute']);
+        $this->assertEquals(55, $value['second']);
+
+        $value = Zend_Locale_Format::getDateTime('151009131455', array('date_format' => 'dd.MM.yy HH:mm:ss'));
+        $this->assertEquals(15, $value['day']  );
+        $this->assertEquals(10, $value['month']);
+        $this->assertEquals(2009, $value['year']);
+        $this->assertEquals(13, $value['hour']  );
+        $this->assertEquals(14, $value['minute']);
+        $this->assertEquals(55, $value['second']);
+    }
 }