См. определение в файле main/lib/type/date.php строка 7
◆ __construct()
__construct |
( |
|
$date = null , |
|
|
|
$format = null |
|
) |
| |
- Аргументы
-
string | $date | String representation of date. |
string | $format | PHP date format. If not specified, the format is got from the current culture. |
- Исключения
-
См. определение в файле main/lib/type/date.php строка 18
20 $this->value = new \DateTime();
21 if ($date !==
null && $date !==
"")
25 $format = static::getFormat();
28 $parsedValue = date_parse_from_format($format, $date);
31 if ($parsedValue[
'error_count'] > 1)
34 current($parsedValue[
'errors']) !==
'Trailing data'
35 && current($parsedValue[
'errors']) !==
'Data missing'
38 throw new Main\ObjectException(
"Incorrect date: ".$date);
42 $this->value->setDate($parsedValue[
'year'], $parsedValue[
'month'], $parsedValue[
'day']);
45 isset($parsedValue[
"relative"])
46 && isset($parsedValue[
"relative"][
"second"])
47 && $parsedValue[
"relative"][
"second"] != 0
50 $this->value->add(
new \DateInterval(
"PT".$parsedValue[
"relative"][
"second"].
"S"));
53 $this->value->setTime(0, 0, 0);
◆ __clone()
◆ __toString()
Converts a date to the string with default culture format setting.
- Возвращает
- string
См. определение в файле main/lib/type/date.php строка 202
◆ add()
Performs dates arithmetic.
Each duration period is represented by an integer value followed by a period designator. If the duration contains time elements, that portion of the specification is preceded by the letter T. Period Designators: Y - years, M - months, D - days, W - weeks, H - hours, M - minutes, S - seconds. Examples: two days - 2D, two seconds - T2S, six years and five minutes - 6YT5M. The unit types must be entered from the largest scale unit on the left to the smallest scale unit on the right. Use first "-" char for negative periods. OR Relative period. Examples: "+5 weeks", "12 day", "-7 weekdays", '3 months - 5 days'
- Аргументы
-
string | $interval | Time interval to add. |
- Возвращает
- $this
См. определение в файле main/lib/type/date.php строка 98
100 $i = $this->tryToCreateIntervalByDesignators($interval);
103 $i = \DateInterval::createFromDateString($interval);
106 $this->value->add($i);
◆ convertFormatToPhp()
static convertFormatToPhp |
( |
|
$format | ) |
|
|
static |
Converts date format from culture to php format.
- Аргументы
-
string | $format | Format string. |
- Возвращает
- mixed
См. определение в файле main/lib/type/date.php строка 252
254 static $from = array(
275 $format = str_replace($from, $to, $format);
277 $tempFormat = $format;
278 $format = str_replace(
"HH",
"H", $format);
279 if ($tempFormat === $format)
281 $format = str_replace(
"H",
"h", $format);
284 $tempFormat = $format;
285 $format = str_replace(
"GG",
"G", $format);
286 if ($tempFormat === $format)
288 $format = str_replace(
"G",
"g", $format);
◆ createFromPhp()
static createFromPhp |
( |
\DateTime |
$datetime | ) |
|
|
static |
Creates Date object from PHP \DateTime object.
- Аргументы
-
\DateTime | $datetime | Source object. |
- Возвращает
- static
Переопределяется в DateTime.
См. определение в файле main/lib/type/date.php строка 330
334 $d->value = clone $datetime;
335 $d->value->setTime(0, 0, 0);
◆ createFromText()
static createFromText |
( |
|
$text | ) |
|
|
static |
Creates Date object from Text (return array of result object) Examples: "end of next week", "tomorrow morning", "friday 25.10".
- Аргументы
-
- Возвращает
- \Bitrix\Main\Type\DateTime|null
См. определение в файле main/lib/type/date.php строка 362
370 return $result[0]->getDate();
◆ createFromTimestamp()
static createFromTimestamp |
( |
|
$timestamp | ) |
|
|
static |
Creates Date object from Unix timestamp.
- Аргументы
-
int | $timestamp | Source timestamp. |
- Возвращает
- static
Переопределяется в DateTime.
См. определение в файле main/lib/type/date.php строка 346
350 $d->value->setTimestamp($timestamp);
351 $d->value->setTime(0, 0, 0);
◆ format()
Formats date value to string.
- Аргументы
-
string | $format | PHP date format. |
- Возвращает
- string
См. определение в файле main/lib/type/date.php строка 63
65 return $this->value->format($format);
◆ getCultureFormat()
static getCultureFormat |
( |
Context\Culture |
$culture | ) |
|
|
staticprotected |
Returns short date culture format.
- Аргументы
-
Context\Culture | $culture | Culture. |
- Возвращает
- string
Переопределяется в DateTime.
См. определение в файле main/lib/type/date.php строка 240
242 return $culture->getDateFormat();
◆ getDiff()
Returns difference between dates.
- Аргументы
-
- Возвращает
- \DateInterval
См. определение в файле main/lib/type/date.php строка 179
181 return $this->value->diff($time->value);
◆ getFormat()
static getFormat |
( |
Context\Culture |
$culture = null | ) |
|
|
static |
Returns a date format from the culture in the php format.
- Аргументы
-
Context\Culture | $culture | Optional culture. |
- Возвращает
- string
См. определение в файле main/lib/type/date.php строка 214
216 static $defaultCulture =
null;
218 if($culture ===
null)
220 if($defaultCulture ===
null)
223 $defaultCulture = $context->getCulture();
225 $culture = $defaultCulture;
228 $format = static::getCultureFormat($culture);
230 return static::convertFormatToPhp($format);
◆ getTimestamp()
Returns Unix timestamp from date.
- Возвращает
- int
См. определение в файле main/lib/type/date.php строка 168
170 return $this->value->getTimestamp();
◆ isCorrect()
static isCorrect |
( |
|
$time, |
|
|
|
$format = null |
|
) |
| |
|
static |
Checks the string for correct date (by trying to create Date object).
- Аргументы
-
string | $time | String representation of date. |
string | $format | PHP date format. If not specified, the format is got from the current culture. |
- Возвращает
- bool
См. определение в файле main/lib/type/date.php строка 302
313 new static($time, $format);
315 catch (Main\ObjectException $ex)
◆ setDate()
setDate |
( |
|
$year, |
|
|
|
$month, |
|
|
|
$day |
|
) |
| |
Sets the current date of the DateTime object to a different date.
- Аргументы
-
int | $year | |
int | $month | |
int | $day | |
- Возвращает
- $this
См. определение в файле main/lib/type/date.php строка 119
121 $this->value->setDate($year, $month, $day);
◆ toString()
toString |
( |
Context\Culture |
$culture = null | ) |
|
Converts a date to the string.
- Аргументы
-
Context\Culture | $culture | Culture contains date format. |
- Возвращает
- string
Переопределяется в DateTime.
См. определение в файле main/lib/type/date.php строка 191
193 $format = static::getFormat($culture);
194 return $this->
format($format);
◆ $value
Объявления и описания членов класса находятся в файле: