public function __construct($time = 'now', \DateTimeZone $timezone = null) { if ($time == 'now') { $time = self::$now; } parent::__construct($time, $timezone); }
/** * @param string $time * @param null $timezone */ public function __construct($time = 'now', $timezone = null) { if ($time instanceof \MongoDate) { parent::__construct(date('Y-m-d H:i:s', $time->sec), null); return; } if ($time instanceof \DateTime) { parent::__construct($time->format(self::DATE_FULL), $time->getTimezone()); return; } if (is_integer($time)) { parent::__construct(date('Y-m-d H:i:s', $time), null); return; } if (empty($time)) { $time = 'now'; } if ($timezone) { if (!$timezone instanceof \DateTimeZone) { $timezone = new \DateTimeZone($timezone); } parent::__construct($time, $timezone); } else { parent::__construct($time); } }
/** */ public function __construct($time = null) { $tz = new DateTimeZone('UTC'); try { parent::__construct($time, $tz); return; } catch (Exception $e) { } /* Bug #5717 - Check for UT vs. UTC. */ if (substr(rtrim($time), -3) === ' UT') { try { parent::__construct($time . 'C', $tz); return; } catch (Exception $e) { } } /* Bug #9847 - Catch paranthesized timezone information at end of date * string. */ $date = preg_replace("/\\s*\\([^\\)]+\\)\\s*\$/", '', $time, -1, $i); if ($i) { try { parent::__construct($date, $tz); return; } catch (Exception $e) { } } parent::__construct('@-1', $tz); }
public function __construct($dateValue = '', DateTimeZone $timezone = null) { if ($dateValue instanceof \DateTime) { $formattedDate = $dateValue->format("Y-m-d H:i:s"); if ($formattedDate == "" || $formattedDate == self::INVALID_DATE) { parent::__construct(self::INVALID_DATE, $timezone); } else { parent::__construct("now"); $this->setTimezone($dateValue->getTimezone()); $this->setDate($dateValue->format("Y"), $dateValue->format("m"), $dateValue->format("d")); $this->setTime($dateValue->format("H"), $dateValue->format("i"), $dateValue->format("s")); if ($timezone !== null) { $this->setTimezone($timezone); } } } elseif (is_numeric($dateValue)) { parent::__construct("now", $timezone); $this->setTimestamp($dateValue); } else { if ($dateValue == "" || $dateValue == "0000-00-00 00:00:00" || $dateValue == "0000-00-00") { parent::__construct(self::INVALID_DATE, $timezone); return; } try { parent::__construct($dateValue, $timezone); } catch (\Exception $er) { parent::__construct(self::INVALID_DATE, $timezone); return; } } }
/** * class constructor * * @param stdClass $p_params * @return OdaDate $this */ public function __construct($p_params = NULL) { $params_attempt = new \stdClass(); $params_attempt->strDate = NULL; $params_attempt->format = NULL; $params_attempt->debug = false; try { $params = (object) array_merge((array) $params_attempt, (array) $p_params); $this->_params = $params; if (is_null($params->strDate)) { parent::__construct(); } else { if (is_null($params->format)) { parent::__construct($params->strDate); } else { $date = \DateTime::createFromFormat($params->format, $params->strDate); parent::__construct($date->format($params->format)); } } $this->_year = $this->getNumYear(); $this->_month = $this->getNumMonth(); $this->_day = $this->getNumDay(); $this->_hour = $this->getHour(); $this->_minute = $this->getMinute(); $this->_seconde = $this->getSeconde(); $this->_microseconds = $this->getMicroseconds(); return $this; } catch (OdaException $e) { die($e); } catch (\Exception $e) { die($e); } }
public function __construct($time = 'now', DateTimeZone $timezone = null) { parent::__construct($time, $timezone); if ($time === 'now') { $this->microTime = microtime(); } }
public function __construct($date = null, DateTimeZone $dtz = null) { if ($dtz === null) { $dtz = new DateTimeZone(date_default_timezone_get()); } parent::__construct($date, $dtz); }
/** * Accepts a DateTime object or; * Adds the ability to pass in an array or object with key names of variable * length but a minimum of 3 characters, upper or lower case. * See setTime and setDate for more information. * * @param object|array|string $time -OPTIONAL * @param DateTimeZone $timezone -OPTIONAL */ public function __construct($time = 'now', $timezone = null) { if (!is_a($timezone, 'DateTimeZone')) { $timezone = new DateTimeZone(date_default_timezone_get()); } switch (gettype($time)) { case 'object': if (is_a($time, 'DateTime')) { parent::__construct($time->format(self::STRING_IO_FORMAT), $time->getTimezone()); break; } $time = (array) $time; case 'array': parent::__construct('now', $timezone); $this->setDate($time); $this->setTime($time); break; case 'string': if ($time === '') { $time = 'now'; } // remove AD extra data if (substr($time, -3) === '.0Z') { $time = substr($time, 0, 14); } parent::__construct($time, $timezone); break; case 'null': case 'NULL': parent::__construct('now', $timezone); break; default: throw new \InvalidArgumentException('first argument is the wrong type: ' . gettype($time)); } }
/** * Initialize instance * * @param string $time * @param string $object */ public function __construct($time = null, $object = null) { if ($time instanceof \DateTime) { $time = $time->getTimestamp(); } parent::__construct($time, $object); }
public function __construct($time = 'now', \DateTimeZone $timezone = null) { if ((string) (int) $time === (string) $time) { $time = '@' . $time; } return parent::__construct($time, $timezone); }
/** * @param string $time * @param \DateTimeZone $timezone * @throws Exception */ public function __construct($time = 'now', \DateTimeZone $timezone = null) { if (is_numeric($time)) { throw new Exception('Invalid date format provided for DateTime: missing `@` prefix.'); } return parent::__construct($time, $timezone); }
public function __construct($time = 'now', DateTimeZone $timezone = null, $default_format = null) { if (!is_null($default_format)) { $this->default_format = $default_format; } parent::__construct($time, $timezone); }
/** * Constructor. * * @param string $date String in a format accepted by strtotime(), defaults to "now". * @param mixed $tz Time zone to be used for the date. Might be a string or a DateTimeZone object. */ public function __construct($date = 'now', $tz = null) { // Create the base GMT and server time zone objects. if (empty(self::$gmt) || empty(self::$stz)) { self::$gmt = new \DateTimeZone('GMT'); self::$stz = new \DateTimeZone(@date_default_timezone_get()); } // If the time zone object is not set, attempt to build it. if (!$tz instanceof \DateTimeZone) { if ($tz === null) { $tz = self::$gmt; } elseif (is_string($tz)) { $tz = new \DateTimeZone($tz); } } // If the date is numeric assume a unix timestamp and convert it. date_default_timezone_set('UTC'); $date = is_numeric($date) ? date('c', $date) : $date; // Call the DateTime constructor. parent::__construct($date, $tz); // Reset the timezone for 3rd party libraries/extension that does not use JDate date_default_timezone_set(self::$stz->getName()); // Set the timezone object for access later. $this->tz = $tz; }
public function __construct($time = 'now', DateTimeZone $timezone = null) { if ($timezone == null) { $timezone = new DateTimeZone(Config::get('intl.timezone')); } parent::__construct($time, $timezone); }
/** * ISO 8601 supported. Complete date plus hours, minutes and seconds: * <code> * YYYY-MM-DDThh:mm:ssTZD (eg. 1997-07-16T19:20:30+01:00) * </code> * * Where: * <code> * YYYY = four-digit year * MM = two-digit month (01 = January, etc.) * DD = two-digit day of month (01 through 31) * hh = two digits of hour (00 through 23) (am/pm not allowed) * mm = two digits of minute (00 through 59) * ss = two digits of second (00 through 59) * TZD = time zone designator (Z or +hh:mm or -hh:mm) * </code> * * * @see http://www.w3.org/TR/NOTE-datetime * @see \Clock\DateTime::toIsoString() * * @throws \InvalidArgumentException When date and time format is wrong. * * @param null|string|\DateTime $dt * @param null|\DateTimeZone $tz */ public function __construct($dt = null, \DateTimeZone $tz = null) { if (!is_null($dt)) { if ($dt instanceof \DateTime) { $tz = $dt->getTimezone(); $dt = $dt->format(static::ATOM); } elseif (is_string($dt)) { $dt = $this->normalizeDateTimeString($dt); } elseif (is_int($dt)) { // Timestamp. $dt = '@' . $dt; } elseif (is_float($dt)) { $this->setMillisecond($this->getMillisecondsFromTimestamp($dt)); $dt = '@' . floor($dt); } else { throw new \InvalidArgumentException('Wrong argument type.'); } } try { parent::__construct($dt, $tz); if (is_null($dt)) { $this->setMillisecond($this->getMillisecondsFromTimestamp(microtime(true))); } } catch (\Exception $exception) { throw new \InvalidArgumentException('Wrong date and time format.', 0, $exception); } }
/** * CONSTRUCTOR * Build a new DateTime object * * @since 0.0.1 * * @access public * @param string|int $time Optional. A date/time string. Default: now * @param string|null $timezone Optional. Timezone identifier or DateTimeZone object. Default: null * @return void */ public function __construct($time = 'now', $timezone = null) { if (null === $timezone || !$timezone instanceof DateTimeZone) { $timezone = new DateTimeZone(); } parent::__construct($time, $timezone); }
/** * Instantiate FedoraDate. * * @param string $time * The date as you would pass to create a DateTime object. */ function __construct($time) { // Make sure we have a default timezone set. We need to use the shutup // operator because getting the timezone if its not set will actually // throw a warning. Ugh. date_default_timezone_set(@date_default_timezone_get()); parent::__construct($time, new DateTimeZone('UTC')); }
public function __construct($date = null, $month = null, $day = null, $hour = null, $minute = null, $second = null) { if (func_num_args() <= 1) { parent::__construct($this->validate($date)); } else { parent::__construct('@' . gmmktime($hour, $minute, $second, $month, $day, $date)); } }
/** * Create a new ExpressiveDate instance. * * @param string $time * @param string|DateTimeZone $timezone * @return void */ public function __construct($time = null, $timezone = null) { $timezone = $this->parseSuppliedTimezone($timezone); if (\is_numeric($time)) { $time = \date('Y-m-d H:i:s', $time); } parent::__construct($time, $timezone); }
/** * ctor * * Returns new DateTime object * @param string A date/time string. * @param \DateTimeZone A DateTimeZone object representing the timezone * @return \Base\Util\DateTime A new DateTime instance */ public function __construct($time = 'now', \DateTimeZone $timezone = null) { if (preg_match('/[\\d+]{10}/', $time)) { return static::createFromFormat('U', $time, $timezone); } else { return parent::__construct($time, $timezone); } }
public function __construct($time = 'now', \DateTimeZone $timezone = NULL) { if (is_null($timezone)) { $timezone = new \DateTimeZone(DI::get("config")->framework->timezone); } $this->time = $time; parent::__construct($time, $timezone); }
/** * @param string $date date as displayed on the website * @param string $time time as displayed on the website */ public function __construct($date, $time) { parent::__construct(); $this->setTimezone(new \DateTimeZone('Europe/Paris')); $this->fullMatch($date); list($hour, $second) = explode(':', $time); $this->setTime($hour, $second); }
/** * Method __construct * * @param string $time * @param \DateTimeZone $timezone * * @throws \Exception * @return DateTime * @link http://php.net/manual/en/datetime.construct.php */ public function __construct($time = 'now', $timezone = null) { if (!is_null($timezone) && !$timezone instanceof \DateTimeZone) { throw new \Exception('DateTime::__construct() expects parameter 2 to be DateTimeZone, ' . gettype($timezone) . ' given'); } parent::__construct($time, $timezone); $this->realDay = $this->format('j'); }
public function __construct($date, $month = null, $day = null) { if (func_num_args() == 1) { parent::__construct($this->validate($date)); } else { parent::__construct('@' . gmmktime(0, 0, 0, $month, $day, $date)); } }
/** * Overwrite constructor to used groupoffice default timezone and not systems default timezone * @param string $time * @param DateTimeZone $timezone */ public function __construct($time = "now", $timezone = null) { if ($timezone === null) { $tz = \GO::user() ? \GO::user()->timezone : \GO::config()->default_timezone; $timezone = new \DateTimeZone($tz); } parent::__construct($time, $timezone); }
/** * @param string $dateTime * @param string $timezone * * @return Moment */ public function resetDateTime($dateTime = 'now', $timezone = 'UTC') { // cache timezone string $this->_setTimezoneString($timezone); // create instance parent::__construct($dateTime, $this->_getDateTimeZone($timezone)); return $this; }
/** * Custom constructor. Defaults to UTC timezone if timezone isn't supplied. * * @param string $time * The date string, the timestamp in '@1306123200' format, or "now" for the * current time. * @param DateTimeZone $timezone * The timezone, if required. Default is NULL. */ public function __construct($time = "now", DateTimeZone $timezone = NULL) { if (empty($timezone)) { $timezone = new DateTimeZone("UTC"); } parent::__construct($time, $timezone); $this->setTimezone($timezone); }
public function __construct($time = null, $tz = null) { if ($tz !== null) { parent::__construct($time, self::safeCreateDateTimeZone($tz)); } else { parent::__construct($time); } }
public function __construct($time, $minute = null, $second = null, $micro = null, $offset = null) { if (func_num_args() == 1) { parent::__construct($this->validate($time)); } else { parent::__construct('@' . gmmktime($time, $minute, $second, 1, 1, 1970)); } }
public function __construct($time = 'now', $timezone = null) { $time = str_replace(array('/', '\\'), '-', $time); if (isset($timezone)) { return parent::__construct($time, $timezone); } else { return parent::__construct($time); } }