Esempio n. 1
0
 public function getDate($key, $timeZone = 'GMT')
 {
     $converter = new DataConverter($timeZone);
     $pattern = 'yyyy-MM-dd HH:mm:ss';
     if (strpos($this->map[$key], " ") === false) {
         $pattern = 'yyyy-MM-dd';
     }
     return $converter->parseDate($this->map[$key], $pattern);
 }
Esempio n. 2
0
 /**
  * Get a date (unix timestamp) from the given map.
  *
  * Currently, parses the value associated with the key.
  * Parses the date using the IntlDateFormatter SHORT format, which accepts
  * year as either 2 or 4 digits.
  *
  * TODO: The map should contain 2 fields:
  * - $key : keeps the formatted date
  * - $key__time: keeps the formatted time
  *
  * @param $map
  * @param $key
  * @return unix timestamp
  */
 public function getDate($map, $key)
 {
     $value = $this->getValue($map, $key);
     if (!isset($value) || $value === "" || $value === false) {
         return null;
     }
     $dataConverter = new DataConverter($this->timezoneName, $this->locale);
     return $dataConverter->parseDate($value);
 }
 /**
  * @covers DataConverter::parseDate
  * @covers DataConverter::parseDateByPattern
  */
 public function testParseDateEmpty()
 {
     $actual = $this->converter->parseDate("", "yyyy.MM.dd");
     $this->assertNull($actual);
 }
Esempio n. 4
0
 /**
  * Get the date value associated with the given key.
  *
  * @param String $key the key
  * @param timestamp $defaultValue value to return in case the key doesn't exist in the request.
  * @param String $timezone If not passed, the user timezone will be used.
  * @return timestamp Unix timestamp - the number of seconds since January 1 1970 00:00:00 GMT
  */
 public function getDate($key, $defaultValue = self::UNDEFINED, $timezone = null)
 {
     try {
         $str = $this->getString($key);
         $converter = DataConverter::getInstance();
         if ($timezone && $converter->getTimeZoneName() != $timezone) {
             $converter = new DataConverter($timezone);
         }
         return $converter->parseDate($str);
     } catch (UndefinedKeyException $e) {
         if ($defaultValue != self::UNDEFINED) {
             return $defaultValue;
         }
         throw $e;
     }
 }