repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
brick/date-time
src/Duration.php
Duration.getTotalMillis
public function getTotalMillis() : int { $millis = $this->seconds * 1000; $millis += \intdiv($this->nanos, 1000000); return $millis; }
php
public function getTotalMillis() : int { $millis = $this->seconds * 1000; $millis += \intdiv($this->nanos, 1000000); return $millis; }
[ "public", "function", "getTotalMillis", "(", ")", ":", "int", "{", "$", "millis", "=", "$", "this", "->", "seconds", "*", "1000", ";", "$", "millis", "+=", "\\", "intdiv", "(", "$", "this", "->", "nanos", ",", "1000000", ")", ";", "return", "$", "millis", ";", "}" ]
Returns the total number of milliseconds in this Duration. The result is rounded towards negative infinity. @return int
[ "Returns", "the", "total", "number", "of", "milliseconds", "in", "this", "Duration", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/Duration.php#L611-L617
train
brick/date-time
src/Duration.php
Duration.getTotalMicros
public function getTotalMicros() : int { $micros = $this->seconds * 1000000; $micros += \intdiv($this->nanos, 1000); return $micros; }
php
public function getTotalMicros() : int { $micros = $this->seconds * 1000000; $micros += \intdiv($this->nanos, 1000); return $micros; }
[ "public", "function", "getTotalMicros", "(", ")", ":", "int", "{", "$", "micros", "=", "$", "this", "->", "seconds", "*", "1000000", ";", "$", "micros", "+=", "\\", "intdiv", "(", "$", "this", "->", "nanos", ",", "1000", ")", ";", "return", "$", "micros", ";", "}" ]
Returns the total number of microseconds in this Duration. The result is rounded towards negative infinity. @return int
[ "Returns", "the", "total", "number", "of", "microseconds", "in", "this", "Duration", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/Duration.php#L626-L632
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.of
public static function of(LocalDateTime $dateTime, TimeZone $timeZone) : ZonedDateTime { $dtz = $timeZone->toDateTimeZone(); $dt = new \DateTime((string) $dateTime->withNano(0), $dtz); $instant = Instant::of($dt->getTimestamp(), $dateTime->getNano()); if ($timeZone instanceof TimeZoneOffset) { $timeZoneOffset = $timeZone; } else { $timeZoneOffset = TimeZoneOffset::ofTotalSeconds($dt->getOffset()); } // The time can be affected if the date-time is not valid for the given time-zone due to a DST transition, // so we have to re-compute the local date-time from the DateTime object. // DateTime does not support nanos of seconds, so we just copy the nanos back from the original date-time. $dateTime = LocalDateTime::parse($dt->format('Y-m-d\TH:i:s'))->withNano($dateTime->getNano()); return new ZonedDateTime($dateTime, $timeZoneOffset, $timeZone, $instant); }
php
public static function of(LocalDateTime $dateTime, TimeZone $timeZone) : ZonedDateTime { $dtz = $timeZone->toDateTimeZone(); $dt = new \DateTime((string) $dateTime->withNano(0), $dtz); $instant = Instant::of($dt->getTimestamp(), $dateTime->getNano()); if ($timeZone instanceof TimeZoneOffset) { $timeZoneOffset = $timeZone; } else { $timeZoneOffset = TimeZoneOffset::ofTotalSeconds($dt->getOffset()); } // The time can be affected if the date-time is not valid for the given time-zone due to a DST transition, // so we have to re-compute the local date-time from the DateTime object. // DateTime does not support nanos of seconds, so we just copy the nanos back from the original date-time. $dateTime = LocalDateTime::parse($dt->format('Y-m-d\TH:i:s'))->withNano($dateTime->getNano()); return new ZonedDateTime($dateTime, $timeZoneOffset, $timeZone, $instant); }
[ "public", "static", "function", "of", "(", "LocalDateTime", "$", "dateTime", ",", "TimeZone", "$", "timeZone", ")", ":", "ZonedDateTime", "{", "$", "dtz", "=", "$", "timeZone", "->", "toDateTimeZone", "(", ")", ";", "$", "dt", "=", "new", "\\", "DateTime", "(", "(", "string", ")", "$", "dateTime", "->", "withNano", "(", "0", ")", ",", "$", "dtz", ")", ";", "$", "instant", "=", "Instant", "::", "of", "(", "$", "dt", "->", "getTimestamp", "(", ")", ",", "$", "dateTime", "->", "getNano", "(", ")", ")", ";", "if", "(", "$", "timeZone", "instanceof", "TimeZoneOffset", ")", "{", "$", "timeZoneOffset", "=", "$", "timeZone", ";", "}", "else", "{", "$", "timeZoneOffset", "=", "TimeZoneOffset", "::", "ofTotalSeconds", "(", "$", "dt", "->", "getOffset", "(", ")", ")", ";", "}", "// The time can be affected if the date-time is not valid for the given time-zone due to a DST transition,", "// so we have to re-compute the local date-time from the DateTime object.", "// DateTime does not support nanos of seconds, so we just copy the nanos back from the original date-time.", "$", "dateTime", "=", "LocalDateTime", "::", "parse", "(", "$", "dt", "->", "format", "(", "'Y-m-d\\TH:i:s'", ")", ")", "->", "withNano", "(", "$", "dateTime", "->", "getNano", "(", ")", ")", ";", "return", "new", "ZonedDateTime", "(", "$", "dateTime", ",", "$", "timeZoneOffset", ",", "$", "timeZone", ",", "$", "instant", ")", ";", "}" ]
Creates a ZonedDateTime from a LocalDateTime and a TimeZone. This resolves the local date-time to an instant on the time-line. When a TimeZoneOffset is used, the local date-time can be converted to an instant without ambiguity. When a TimeZoneRegion is used, Daylight Saving Time can make the conversion more complex. There are 3 cases: - Normal: when there is only one valid offset for the date-time. The conversion is then as straightforward as when using a TimeZoneOffset. This is fortunately the case for the vast majority of the year. - Gap: when there is no valid offset for the date-time. This happens when the clock jumps forward typically due to a DST transition from "winter" to "summer". The date-times between the two times of the transition do not exist. - Overlap: when there are two valid offets for the date-time. This happens when the clock is set back typically due to a DST transition from "summer" to "winter". The date-times between the two times of the transition can be resolved to two different offsets, representing two different instants on the time-line. The strategy for resolving gaps and overlaps is the following: - If the local date-time falls in the middle of a gap, then the resulting date-time will be shifted forward by the length of the gap, and the later offset, typically "summer" time, will be used. - If the local date-time falls in the middle of an overlap, then the offset closest to UTC will be used. @param LocalDateTime $dateTime @param TimeZone timeZone @return ZonedDateTime
[ "Creates", "a", "ZonedDateTime", "from", "a", "LocalDateTime", "and", "a", "TimeZone", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L98-L117
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.ofInstant
public static function ofInstant(Instant $instant, TimeZone $timeZone) : ZonedDateTime { $dateTimeZone = $timeZone->toDateTimeZone(); // We need to pass a DateTimeZone to avoid a PHP warning... $dateTime = new \DateTime('@' . $instant->getEpochSecond(), $dateTimeZone); // ... but this DateTimeZone is ignored because of the timestamp, so we set it again. $dateTime->setTimezone($dateTimeZone); $localDateTime = LocalDateTime::parse($dateTime->format('Y-m-d\TH:i:s')); $localDateTime = $localDateTime->withNano($instant->getNano()); if ($timeZone instanceof TimeZoneOffset) { $timeZoneOffset = $timeZone; } else { $timeZoneOffset = TimeZoneOffset::ofTotalSeconds($dateTime->getOffset()); } return new ZonedDateTime($localDateTime, $timeZoneOffset, $timeZone, $instant); }
php
public static function ofInstant(Instant $instant, TimeZone $timeZone) : ZonedDateTime { $dateTimeZone = $timeZone->toDateTimeZone(); // We need to pass a DateTimeZone to avoid a PHP warning... $dateTime = new \DateTime('@' . $instant->getEpochSecond(), $dateTimeZone); // ... but this DateTimeZone is ignored because of the timestamp, so we set it again. $dateTime->setTimezone($dateTimeZone); $localDateTime = LocalDateTime::parse($dateTime->format('Y-m-d\TH:i:s')); $localDateTime = $localDateTime->withNano($instant->getNano()); if ($timeZone instanceof TimeZoneOffset) { $timeZoneOffset = $timeZone; } else { $timeZoneOffset = TimeZoneOffset::ofTotalSeconds($dateTime->getOffset()); } return new ZonedDateTime($localDateTime, $timeZoneOffset, $timeZone, $instant); }
[ "public", "static", "function", "ofInstant", "(", "Instant", "$", "instant", ",", "TimeZone", "$", "timeZone", ")", ":", "ZonedDateTime", "{", "$", "dateTimeZone", "=", "$", "timeZone", "->", "toDateTimeZone", "(", ")", ";", "// We need to pass a DateTimeZone to avoid a PHP warning...", "$", "dateTime", "=", "new", "\\", "DateTime", "(", "'@'", ".", "$", "instant", "->", "getEpochSecond", "(", ")", ",", "$", "dateTimeZone", ")", ";", "// ... but this DateTimeZone is ignored because of the timestamp, so we set it again.", "$", "dateTime", "->", "setTimezone", "(", "$", "dateTimeZone", ")", ";", "$", "localDateTime", "=", "LocalDateTime", "::", "parse", "(", "$", "dateTime", "->", "format", "(", "'Y-m-d\\TH:i:s'", ")", ")", ";", "$", "localDateTime", "=", "$", "localDateTime", "->", "withNano", "(", "$", "instant", "->", "getNano", "(", ")", ")", ";", "if", "(", "$", "timeZone", "instanceof", "TimeZoneOffset", ")", "{", "$", "timeZoneOffset", "=", "$", "timeZone", ";", "}", "else", "{", "$", "timeZoneOffset", "=", "TimeZoneOffset", "::", "ofTotalSeconds", "(", "$", "dateTime", "->", "getOffset", "(", ")", ")", ";", "}", "return", "new", "ZonedDateTime", "(", "$", "localDateTime", ",", "$", "timeZoneOffset", ",", "$", "timeZone", ",", "$", "instant", ")", ";", "}" ]
Creates a ZonedDateTime from an instant and a time zone. This resolves the instant to a date and time without ambiguity. @param Instant $instant The instant. @param TimeZone $timeZone The time zone. @return ZonedDateTime
[ "Creates", "a", "ZonedDateTime", "from", "an", "instant", "and", "a", "time", "zone", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L129-L149
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.now
public static function now(TimeZone $timeZone, Clock $clock = null) : ZonedDateTime { return ZonedDateTime::ofInstant(Instant::now($clock), $timeZone); }
php
public static function now(TimeZone $timeZone, Clock $clock = null) : ZonedDateTime { return ZonedDateTime::ofInstant(Instant::now($clock), $timeZone); }
[ "public", "static", "function", "now", "(", "TimeZone", "$", "timeZone", ",", "Clock", "$", "clock", "=", "null", ")", ":", "ZonedDateTime", "{", "return", "ZonedDateTime", "::", "ofInstant", "(", "Instant", "::", "now", "(", "$", "clock", ")", ",", "$", "timeZone", ")", ";", "}" ]
Returns the current date-time in the given time-zone, according to the given clock. If no clock is provided, the system clock is used. @param TimeZone $timeZone @param Clock|null $clock @return ZonedDateTime
[ "Returns", "the", "current", "date", "-", "time", "in", "the", "given", "time", "-", "zone", "according", "to", "the", "given", "clock", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L161-L164
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.from
public static function from(DateTimeParseResult $result) : ZonedDateTime { $localDateTime = LocalDateTime::from($result); $timeZoneOffset = TimeZoneOffset::from($result); if ($result->hasField(Field\TimeZoneRegion::NAME)) { $timeZone = TimeZoneRegion::from($result); } else { $timeZone = $timeZoneOffset; } return ZonedDateTime::of( $localDateTime, $timeZone ); }
php
public static function from(DateTimeParseResult $result) : ZonedDateTime { $localDateTime = LocalDateTime::from($result); $timeZoneOffset = TimeZoneOffset::from($result); if ($result->hasField(Field\TimeZoneRegion::NAME)) { $timeZone = TimeZoneRegion::from($result); } else { $timeZone = $timeZoneOffset; } return ZonedDateTime::of( $localDateTime, $timeZone ); }
[ "public", "static", "function", "from", "(", "DateTimeParseResult", "$", "result", ")", ":", "ZonedDateTime", "{", "$", "localDateTime", "=", "LocalDateTime", "::", "from", "(", "$", "result", ")", ";", "$", "timeZoneOffset", "=", "TimeZoneOffset", "::", "from", "(", "$", "result", ")", ";", "if", "(", "$", "result", "->", "hasField", "(", "Field", "\\", "TimeZoneRegion", "::", "NAME", ")", ")", "{", "$", "timeZone", "=", "TimeZoneRegion", "::", "from", "(", "$", "result", ")", ";", "}", "else", "{", "$", "timeZone", "=", "$", "timeZoneOffset", ";", "}", "return", "ZonedDateTime", "::", "of", "(", "$", "localDateTime", ",", "$", "timeZone", ")", ";", "}" ]
Obtains an instance of `ZonedDateTime` from a set of date-time fields. This method is only useful to parsers. @param DateTimeParseResult $result @return ZonedDateTime @throws DateTimeException If the zoned date-time is not valid. @throws DateTimeParseException If required fields are missing from the result.
[ "Obtains", "an", "instance", "of", "ZonedDateTime", "from", "a", "set", "of", "date", "-", "time", "fields", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L178-L194
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.parse
public static function parse(string $text, DateTimeParser $parser = null) : ZonedDateTime { if (! $parser) { $parser = IsoParsers::zonedDateTime(); } return ZonedDateTime::from($parser->parse($text)); }
php
public static function parse(string $text, DateTimeParser $parser = null) : ZonedDateTime { if (! $parser) { $parser = IsoParsers::zonedDateTime(); } return ZonedDateTime::from($parser->parse($text)); }
[ "public", "static", "function", "parse", "(", "string", "$", "text", ",", "DateTimeParser", "$", "parser", "=", "null", ")", ":", "ZonedDateTime", "{", "if", "(", "!", "$", "parser", ")", "{", "$", "parser", "=", "IsoParsers", "::", "zonedDateTime", "(", ")", ";", "}", "return", "ZonedDateTime", "::", "from", "(", "$", "parser", "->", "parse", "(", "$", "text", ")", ")", ";", "}" ]
Obtains an instance of `ZonedDateTime` from a text string. Valid examples: - `2007-12-03T10:15:30:45Z` - `2007-12-03T10:15:30+01:00` - `2007-12-03T10:15:30+01:00[Europe/Paris]` @param string $text The text to parse. @param DateTimeParser|null $parser The parser to use, defaults to the ISO 8601 parser. @return ZonedDateTime @throws DateTimeException If the date is not valid. @throws DateTimeParseException If the text string does not follow the expected format.
[ "Obtains", "an", "instance", "of", "ZonedDateTime", "from", "a", "text", "string", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L212-L219
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.fromDateTime
public static function fromDateTime(\DateTimeInterface $dateTime) : ZonedDateTime { $localDateTime = LocalDateTime::fromDateTime($dateTime); $dateTimeZone = $dateTime->getTimezone(); if ($dateTimeZone === false) { throw new DateTimeException('This DateTime object has no timezone.'); } $timeZone = TimeZone::fromDateTimeZone($dateTimeZone); if ($timeZone instanceof TimeZoneOffset) { $timeZoneOffset = $timeZone; } else { $timeZoneOffset = TimeZoneOffset::ofTotalSeconds($dateTime->getOffset()); } $instant = Instant::of($dateTime->getTimestamp(), $localDateTime->getNano()); return new ZonedDateTime($localDateTime, $timeZoneOffset, $timeZone, $instant); }
php
public static function fromDateTime(\DateTimeInterface $dateTime) : ZonedDateTime { $localDateTime = LocalDateTime::fromDateTime($dateTime); $dateTimeZone = $dateTime->getTimezone(); if ($dateTimeZone === false) { throw new DateTimeException('This DateTime object has no timezone.'); } $timeZone = TimeZone::fromDateTimeZone($dateTimeZone); if ($timeZone instanceof TimeZoneOffset) { $timeZoneOffset = $timeZone; } else { $timeZoneOffset = TimeZoneOffset::ofTotalSeconds($dateTime->getOffset()); } $instant = Instant::of($dateTime->getTimestamp(), $localDateTime->getNano()); return new ZonedDateTime($localDateTime, $timeZoneOffset, $timeZone, $instant); }
[ "public", "static", "function", "fromDateTime", "(", "\\", "DateTimeInterface", "$", "dateTime", ")", ":", "ZonedDateTime", "{", "$", "localDateTime", "=", "LocalDateTime", "::", "fromDateTime", "(", "$", "dateTime", ")", ";", "$", "dateTimeZone", "=", "$", "dateTime", "->", "getTimezone", "(", ")", ";", "if", "(", "$", "dateTimeZone", "===", "false", ")", "{", "throw", "new", "DateTimeException", "(", "'This DateTime object has no timezone.'", ")", ";", "}", "$", "timeZone", "=", "TimeZone", "::", "fromDateTimeZone", "(", "$", "dateTimeZone", ")", ";", "if", "(", "$", "timeZone", "instanceof", "TimeZoneOffset", ")", "{", "$", "timeZoneOffset", "=", "$", "timeZone", ";", "}", "else", "{", "$", "timeZoneOffset", "=", "TimeZoneOffset", "::", "ofTotalSeconds", "(", "$", "dateTime", "->", "getOffset", "(", ")", ")", ";", "}", "$", "instant", "=", "Instant", "::", "of", "(", "$", "dateTime", "->", "getTimestamp", "(", ")", ",", "$", "localDateTime", "->", "getNano", "(", ")", ")", ";", "return", "new", "ZonedDateTime", "(", "$", "localDateTime", ",", "$", "timeZoneOffset", ",", "$", "timeZone", ",", "$", "instant", ")", ";", "}" ]
Creates a ZonedDateTime from a native DateTime or DateTimeImmutable object. @param \DateTimeInterface $dateTime @return ZonedDateTime @throws DateTimeException If the DateTime object has no timezone.
[ "Creates", "a", "ZonedDateTime", "from", "a", "native", "DateTime", "or", "DateTimeImmutable", "object", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L229-L250
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.withDate
public function withDate(LocalDate $date) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->withDate($date), $this->timeZone); }
php
public function withDate(LocalDate $date) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->withDate($date), $this->timeZone); }
[ "public", "function", "withDate", "(", "LocalDate", "$", "date", ")", ":", "ZonedDateTime", "{", "return", "ZonedDateTime", "::", "of", "(", "$", "this", "->", "localDateTime", "->", "withDate", "(", "$", "date", ")", ",", "$", "this", "->", "timeZone", ")", ";", "}" ]
Returns a copy of this ZonedDateTime with a different date. @param LocalDate $date @return ZonedDateTime
[ "Returns", "a", "copy", "of", "this", "ZonedDateTime", "with", "a", "different", "date", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L397-L400
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.withTime
public function withTime(LocalTime $time) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->withTime($time), $this->timeZone); }
php
public function withTime(LocalTime $time) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->withTime($time), $this->timeZone); }
[ "public", "function", "withTime", "(", "LocalTime", "$", "time", ")", ":", "ZonedDateTime", "{", "return", "ZonedDateTime", "::", "of", "(", "$", "this", "->", "localDateTime", "->", "withTime", "(", "$", "time", ")", ",", "$", "this", "->", "timeZone", ")", ";", "}" ]
Returns a copy of this ZonedDateTime with a different time. @param LocalTime $time @return ZonedDateTime
[ "Returns", "a", "copy", "of", "this", "ZonedDateTime", "with", "a", "different", "time", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L409-L412
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.withYear
public function withYear(int $year) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->withYear($year), $this->timeZone); }
php
public function withYear(int $year) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->withYear($year), $this->timeZone); }
[ "public", "function", "withYear", "(", "int", "$", "year", ")", ":", "ZonedDateTime", "{", "return", "ZonedDateTime", "::", "of", "(", "$", "this", "->", "localDateTime", "->", "withYear", "(", "$", "year", ")", ",", "$", "this", "->", "timeZone", ")", ";", "}" ]
Returns a copy of this ZonedDateTime with the year altered. @param int $year @return ZonedDateTime
[ "Returns", "a", "copy", "of", "this", "ZonedDateTime", "with", "the", "year", "altered", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L421-L424
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.withMonth
public function withMonth(int $month) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->withMonth($month), $this->timeZone); }
php
public function withMonth(int $month) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->withMonth($month), $this->timeZone); }
[ "public", "function", "withMonth", "(", "int", "$", "month", ")", ":", "ZonedDateTime", "{", "return", "ZonedDateTime", "::", "of", "(", "$", "this", "->", "localDateTime", "->", "withMonth", "(", "$", "month", ")", ",", "$", "this", "->", "timeZone", ")", ";", "}" ]
Returns a copy of this ZonedDateTime with the month-of-year altered. @param int $month @return ZonedDateTime
[ "Returns", "a", "copy", "of", "this", "ZonedDateTime", "with", "the", "month", "-", "of", "-", "year", "altered", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L433-L436
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.withDay
public function withDay(int $day) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->withDay($day), $this->timeZone); }
php
public function withDay(int $day) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->withDay($day), $this->timeZone); }
[ "public", "function", "withDay", "(", "int", "$", "day", ")", ":", "ZonedDateTime", "{", "return", "ZonedDateTime", "::", "of", "(", "$", "this", "->", "localDateTime", "->", "withDay", "(", "$", "day", ")", ",", "$", "this", "->", "timeZone", ")", ";", "}" ]
Returns a copy of this ZonedDateTime with the day-of-month altered. @param int $day @return ZonedDateTime
[ "Returns", "a", "copy", "of", "this", "ZonedDateTime", "with", "the", "day", "-", "of", "-", "month", "altered", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L445-L448
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.withHour
public function withHour(int $hour) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->withHour($hour), $this->timeZone); }
php
public function withHour(int $hour) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->withHour($hour), $this->timeZone); }
[ "public", "function", "withHour", "(", "int", "$", "hour", ")", ":", "ZonedDateTime", "{", "return", "ZonedDateTime", "::", "of", "(", "$", "this", "->", "localDateTime", "->", "withHour", "(", "$", "hour", ")", ",", "$", "this", "->", "timeZone", ")", ";", "}" ]
Returns a copy of this ZonedDateTime with the hour-of-day altered. @param int $hour @return ZonedDateTime
[ "Returns", "a", "copy", "of", "this", "ZonedDateTime", "with", "the", "hour", "-", "of", "-", "day", "altered", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L457-L460
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.withMinute
public function withMinute(int $minute) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->withMinute($minute), $this->timeZone); }
php
public function withMinute(int $minute) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->withMinute($minute), $this->timeZone); }
[ "public", "function", "withMinute", "(", "int", "$", "minute", ")", ":", "ZonedDateTime", "{", "return", "ZonedDateTime", "::", "of", "(", "$", "this", "->", "localDateTime", "->", "withMinute", "(", "$", "minute", ")", ",", "$", "this", "->", "timeZone", ")", ";", "}" ]
Returns a copy of this ZonedDateTime with the minute-of-hour altered. @param int $minute @return ZonedDateTime
[ "Returns", "a", "copy", "of", "this", "ZonedDateTime", "with", "the", "minute", "-", "of", "-", "hour", "altered", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L469-L472
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.withSecond
public function withSecond(int $second) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->withSecond($second), $this->timeZone); }
php
public function withSecond(int $second) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->withSecond($second), $this->timeZone); }
[ "public", "function", "withSecond", "(", "int", "$", "second", ")", ":", "ZonedDateTime", "{", "return", "ZonedDateTime", "::", "of", "(", "$", "this", "->", "localDateTime", "->", "withSecond", "(", "$", "second", ")", ",", "$", "this", "->", "timeZone", ")", ";", "}" ]
Returns a copy of this ZonedDateTime with the second-of-minute altered. @param int $second @return ZonedDateTime
[ "Returns", "a", "copy", "of", "this", "ZonedDateTime", "with", "the", "second", "-", "of", "-", "minute", "altered", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L481-L484
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.withNano
public function withNano(int $nano) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->withNano($nano), $this->timeZone); }
php
public function withNano(int $nano) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->withNano($nano), $this->timeZone); }
[ "public", "function", "withNano", "(", "int", "$", "nano", ")", ":", "ZonedDateTime", "{", "return", "ZonedDateTime", "::", "of", "(", "$", "this", "->", "localDateTime", "->", "withNano", "(", "$", "nano", ")", ",", "$", "this", "->", "timeZone", ")", ";", "}" ]
Returns a copy of this ZonedDateTime with the nano-of-second altered. @param int $nano @return ZonedDateTime
[ "Returns", "a", "copy", "of", "this", "ZonedDateTime", "with", "the", "nano", "-", "of", "-", "second", "altered", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L493-L496
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.plusPeriod
public function plusPeriod(Period $period) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->plusPeriod($period), $this->timeZone); }
php
public function plusPeriod(Period $period) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->plusPeriod($period), $this->timeZone); }
[ "public", "function", "plusPeriod", "(", "Period", "$", "period", ")", ":", "ZonedDateTime", "{", "return", "ZonedDateTime", "::", "of", "(", "$", "this", "->", "localDateTime", "->", "plusPeriod", "(", "$", "period", ")", ",", "$", "this", "->", "timeZone", ")", ";", "}" ]
Returns a copy of this ZonedDateTime with the specified Period added. @param Period $period @return ZonedDateTime
[ "Returns", "a", "copy", "of", "this", "ZonedDateTime", "with", "the", "specified", "Period", "added", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L549-L552
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.plusDuration
public function plusDuration(Duration $duration) : ZonedDateTime { return ZonedDateTime::ofInstant($this->instant->plus($duration), $this->timeZone); }
php
public function plusDuration(Duration $duration) : ZonedDateTime { return ZonedDateTime::ofInstant($this->instant->plus($duration), $this->timeZone); }
[ "public", "function", "plusDuration", "(", "Duration", "$", "duration", ")", ":", "ZonedDateTime", "{", "return", "ZonedDateTime", "::", "ofInstant", "(", "$", "this", "->", "instant", "->", "plus", "(", "$", "duration", ")", ",", "$", "this", "->", "timeZone", ")", ";", "}" ]
Returns a copy of this ZonedDateTime with the specified Duration added. @param Duration $duration @return ZonedDateTime
[ "Returns", "a", "copy", "of", "this", "ZonedDateTime", "with", "the", "specified", "Duration", "added", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L561-L564
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.plusYears
public function plusYears(int $years) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->plusYears($years), $this->timeZone); }
php
public function plusYears(int $years) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->plusYears($years), $this->timeZone); }
[ "public", "function", "plusYears", "(", "int", "$", "years", ")", ":", "ZonedDateTime", "{", "return", "ZonedDateTime", "::", "of", "(", "$", "this", "->", "localDateTime", "->", "plusYears", "(", "$", "years", ")", ",", "$", "this", "->", "timeZone", ")", ";", "}" ]
Returns a copy of this ZonedDateTime with the specified period in years added. @param int $years @return ZonedDateTime
[ "Returns", "a", "copy", "of", "this", "ZonedDateTime", "with", "the", "specified", "period", "in", "years", "added", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L573-L576
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.plusMonths
public function plusMonths(int $months) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->plusMonths($months), $this->timeZone); }
php
public function plusMonths(int $months) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->plusMonths($months), $this->timeZone); }
[ "public", "function", "plusMonths", "(", "int", "$", "months", ")", ":", "ZonedDateTime", "{", "return", "ZonedDateTime", "::", "of", "(", "$", "this", "->", "localDateTime", "->", "plusMonths", "(", "$", "months", ")", ",", "$", "this", "->", "timeZone", ")", ";", "}" ]
Returns a copy of this ZonedDateTime with the specified period in months added. @param int $months @return ZonedDateTime
[ "Returns", "a", "copy", "of", "this", "ZonedDateTime", "with", "the", "specified", "period", "in", "months", "added", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L585-L588
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.plusWeeks
public function plusWeeks(int $weeks) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->plusWeeks($weeks), $this->timeZone); }
php
public function plusWeeks(int $weeks) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->plusWeeks($weeks), $this->timeZone); }
[ "public", "function", "plusWeeks", "(", "int", "$", "weeks", ")", ":", "ZonedDateTime", "{", "return", "ZonedDateTime", "::", "of", "(", "$", "this", "->", "localDateTime", "->", "plusWeeks", "(", "$", "weeks", ")", ",", "$", "this", "->", "timeZone", ")", ";", "}" ]
Returns a copy of this ZonedDateTime with the specified period in weeks added. @param int $weeks @return ZonedDateTime
[ "Returns", "a", "copy", "of", "this", "ZonedDateTime", "with", "the", "specified", "period", "in", "weeks", "added", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L597-L600
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.plusDays
public function plusDays(int $days) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->plusDays($days), $this->timeZone); }
php
public function plusDays(int $days) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->plusDays($days), $this->timeZone); }
[ "public", "function", "plusDays", "(", "int", "$", "days", ")", ":", "ZonedDateTime", "{", "return", "ZonedDateTime", "::", "of", "(", "$", "this", "->", "localDateTime", "->", "plusDays", "(", "$", "days", ")", ",", "$", "this", "->", "timeZone", ")", ";", "}" ]
Returns a copy of this ZonedDateTime with the specified period in days added. @param int $days @return ZonedDateTime
[ "Returns", "a", "copy", "of", "this", "ZonedDateTime", "with", "the", "specified", "period", "in", "days", "added", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L609-L612
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.plusHours
public function plusHours(int $hours) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->plusHours($hours), $this->timeZone); }
php
public function plusHours(int $hours) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->plusHours($hours), $this->timeZone); }
[ "public", "function", "plusHours", "(", "int", "$", "hours", ")", ":", "ZonedDateTime", "{", "return", "ZonedDateTime", "::", "of", "(", "$", "this", "->", "localDateTime", "->", "plusHours", "(", "$", "hours", ")", ",", "$", "this", "->", "timeZone", ")", ";", "}" ]
Returns a copy of this ZonedDateTime with the specified period in hours added. @param int $hours @return ZonedDateTime
[ "Returns", "a", "copy", "of", "this", "ZonedDateTime", "with", "the", "specified", "period", "in", "hours", "added", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L621-L624
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.plusMinutes
public function plusMinutes(int $minutes) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->plusMinutes($minutes), $this->timeZone); }
php
public function plusMinutes(int $minutes) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->plusMinutes($minutes), $this->timeZone); }
[ "public", "function", "plusMinutes", "(", "int", "$", "minutes", ")", ":", "ZonedDateTime", "{", "return", "ZonedDateTime", "::", "of", "(", "$", "this", "->", "localDateTime", "->", "plusMinutes", "(", "$", "minutes", ")", ",", "$", "this", "->", "timeZone", ")", ";", "}" ]
Returns a copy of this ZonedDateTime with the specified period in minutes added. @param int $minutes @return ZonedDateTime
[ "Returns", "a", "copy", "of", "this", "ZonedDateTime", "with", "the", "specified", "period", "in", "minutes", "added", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L633-L636
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.plusSeconds
public function plusSeconds(int $seconds) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->plusSeconds($seconds), $this->timeZone); }
php
public function plusSeconds(int $seconds) : ZonedDateTime { return ZonedDateTime::of($this->localDateTime->plusSeconds($seconds), $this->timeZone); }
[ "public", "function", "plusSeconds", "(", "int", "$", "seconds", ")", ":", "ZonedDateTime", "{", "return", "ZonedDateTime", "::", "of", "(", "$", "this", "->", "localDateTime", "->", "plusSeconds", "(", "$", "seconds", ")", ",", "$", "this", "->", "timeZone", ")", ";", "}" ]
Returns a copy of this ZonedDateTime with the specified period in seconds added. @param int $seconds @return ZonedDateTime
[ "Returns", "a", "copy", "of", "this", "ZonedDateTime", "with", "the", "specified", "period", "in", "seconds", "added", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L645-L648
train
brick/date-time
src/ZonedDateTime.php
ZonedDateTime.toDateTime
public function toDateTime() : \DateTime { $second = $this->localDateTime->getSecond(); // round down to the microsecond $nano = $this->localDateTime->getNano(); $nano = 1000 * intdiv($nano, 1000); $dateTime = (string) $this->localDateTime->withNano($nano); $dateTimeZone = $this->timeZone->toDateTimeZone(); $format = 'Y-m-d\TH:i'; if ($second !== 0 || $nano !== 0) { $format .= ':s'; if ($nano !== 0) { $format .= '.u'; } } return \DateTime::createFromFormat($format, $dateTime, $dateTimeZone); }
php
public function toDateTime() : \DateTime { $second = $this->localDateTime->getSecond(); // round down to the microsecond $nano = $this->localDateTime->getNano(); $nano = 1000 * intdiv($nano, 1000); $dateTime = (string) $this->localDateTime->withNano($nano); $dateTimeZone = $this->timeZone->toDateTimeZone(); $format = 'Y-m-d\TH:i'; if ($second !== 0 || $nano !== 0) { $format .= ':s'; if ($nano !== 0) { $format .= '.u'; } } return \DateTime::createFromFormat($format, $dateTime, $dateTimeZone); }
[ "public", "function", "toDateTime", "(", ")", ":", "\\", "DateTime", "{", "$", "second", "=", "$", "this", "->", "localDateTime", "->", "getSecond", "(", ")", ";", "// round down to the microsecond", "$", "nano", "=", "$", "this", "->", "localDateTime", "->", "getNano", "(", ")", ";", "$", "nano", "=", "1000", "*", "intdiv", "(", "$", "nano", ",", "1000", ")", ";", "$", "dateTime", "=", "(", "string", ")", "$", "this", "->", "localDateTime", "->", "withNano", "(", "$", "nano", ")", ";", "$", "dateTimeZone", "=", "$", "this", "->", "timeZone", "->", "toDateTimeZone", "(", ")", ";", "$", "format", "=", "'Y-m-d\\TH:i'", ";", "if", "(", "$", "second", "!==", "0", "||", "$", "nano", "!==", "0", ")", "{", "$", "format", ".=", "':s'", ";", "if", "(", "$", "nano", "!==", "0", ")", "{", "$", "format", ".=", "'.u'", ";", "}", "}", "return", "\\", "DateTime", "::", "createFromFormat", "(", "$", "format", ",", "$", "dateTime", ",", "$", "dateTimeZone", ")", ";", "}" ]
Converts this ZonedDateTime to a native DateTime object. Note that the native DateTime object supports a precision up to the microsecond, so the nanoseconds are rounded down to the nearest microsecond. @return \DateTime
[ "Converts", "this", "ZonedDateTime", "to", "a", "native", "DateTime", "object", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/ZonedDateTime.php#L890-L912
train
brick/date-time
src/Month.php
Month.get
private static function get(int $value) : Month { static $values; if (! isset($values[$value])) { $values[$value] = new Month($value); } return $values[$value]; }
php
private static function get(int $value) : Month { static $values; if (! isset($values[$value])) { $values[$value] = new Month($value); } return $values[$value]; }
[ "private", "static", "function", "get", "(", "int", "$", "value", ")", ":", "Month", "{", "static", "$", "values", ";", "if", "(", "!", "isset", "(", "$", "values", "[", "$", "value", "]", ")", ")", "{", "$", "values", "[", "$", "value", "]", "=", "new", "Month", "(", "$", "value", ")", ";", "}", "return", "$", "values", "[", "$", "value", "]", ";", "}" ]
Returns a cached Month instance. @param int $value The month value, validated from 1 to 12. @return Month The cached Month instance.
[ "Returns", "a", "cached", "Month", "instance", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/Month.php#L49-L58
train
brick/date-time
src/Month.php
Month.of
public static function of(int $value) : Month { Field\MonthOfYear::check($value); return Month::get($value); }
php
public static function of(int $value) : Month { Field\MonthOfYear::check($value); return Month::get($value); }
[ "public", "static", "function", "of", "(", "int", "$", "value", ")", ":", "Month", "{", "Field", "\\", "MonthOfYear", "::", "check", "(", "$", "value", ")", ";", "return", "Month", "::", "get", "(", "$", "value", ")", ";", "}" ]
Returns an instance of Month for the given month value. @param int $value The month number, from 1 (January) to 12 (December). @return Month The Month instance. @throws DateTimeException
[ "Returns", "an", "instance", "of", "Month", "for", "the", "given", "month", "value", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/Month.php#L69-L74
train
brick/date-time
src/Month.php
Month.getAll
public static function getAll() : array { $months = []; for ($month = Month::JANUARY; $month <= Month::DECEMBER; $month++) { $months[] = Month::get($month); } return $months; }
php
public static function getAll() : array { $months = []; for ($month = Month::JANUARY; $month <= Month::DECEMBER; $month++) { $months[] = Month::get($month); } return $months; }
[ "public", "static", "function", "getAll", "(", ")", ":", "array", "{", "$", "months", "=", "[", "]", ";", "for", "(", "$", "month", "=", "Month", "::", "JANUARY", ";", "$", "month", "<=", "Month", "::", "DECEMBER", ";", "$", "month", "++", ")", "{", "$", "months", "[", "]", "=", "Month", "::", "get", "(", "$", "month", ")", ";", "}", "return", "$", "months", ";", "}" ]
Returns the twelve months of the year in an array. @return Month[]
[ "Returns", "the", "twelve", "months", "of", "the", "year", "in", "an", "array", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/Month.php#L81-L90
train
brick/date-time
src/Month.php
Month.getMinLength
public function getMinLength() : int { switch ($this->month) { case Month::FEBRUARY: return 28; case Month::APRIL: case Month::JUNE: case Month::SEPTEMBER: case Month::NOVEMBER: return 30; default: return 31; } }
php
public function getMinLength() : int { switch ($this->month) { case Month::FEBRUARY: return 28; case Month::APRIL: case Month::JUNE: case Month::SEPTEMBER: case Month::NOVEMBER: return 30; default: return 31; } }
[ "public", "function", "getMinLength", "(", ")", ":", "int", "{", "switch", "(", "$", "this", "->", "month", ")", "{", "case", "Month", "::", "FEBRUARY", ":", "return", "28", ";", "case", "Month", "::", "APRIL", ":", "case", "Month", "::", "JUNE", ":", "case", "Month", "::", "SEPTEMBER", ":", "case", "Month", "::", "NOVEMBER", ":", "return", "30", ";", "default", ":", "return", "31", ";", "}", "}" ]
Returns the minimum length of this month in days. @return int The minimum length of this month in days, from 28 to 31.
[ "Returns", "the", "minimum", "length", "of", "this", "month", "in", "days", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/Month.php#L131-L144
train
brick/date-time
src/Month.php
Month.getFirstDayOfYear
public function getFirstDayOfYear(bool $leapYear) : int { $leap = $leapYear ? 1 : 0; switch ($this->month) { case Month::JANUARY: return 1; case Month::FEBRUARY: return 32; case Month::MARCH: return 60 + $leap; case Month::APRIL: return 91 + $leap; case Month::MAY: return 121 + $leap; case Month::JUNE: return 152 + $leap; case Month::JULY: return 182 + $leap; case Month::AUGUST: return 213 + $leap; case Month::SEPTEMBER: return 244 + $leap; case Month::OCTOBER: return 274 + $leap; case Month::NOVEMBER: return 305 + $leap; } return 335 + $leap; }
php
public function getFirstDayOfYear(bool $leapYear) : int { $leap = $leapYear ? 1 : 0; switch ($this->month) { case Month::JANUARY: return 1; case Month::FEBRUARY: return 32; case Month::MARCH: return 60 + $leap; case Month::APRIL: return 91 + $leap; case Month::MAY: return 121 + $leap; case Month::JUNE: return 152 + $leap; case Month::JULY: return 182 + $leap; case Month::AUGUST: return 213 + $leap; case Month::SEPTEMBER: return 244 + $leap; case Month::OCTOBER: return 274 + $leap; case Month::NOVEMBER: return 305 + $leap; } return 335 + $leap; }
[ "public", "function", "getFirstDayOfYear", "(", "bool", "$", "leapYear", ")", ":", "int", "{", "$", "leap", "=", "$", "leapYear", "?", "1", ":", "0", ";", "switch", "(", "$", "this", "->", "month", ")", "{", "case", "Month", "::", "JANUARY", ":", "return", "1", ";", "case", "Month", "::", "FEBRUARY", ":", "return", "32", ";", "case", "Month", "::", "MARCH", ":", "return", "60", "+", "$", "leap", ";", "case", "Month", "::", "APRIL", ":", "return", "91", "+", "$", "leap", ";", "case", "Month", "::", "MAY", ":", "return", "121", "+", "$", "leap", ";", "case", "Month", "::", "JUNE", ":", "return", "152", "+", "$", "leap", ";", "case", "Month", "::", "JULY", ":", "return", "182", "+", "$", "leap", ";", "case", "Month", "::", "AUGUST", ":", "return", "213", "+", "$", "leap", ";", "case", "Month", "::", "SEPTEMBER", ":", "return", "244", "+", "$", "leap", ";", "case", "Month", "::", "OCTOBER", ":", "return", "274", "+", "$", "leap", ";", "case", "Month", "::", "NOVEMBER", ":", "return", "305", "+", "$", "leap", ";", "}", "return", "335", "+", "$", "leap", ";", "}" ]
Returns the day-of-year for the first day of this month. This returns the day-of-year that this month begins on, using the leap year flag to determine the length of February. @param bool $leapYear @return int
[ "Returns", "the", "day", "-", "of", "-", "year", "for", "the", "first", "day", "of", "this", "month", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/Month.php#L176-L206
train
brick/date-time
src/Month.php
Month.getLength
public function getLength(bool $leapYear) : int { switch ($this->month) { case Month::FEBRUARY: return ($leapYear ? 29 : 28); case Month::APRIL: case Month::JUNE: case Month::SEPTEMBER: case Month::NOVEMBER: return 30; default: return 31; } }
php
public function getLength(bool $leapYear) : int { switch ($this->month) { case Month::FEBRUARY: return ($leapYear ? 29 : 28); case Month::APRIL: case Month::JUNE: case Month::SEPTEMBER: case Month::NOVEMBER: return 30; default: return 31; } }
[ "public", "function", "getLength", "(", "bool", "$", "leapYear", ")", ":", "int", "{", "switch", "(", "$", "this", "->", "month", ")", "{", "case", "Month", "::", "FEBRUARY", ":", "return", "(", "$", "leapYear", "?", "29", ":", "28", ")", ";", "case", "Month", "::", "APRIL", ":", "case", "Month", "::", "JUNE", ":", "case", "Month", "::", "SEPTEMBER", ":", "case", "Month", "::", "NOVEMBER", ":", "return", "30", ";", "default", ":", "return", "31", ";", "}", "}" ]
Returns the length of this month in days. This takes a flag to determine whether to return the length for a leap year or not. February has 28 days in a standard year and 29 days in a leap year. April, June, September and November have 30 days. All other months have 31 days. @param bool $leapYear @return int
[ "Returns", "the", "length", "of", "this", "month", "in", "days", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/Month.php#L221-L234
train
uecode/qpush-bundle
src/Provider/DoctrineProvider.php
DoctrineProvider.create
public function create() { $sm = $this->em->getConnection()->getSchemaManager(); $table = $this->em->getClassMetadata(self::$entityName)->getTableName(); return $sm->tablesExist(array($table)); }
php
public function create() { $sm = $this->em->getConnection()->getSchemaManager(); $table = $this->em->getClassMetadata(self::$entityName)->getTableName(); return $sm->tablesExist(array($table)); }
[ "public", "function", "create", "(", ")", "{", "$", "sm", "=", "$", "this", "->", "em", "->", "getConnection", "(", ")", "->", "getSchemaManager", "(", ")", ";", "$", "table", "=", "$", "this", "->", "em", "->", "getClassMetadata", "(", "self", "::", "$", "entityName", ")", "->", "getTableName", "(", ")", ";", "return", "$", "sm", "->", "tablesExist", "(", "array", "(", "$", "table", ")", ")", ";", "}" ]
Creates the Queue Checks to see if the underlying table has been created or not @return bool
[ "Creates", "the", "Queue", "Checks", "to", "see", "if", "the", "underlying", "table", "has", "been", "created", "or", "not" ]
cf4540278f1344bf7fd3601789cb10da5d706602
https://github.com/uecode/qpush-bundle/blob/cf4540278f1344bf7fd3601789cb10da5d706602/src/Provider/DoctrineProvider.php#L128-L134
train
uecode/qpush-bundle
src/Provider/DoctrineProvider.php
DoctrineProvider.publish
public function publish(array $message, array $options = []) { if (!$this->em) { return ''; } $doctrineMessage = new DoctrineMessage(); $doctrineMessage->setQueue($this->name) ->setDelivered(false) ->setMessage($message) ->setLength(strlen(serialize($message))); $this->em->persist($doctrineMessage); $this->em->flush(); return (string) $doctrineMessage->getId(); }
php
public function publish(array $message, array $options = []) { if (!$this->em) { return ''; } $doctrineMessage = new DoctrineMessage(); $doctrineMessage->setQueue($this->name) ->setDelivered(false) ->setMessage($message) ->setLength(strlen(serialize($message))); $this->em->persist($doctrineMessage); $this->em->flush(); return (string) $doctrineMessage->getId(); }
[ "public", "function", "publish", "(", "array", "$", "message", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "$", "this", "->", "em", ")", "{", "return", "''", ";", "}", "$", "doctrineMessage", "=", "new", "DoctrineMessage", "(", ")", ";", "$", "doctrineMessage", "->", "setQueue", "(", "$", "this", "->", "name", ")", "->", "setDelivered", "(", "false", ")", "->", "setMessage", "(", "$", "message", ")", "->", "setLength", "(", "strlen", "(", "serialize", "(", "$", "message", ")", ")", ")", ";", "$", "this", "->", "em", "->", "persist", "(", "$", "doctrineMessage", ")", ";", "$", "this", "->", "em", "->", "flush", "(", ")", ";", "return", "(", "string", ")", "$", "doctrineMessage", "->", "getId", "(", ")", ";", "}" ]
Publishes a message to the Queue This method should return a string MessageId or Response @param array $message The message to queue @param array $options An array of options that override the queue defaults @return string
[ "Publishes", "a", "message", "to", "the", "Queue" ]
cf4540278f1344bf7fd3601789cb10da5d706602
https://github.com/uecode/qpush-bundle/blob/cf4540278f1344bf7fd3601789cb10da5d706602/src/Provider/DoctrineProvider.php#L146-L162
train
uecode/qpush-bundle
src/Provider/DoctrineProvider.php
DoctrineProvider.receive
public function receive(array $options = []) { if (!$this->em) { return []; } $doctrineMessages = $this->repository->findBy( array('delivered' => false, 'queue' => $this->name), array('id' => 'ASC') ); $messages = []; foreach ($doctrineMessages as $doctrineMessage) { $messages[] = new Message($doctrineMessage->getId(), $doctrineMessage->getMessage(), []); $doctrineMessage->setDelivered(true); } $this->em->flush(); return $messages; }
php
public function receive(array $options = []) { if (!$this->em) { return []; } $doctrineMessages = $this->repository->findBy( array('delivered' => false, 'queue' => $this->name), array('id' => 'ASC') ); $messages = []; foreach ($doctrineMessages as $doctrineMessage) { $messages[] = new Message($doctrineMessage->getId(), $doctrineMessage->getMessage(), []); $doctrineMessage->setDelivered(true); } $this->em->flush(); return $messages; }
[ "public", "function", "receive", "(", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "$", "this", "->", "em", ")", "{", "return", "[", "]", ";", "}", "$", "doctrineMessages", "=", "$", "this", "->", "repository", "->", "findBy", "(", "array", "(", "'delivered'", "=>", "false", ",", "'queue'", "=>", "$", "this", "->", "name", ")", ",", "array", "(", "'id'", "=>", "'ASC'", ")", ")", ";", "$", "messages", "=", "[", "]", ";", "foreach", "(", "$", "doctrineMessages", "as", "$", "doctrineMessage", ")", "{", "$", "messages", "[", "]", "=", "new", "Message", "(", "$", "doctrineMessage", "->", "getId", "(", ")", ",", "$", "doctrineMessage", "->", "getMessage", "(", ")", ",", "[", "]", ")", ";", "$", "doctrineMessage", "->", "setDelivered", "(", "true", ")", ";", "}", "$", "this", "->", "em", "->", "flush", "(", ")", ";", "return", "$", "messages", ";", "}" ]
Polls the Queue for Messages Depending on the Provider, this method may keep the connection open for a configurable amount of time, to allow for long polling. In most cases, this method is not meant to be used to long poll indefinitely, but should return in reasonable amount of time @param array $options An array of options that override the queue defaults @return array
[ "Polls", "the", "Queue", "for", "Messages" ]
cf4540278f1344bf7fd3601789cb10da5d706602
https://github.com/uecode/qpush-bundle/blob/cf4540278f1344bf7fd3601789cb10da5d706602/src/Provider/DoctrineProvider.php#L176-L194
train
uecode/qpush-bundle
src/Provider/DoctrineProvider.php
DoctrineProvider.delete
public function delete($id) { $doctrineMessage = $this->repository->findById($id); $doctrineMessage->setDelivered(true); $this->em->flush(); return true; }
php
public function delete($id) { $doctrineMessage = $this->repository->findById($id); $doctrineMessage->setDelivered(true); $this->em->flush(); return true; }
[ "public", "function", "delete", "(", "$", "id", ")", "{", "$", "doctrineMessage", "=", "$", "this", "->", "repository", "->", "findById", "(", "$", "id", ")", ";", "$", "doctrineMessage", "->", "setDelivered", "(", "true", ")", ";", "$", "this", "->", "em", "->", "flush", "(", ")", ";", "return", "true", ";", "}" ]
Deletes the Queue Message @param mixed $id A message identifier or resource
[ "Deletes", "the", "Queue", "Message" ]
cf4540278f1344bf7fd3601789cb10da5d706602
https://github.com/uecode/qpush-bundle/blob/cf4540278f1344bf7fd3601789cb10da5d706602/src/Provider/DoctrineProvider.php#L201-L208
train
uecode/qpush-bundle
src/Provider/DoctrineProvider.php
DoctrineProvider.destroy
public function destroy() { $qb = $this->repository->createQueryBuilder('dm'); $qb->delete(); $qb->where('dm.queue = :queue'); $qb->setParameter('queue', $this->name); $qb->getQuery()->execute(); return true; }
php
public function destroy() { $qb = $this->repository->createQueryBuilder('dm'); $qb->delete(); $qb->where('dm.queue = :queue'); $qb->setParameter('queue', $this->name); $qb->getQuery()->execute(); return true; }
[ "public", "function", "destroy", "(", ")", "{", "$", "qb", "=", "$", "this", "->", "repository", "->", "createQueryBuilder", "(", "'dm'", ")", ";", "$", "qb", "->", "delete", "(", ")", ";", "$", "qb", "->", "where", "(", "'dm.queue = :queue'", ")", ";", "$", "qb", "->", "setParameter", "(", "'queue'", ",", "$", "this", "->", "name", ")", ";", "$", "qb", "->", "getQuery", "(", ")", "->", "execute", "(", ")", ";", "return", "true", ";", "}" ]
Destroys a Queue and clears any Queue related Cache @return bool
[ "Destroys", "a", "Queue", "and", "clears", "any", "Queue", "related", "Cache" ]
cf4540278f1344bf7fd3601789cb10da5d706602
https://github.com/uecode/qpush-bundle/blob/cf4540278f1344bf7fd3601789cb10da5d706602/src/Provider/DoctrineProvider.php#L215-L224
train
uecode/qpush-bundle
src/Provider/DoctrineProvider.php
DoctrineProvider.findBy
public function findBy($data) { $qb = $this->repository->createQueryBuilder('p'); $qb->select('p'); $qb->where('p.queue = :queue'); $qb->setParameter('queue', $this->name); $field = (isset($data['field'])) ? $data['field'] : 'message'; if (isset($data['search']) && $data['search'] !== null) { $qb->andWhere('p.' . $field . ' LIKE :contains'); $qb->setParameter('contains', '%' . $data['search'] . '%'); } if (isset($data['from']) && $data['from'] !== null && isset($data['to']) && $data['to'] !== null) { $qb->andWhere('p.created BETWEEN :from AND :to'); $qb->setParameter('from', $data['from']); $qb->setParameter('to', $data['to']); } return $qb->getQuery(); }
php
public function findBy($data) { $qb = $this->repository->createQueryBuilder('p'); $qb->select('p'); $qb->where('p.queue = :queue'); $qb->setParameter('queue', $this->name); $field = (isset($data['field'])) ? $data['field'] : 'message'; if (isset($data['search']) && $data['search'] !== null) { $qb->andWhere('p.' . $field . ' LIKE :contains'); $qb->setParameter('contains', '%' . $data['search'] . '%'); } if (isset($data['from']) && $data['from'] !== null && isset($data['to']) && $data['to'] !== null) { $qb->andWhere('p.created BETWEEN :from AND :to'); $qb->setParameter('from', $data['from']); $qb->setParameter('to', $data['to']); } return $qb->getQuery(); }
[ "public", "function", "findBy", "(", "$", "data", ")", "{", "$", "qb", "=", "$", "this", "->", "repository", "->", "createQueryBuilder", "(", "'p'", ")", ";", "$", "qb", "->", "select", "(", "'p'", ")", ";", "$", "qb", "->", "where", "(", "'p.queue = :queue'", ")", ";", "$", "qb", "->", "setParameter", "(", "'queue'", ",", "$", "this", "->", "name", ")", ";", "$", "field", "=", "(", "isset", "(", "$", "data", "[", "'field'", "]", ")", ")", "?", "$", "data", "[", "'field'", "]", ":", "'message'", ";", "if", "(", "isset", "(", "$", "data", "[", "'search'", "]", ")", "&&", "$", "data", "[", "'search'", "]", "!==", "null", ")", "{", "$", "qb", "->", "andWhere", "(", "'p.'", ".", "$", "field", ".", "' LIKE :contains'", ")", ";", "$", "qb", "->", "setParameter", "(", "'contains'", ",", "'%'", ".", "$", "data", "[", "'search'", "]", ".", "'%'", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'from'", "]", ")", "&&", "$", "data", "[", "'from'", "]", "!==", "null", "&&", "isset", "(", "$", "data", "[", "'to'", "]", ")", "&&", "$", "data", "[", "'to'", "]", "!==", "null", ")", "{", "$", "qb", "->", "andWhere", "(", "'p.created BETWEEN :from AND :to'", ")", ";", "$", "qb", "->", "setParameter", "(", "'from'", ",", "$", "data", "[", "'from'", "]", ")", ";", "$", "qb", "->", "setParameter", "(", "'to'", ",", "$", "data", "[", "'to'", "]", ")", ";", "}", "return", "$", "qb", "->", "getQuery", "(", ")", ";", "}" ]
Returns a query of the message queue @param array $data ['field'=>'id', 'search'=>'text', 'to'=>date, from=>date] @return Query
[ "Returns", "a", "query", "of", "the", "message", "queue" ]
cf4540278f1344bf7fd3601789cb10da5d706602
https://github.com/uecode/qpush-bundle/blob/cf4540278f1344bf7fd3601789cb10da5d706602/src/Provider/DoctrineProvider.php#L245-L266
train
brick/date-time
src/Instant.php
Instant.of
public static function of(int $epochSecond, int $nanoAdjustment = 0) : Instant { $nanos = $nanoAdjustment % LocalTime::NANOS_PER_SECOND; $epochSecond += ($nanoAdjustment - $nanos) / LocalTime::NANOS_PER_SECOND; if ($nanos < 0) { $nanos += LocalTime::NANOS_PER_SECOND; $epochSecond--; } return new Instant($epochSecond, $nanos); }
php
public static function of(int $epochSecond, int $nanoAdjustment = 0) : Instant { $nanos = $nanoAdjustment % LocalTime::NANOS_PER_SECOND; $epochSecond += ($nanoAdjustment - $nanos) / LocalTime::NANOS_PER_SECOND; if ($nanos < 0) { $nanos += LocalTime::NANOS_PER_SECOND; $epochSecond--; } return new Instant($epochSecond, $nanos); }
[ "public", "static", "function", "of", "(", "int", "$", "epochSecond", ",", "int", "$", "nanoAdjustment", "=", "0", ")", ":", "Instant", "{", "$", "nanos", "=", "$", "nanoAdjustment", "%", "LocalTime", "::", "NANOS_PER_SECOND", ";", "$", "epochSecond", "+=", "(", "$", "nanoAdjustment", "-", "$", "nanos", ")", "/", "LocalTime", "::", "NANOS_PER_SECOND", ";", "if", "(", "$", "nanos", "<", "0", ")", "{", "$", "nanos", "+=", "LocalTime", "::", "NANOS_PER_SECOND", ";", "$", "epochSecond", "--", ";", "}", "return", "new", "Instant", "(", "$", "epochSecond", ",", "$", "nanos", ")", ";", "}" ]
Returns an Instant representing a number of seconds and an adjustment in nanoseconds. This method allows an arbitrary number of nanoseconds to be passed in. The factory will alter the values of the second and nanosecond in order to ensure that the stored nanosecond is in the range 0 to 999,999,999. For example, the following will result in the exactly the same duration: * Instant::of(3, 1); * Duration::of(4, -999999999); * Duration::of(2, 1000000001); @param int $epochSecond The number of seconds since the UNIX epoch of 1970-01-01T00:00:00Z. @param int $nanoAdjustment The adjustment to the epoch second in nanoseconds. @return Instant
[ "Returns", "an", "Instant", "representing", "a", "number", "of", "seconds", "and", "an", "adjustment", "in", "nanoseconds", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/Instant.php#L61-L72
train
brick/date-time
src/Instant.php
Instant.withEpochSecond
public function withEpochSecond(int $epochSecond) : Instant { if ($epochSecond === $this->epochSecond) { return $this; } return new Instant($epochSecond, $this->nano); }
php
public function withEpochSecond(int $epochSecond) : Instant { if ($epochSecond === $this->epochSecond) { return $this; } return new Instant($epochSecond, $this->nano); }
[ "public", "function", "withEpochSecond", "(", "int", "$", "epochSecond", ")", ":", "Instant", "{", "if", "(", "$", "epochSecond", "===", "$", "this", "->", "epochSecond", ")", "{", "return", "$", "this", ";", "}", "return", "new", "Instant", "(", "$", "epochSecond", ",", "$", "this", "->", "nano", ")", ";", "}" ]
Returns a copy of this Instant with epoch second altered. @param int $epochSecond @return Instant
[ "Returns", "a", "copy", "of", "this", "Instant", "with", "epoch", "second", "altered", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/Instant.php#L232-L239
train
brick/date-time
src/Instant.php
Instant.withNano
public function withNano(int $nano) : Instant { if ($nano === $this->nano) { return $this; } Field\NanoOfSecond::check($nano); return new Instant($this->epochSecond, $nano); }
php
public function withNano(int $nano) : Instant { if ($nano === $this->nano) { return $this; } Field\NanoOfSecond::check($nano); return new Instant($this->epochSecond, $nano); }
[ "public", "function", "withNano", "(", "int", "$", "nano", ")", ":", "Instant", "{", "if", "(", "$", "nano", "===", "$", "this", "->", "nano", ")", "{", "return", "$", "this", ";", "}", "Field", "\\", "NanoOfSecond", "::", "check", "(", "$", "nano", ")", ";", "return", "new", "Instant", "(", "$", "this", "->", "epochSecond", ",", "$", "nano", ")", ";", "}" ]
Returns a copy of this Instant with the nano-of-second altered. @param int $nano @return Instant @throws DateTimeException If the nano-of-second if not valid.
[ "Returns", "a", "copy", "of", "this", "Instant", "with", "the", "nano", "-", "of", "-", "second", "altered", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/Instant.php#L250-L259
train
brick/date-time
src/Instant.php
Instant.compareTo
public function compareTo(Instant $that) : int { $seconds = $this->getEpochSecond() - $that->getEpochSecond(); if ($seconds !== 0) { return $seconds > 0 ? 1 : -1; } $nanos = $this->getNano() - $that->getNano(); if ($nanos !== 0) { return $nanos > 0 ? 1 : -1; } return 0; }
php
public function compareTo(Instant $that) : int { $seconds = $this->getEpochSecond() - $that->getEpochSecond(); if ($seconds !== 0) { return $seconds > 0 ? 1 : -1; } $nanos = $this->getNano() - $that->getNano(); if ($nanos !== 0) { return $nanos > 0 ? 1 : -1; } return 0; }
[ "public", "function", "compareTo", "(", "Instant", "$", "that", ")", ":", "int", "{", "$", "seconds", "=", "$", "this", "->", "getEpochSecond", "(", ")", "-", "$", "that", "->", "getEpochSecond", "(", ")", ";", "if", "(", "$", "seconds", "!==", "0", ")", "{", "return", "$", "seconds", ">", "0", "?", "1", ":", "-", "1", ";", "}", "$", "nanos", "=", "$", "this", "->", "getNano", "(", ")", "-", "$", "that", "->", "getNano", "(", ")", ";", "if", "(", "$", "nanos", "!==", "0", ")", "{", "return", "$", "nanos", ">", "0", "?", "1", ":", "-", "1", ";", "}", "return", "0", ";", "}" ]
Compares this instant with another. @param Instant $that @return int [-1,0,1] If this instant is before, on, or after the given instant.
[ "Compares", "this", "instant", "with", "another", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/Instant.php#L294-L309
train
brick/date-time
src/Instant.php
Instant.isFuture
public function isFuture(Clock $clock = null) : bool { return $this->isAfter(Instant::now($clock)); }
php
public function isFuture(Clock $clock = null) : bool { return $this->isAfter(Instant::now($clock)); }
[ "public", "function", "isFuture", "(", "Clock", "$", "clock", "=", "null", ")", ":", "bool", "{", "return", "$", "this", "->", "isAfter", "(", "Instant", "::", "now", "(", "$", "clock", ")", ")", ";", "}" ]
Returns whether this instant is in the future, according to the given clock. If no clock is provided, the system clock is used. @param Clock|null $clock @return bool
[ "Returns", "whether", "this", "instant", "is", "in", "the", "future", "according", "to", "the", "given", "clock", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/Instant.php#L402-L405
train
brick/date-time
src/Instant.php
Instant.isPast
public function isPast(Clock $clock = null) : bool { return $this->isBefore(Instant::now($clock)); }
php
public function isPast(Clock $clock = null) : bool { return $this->isBefore(Instant::now($clock)); }
[ "public", "function", "isPast", "(", "Clock", "$", "clock", "=", "null", ")", ":", "bool", "{", "return", "$", "this", "->", "isBefore", "(", "Instant", "::", "now", "(", "$", "clock", ")", ")", ";", "}" ]
Returns whether this instant is in the past, according to the given clock. If no clock is provided, the system clock is used. @param Clock|null $clock @return bool
[ "Returns", "whether", "this", "instant", "is", "in", "the", "past", "according", "to", "the", "given", "clock", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/Instant.php#L416-L419
train
brick/date-time
src/Instant.php
Instant.toDecimal
public function toDecimal() : string { $result = (string) $this->epochSecond; if ($this->nano !== 0) { $nano = (string) $this->nano; $nano = str_pad($nano, 9, '0', STR_PAD_LEFT); $nano = rtrim($nano, '0'); $result .= '.' . $nano; } return $result; }
php
public function toDecimal() : string { $result = (string) $this->epochSecond; if ($this->nano !== 0) { $nano = (string) $this->nano; $nano = str_pad($nano, 9, '0', STR_PAD_LEFT); $nano = rtrim($nano, '0'); $result .= '.' . $nano; } return $result; }
[ "public", "function", "toDecimal", "(", ")", ":", "string", "{", "$", "result", "=", "(", "string", ")", "$", "this", "->", "epochSecond", ";", "if", "(", "$", "this", "->", "nano", "!==", "0", ")", "{", "$", "nano", "=", "(", "string", ")", "$", "this", "->", "nano", ";", "$", "nano", "=", "str_pad", "(", "$", "nano", ",", "9", ",", "'0'", ",", "STR_PAD_LEFT", ")", ";", "$", "nano", "=", "rtrim", "(", "$", "nano", ",", "'0'", ")", ";", "$", "result", ".=", "'.'", ".", "$", "nano", ";", "}", "return", "$", "result", ";", "}" ]
Returns a decimal representation of the timestamp represented by this instant. The output does not have trailing decimal zeros. Examples: `123456789`, `123456789.5`, `123456789.000000001`. @return string
[ "Returns", "a", "decimal", "representation", "of", "the", "timestamp", "represented", "by", "this", "instant", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/Instant.php#L442-L455
train
brick/date-time
src/Parser/IsoParsers.php
IsoParsers.localDate
public static function localDate() : PatternParser { static $parser; if ($parser) { return $parser; } return $parser = (new PatternParserBuilder()) ->appendCapturePattern(Year::PATTERN, Year::NAME) ->appendLiteral('-') ->appendCapturePattern(MonthOfYear::PATTERN, MonthOfYear::NAME) ->appendLiteral('-') ->appendCapturePattern(DayOfMonth::PATTERN, DayOfMonth::NAME) ->toParser(); }
php
public static function localDate() : PatternParser { static $parser; if ($parser) { return $parser; } return $parser = (new PatternParserBuilder()) ->appendCapturePattern(Year::PATTERN, Year::NAME) ->appendLiteral('-') ->appendCapturePattern(MonthOfYear::PATTERN, MonthOfYear::NAME) ->appendLiteral('-') ->appendCapturePattern(DayOfMonth::PATTERN, DayOfMonth::NAME) ->toParser(); }
[ "public", "static", "function", "localDate", "(", ")", ":", "PatternParser", "{", "static", "$", "parser", ";", "if", "(", "$", "parser", ")", "{", "return", "$", "parser", ";", "}", "return", "$", "parser", "=", "(", "new", "PatternParserBuilder", "(", ")", ")", "->", "appendCapturePattern", "(", "Year", "::", "PATTERN", ",", "Year", "::", "NAME", ")", "->", "appendLiteral", "(", "'-'", ")", "->", "appendCapturePattern", "(", "MonthOfYear", "::", "PATTERN", ",", "MonthOfYear", "::", "NAME", ")", "->", "appendLiteral", "(", "'-'", ")", "->", "appendCapturePattern", "(", "DayOfMonth", "::", "PATTERN", ",", "DayOfMonth", "::", "NAME", ")", "->", "toParser", "(", ")", ";", "}" ]
Returns a parser for an ISO local date such as `2014-12-31`. @return PatternParser
[ "Returns", "a", "parser", "for", "an", "ISO", "local", "date", "such", "as", "2014", "-", "12", "-", "31", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/Parser/IsoParsers.php#L37-L52
train
brick/date-time
src/Parser/IsoParsers.php
IsoParsers.yearMonth
public static function yearMonth() : PatternParser { static $parser; if ($parser) { return $parser; } return $parser = (new PatternParserBuilder()) ->appendCapturePattern(Year::PATTERN, Year::NAME) ->appendLiteral('-') ->appendCapturePattern(MonthOfYear::PATTERN, MonthOfYear::NAME) ->toParser(); }
php
public static function yearMonth() : PatternParser { static $parser; if ($parser) { return $parser; } return $parser = (new PatternParserBuilder()) ->appendCapturePattern(Year::PATTERN, Year::NAME) ->appendLiteral('-') ->appendCapturePattern(MonthOfYear::PATTERN, MonthOfYear::NAME) ->toParser(); }
[ "public", "static", "function", "yearMonth", "(", ")", ":", "PatternParser", "{", "static", "$", "parser", ";", "if", "(", "$", "parser", ")", "{", "return", "$", "parser", ";", "}", "return", "$", "parser", "=", "(", "new", "PatternParserBuilder", "(", ")", ")", "->", "appendCapturePattern", "(", "Year", "::", "PATTERN", ",", "Year", "::", "NAME", ")", "->", "appendLiteral", "(", "'-'", ")", "->", "appendCapturePattern", "(", "MonthOfYear", "::", "PATTERN", ",", "MonthOfYear", "::", "NAME", ")", "->", "toParser", "(", ")", ";", "}" ]
Returns a parser for a year-month such as `2014-12`. @return PatternParser
[ "Returns", "a", "parser", "for", "a", "year", "-", "month", "such", "as", "2014", "-", "12", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/Parser/IsoParsers.php#L178-L191
train
brick/date-time
src/Parser/IsoParsers.php
IsoParsers.monthDay
public static function monthDay() : PatternParser { static $parser; if ($parser) { return $parser; } return $parser = (new PatternParserBuilder()) ->appendLiteral('--') ->appendCapturePattern(MonthOfYear::PATTERN, MonthOfYear::NAME) ->appendLiteral('-') ->appendCapturePattern(DayOfMonth::PATTERN, DayOfMonth::NAME) ->toParser(); }
php
public static function monthDay() : PatternParser { static $parser; if ($parser) { return $parser; } return $parser = (new PatternParserBuilder()) ->appendLiteral('--') ->appendCapturePattern(MonthOfYear::PATTERN, MonthOfYear::NAME) ->appendLiteral('-') ->appendCapturePattern(DayOfMonth::PATTERN, DayOfMonth::NAME) ->toParser(); }
[ "public", "static", "function", "monthDay", "(", ")", ":", "PatternParser", "{", "static", "$", "parser", ";", "if", "(", "$", "parser", ")", "{", "return", "$", "parser", ";", "}", "return", "$", "parser", "=", "(", "new", "PatternParserBuilder", "(", ")", ")", "->", "appendLiteral", "(", "'--'", ")", "->", "appendCapturePattern", "(", "MonthOfYear", "::", "PATTERN", ",", "MonthOfYear", "::", "NAME", ")", "->", "appendLiteral", "(", "'-'", ")", "->", "appendCapturePattern", "(", "DayOfMonth", "::", "PATTERN", ",", "DayOfMonth", "::", "NAME", ")", "->", "toParser", "(", ")", ";", "}" ]
Returns a parser for a month-day such as `12-31`. @return PatternParser
[ "Returns", "a", "parser", "for", "a", "month", "-", "day", "such", "as", "12", "-", "31", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/Parser/IsoParsers.php#L198-L212
train
uecode/qpush-bundle
src/EventListener/RequestListener.php
RequestListener.onKernelRequest
public function onKernelRequest(GetResponseEvent $event) { if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) { return; } if ($event->getRequest()->headers->has('x-amz-sns-message-type')) { $result = $this->handleSnsNotifications($event); $event->setResponse(new Response($result, 200)); } if ($event->getRequest()->headers->has('iron-message-id')) { $result = $this->handleIronMqNotifications($event); $event->setResponse(new Response($result, 200)); } }
php
public function onKernelRequest(GetResponseEvent $event) { if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) { return; } if ($event->getRequest()->headers->has('x-amz-sns-message-type')) { $result = $this->handleSnsNotifications($event); $event->setResponse(new Response($result, 200)); } if ($event->getRequest()->headers->has('iron-message-id')) { $result = $this->handleIronMqNotifications($event); $event->setResponse(new Response($result, 200)); } }
[ "public", "function", "onKernelRequest", "(", "GetResponseEvent", "$", "event", ")", "{", "if", "(", "HttpKernel", "::", "MASTER_REQUEST", "!=", "$", "event", "->", "getRequestType", "(", ")", ")", "{", "return", ";", "}", "if", "(", "$", "event", "->", "getRequest", "(", ")", "->", "headers", "->", "has", "(", "'x-amz-sns-message-type'", ")", ")", "{", "$", "result", "=", "$", "this", "->", "handleSnsNotifications", "(", "$", "event", ")", ";", "$", "event", "->", "setResponse", "(", "new", "Response", "(", "$", "result", ",", "200", ")", ")", ";", "}", "if", "(", "$", "event", "->", "getRequest", "(", ")", "->", "headers", "->", "has", "(", "'iron-message-id'", ")", ")", "{", "$", "result", "=", "$", "this", "->", "handleIronMqNotifications", "(", "$", "event", ")", ";", "$", "event", "->", "setResponse", "(", "new", "Response", "(", "$", "result", ",", "200", ")", ")", ";", "}", "}" ]
Kernel Request Event Handler for QPush Notifications @param GetResponseEvent $event The Kernel Request's GetResponseEvent
[ "Kernel", "Request", "Event", "Handler", "for", "QPush", "Notifications" ]
cf4540278f1344bf7fd3601789cb10da5d706602
https://github.com/uecode/qpush-bundle/blob/cf4540278f1344bf7fd3601789cb10da5d706602/src/EventListener/RequestListener.php#L59-L73
train
uecode/qpush-bundle
src/EventListener/RequestListener.php
RequestListener.handleIronMqNotifications
private function handleIronMqNotifications(GetResponseEvent $event) { $headers = $event->getRequest()->headers; $messageId = $headers->get('iron-message-id'); if (null === ($message = json_decode($event->getRequest()->getContent(), true))) { throw new \InvalidArgumentException('Unable to decode JSON'); } $queue = $this->getIronMqQueueName($event, $message); $metadata = [ 'iron-subscriber-message-id' => $headers->get('iron-subscriber-message-id'), 'iron-subscriber-message-url' => $headers->get('iron-subscriber-message-url') ]; unset($message['_qpush_queue']); $notification = new Notification( $messageId, $message, $metadata ); $this->dispatcher->dispatch( Events::Notification($queue), new NotificationEvent($queue, NotificationEvent::TYPE_MESSAGE, $notification) ); return "IronMQ Notification Received."; }
php
private function handleIronMqNotifications(GetResponseEvent $event) { $headers = $event->getRequest()->headers; $messageId = $headers->get('iron-message-id'); if (null === ($message = json_decode($event->getRequest()->getContent(), true))) { throw new \InvalidArgumentException('Unable to decode JSON'); } $queue = $this->getIronMqQueueName($event, $message); $metadata = [ 'iron-subscriber-message-id' => $headers->get('iron-subscriber-message-id'), 'iron-subscriber-message-url' => $headers->get('iron-subscriber-message-url') ]; unset($message['_qpush_queue']); $notification = new Notification( $messageId, $message, $metadata ); $this->dispatcher->dispatch( Events::Notification($queue), new NotificationEvent($queue, NotificationEvent::TYPE_MESSAGE, $notification) ); return "IronMQ Notification Received."; }
[ "private", "function", "handleIronMqNotifications", "(", "GetResponseEvent", "$", "event", ")", "{", "$", "headers", "=", "$", "event", "->", "getRequest", "(", ")", "->", "headers", ";", "$", "messageId", "=", "$", "headers", "->", "get", "(", "'iron-message-id'", ")", ";", "if", "(", "null", "===", "(", "$", "message", "=", "json_decode", "(", "$", "event", "->", "getRequest", "(", ")", "->", "getContent", "(", ")", ",", "true", ")", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Unable to decode JSON'", ")", ";", "}", "$", "queue", "=", "$", "this", "->", "getIronMqQueueName", "(", "$", "event", ",", "$", "message", ")", ";", "$", "metadata", "=", "[", "'iron-subscriber-message-id'", "=>", "$", "headers", "->", "get", "(", "'iron-subscriber-message-id'", ")", ",", "'iron-subscriber-message-url'", "=>", "$", "headers", "->", "get", "(", "'iron-subscriber-message-url'", ")", "]", ";", "unset", "(", "$", "message", "[", "'_qpush_queue'", "]", ")", ";", "$", "notification", "=", "new", "Notification", "(", "$", "messageId", ",", "$", "message", ",", "$", "metadata", ")", ";", "$", "this", "->", "dispatcher", "->", "dispatch", "(", "Events", "::", "Notification", "(", "$", "queue", ")", ",", "new", "NotificationEvent", "(", "$", "queue", ",", "NotificationEvent", "::", "TYPE_MESSAGE", ",", "$", "notification", ")", ")", ";", "return", "\"IronMQ Notification Received.\"", ";", "}" ]
Handles Messages sent from a IronMQ Push Queue @param GetResponseEvent $event The Kernel Request's GetResponseEvent @return string|void
[ "Handles", "Messages", "sent", "from", "a", "IronMQ", "Push", "Queue" ]
cf4540278f1344bf7fd3601789cb10da5d706602
https://github.com/uecode/qpush-bundle/blob/cf4540278f1344bf7fd3601789cb10da5d706602/src/EventListener/RequestListener.php#L81-L109
train
uecode/qpush-bundle
src/EventListener/RequestListener.php
RequestListener.handleSnsNotifications
private function handleSnsNotifications(GetResponseEvent $event) { $notification = json_decode((string) $event->getRequest()->getContent(), true); $type = $event->getRequest()->headers->get('x-amz-sns-message-type'); $metadata = [ 'Type' => $notification['Type'], 'TopicArn' => $notification['TopicArn'], 'Timestamp' => $notification['Timestamp'], ]; if ($type === 'Notification') { // We put the queue name in the Subject field $queue = $notification['Subject']; $metadata['Subject'] = $queue; $notification = new Notification( $notification['MessageId'], $notification['Message'], $metadata ); $this->dispatcher->dispatch( Events::Notification($queue), new NotificationEvent($queue, NotificationEvent::TYPE_MESSAGE, $notification) ); return "SNS Message Notification Received."; } // For subscription notifications, we need to parse the Queue from // the Topic ARN $arnParts = explode(':', $notification['TopicArn']); $last = end($arnParts); $queue = str_replace('qpush_', '', $last); // Get the token for the Subscription Confirmation $metadata['Token'] = $notification['Token']; $notification = new Notification( $notification['MessageId'], $notification['Message'], $metadata ); $this->dispatcher->dispatch( Events::Notification($queue), new NotificationEvent($queue, NotificationEvent::TYPE_SUBSCRIPTION, $notification) ); return "SNS Subscription Confirmation Received."; }
php
private function handleSnsNotifications(GetResponseEvent $event) { $notification = json_decode((string) $event->getRequest()->getContent(), true); $type = $event->getRequest()->headers->get('x-amz-sns-message-type'); $metadata = [ 'Type' => $notification['Type'], 'TopicArn' => $notification['TopicArn'], 'Timestamp' => $notification['Timestamp'], ]; if ($type === 'Notification') { // We put the queue name in the Subject field $queue = $notification['Subject']; $metadata['Subject'] = $queue; $notification = new Notification( $notification['MessageId'], $notification['Message'], $metadata ); $this->dispatcher->dispatch( Events::Notification($queue), new NotificationEvent($queue, NotificationEvent::TYPE_MESSAGE, $notification) ); return "SNS Message Notification Received."; } // For subscription notifications, we need to parse the Queue from // the Topic ARN $arnParts = explode(':', $notification['TopicArn']); $last = end($arnParts); $queue = str_replace('qpush_', '', $last); // Get the token for the Subscription Confirmation $metadata['Token'] = $notification['Token']; $notification = new Notification( $notification['MessageId'], $notification['Message'], $metadata ); $this->dispatcher->dispatch( Events::Notification($queue), new NotificationEvent($queue, NotificationEvent::TYPE_SUBSCRIPTION, $notification) ); return "SNS Subscription Confirmation Received."; }
[ "private", "function", "handleSnsNotifications", "(", "GetResponseEvent", "$", "event", ")", "{", "$", "notification", "=", "json_decode", "(", "(", "string", ")", "$", "event", "->", "getRequest", "(", ")", "->", "getContent", "(", ")", ",", "true", ")", ";", "$", "type", "=", "$", "event", "->", "getRequest", "(", ")", "->", "headers", "->", "get", "(", "'x-amz-sns-message-type'", ")", ";", "$", "metadata", "=", "[", "'Type'", "=>", "$", "notification", "[", "'Type'", "]", ",", "'TopicArn'", "=>", "$", "notification", "[", "'TopicArn'", "]", ",", "'Timestamp'", "=>", "$", "notification", "[", "'Timestamp'", "]", ",", "]", ";", "if", "(", "$", "type", "===", "'Notification'", ")", "{", "// We put the queue name in the Subject field", "$", "queue", "=", "$", "notification", "[", "'Subject'", "]", ";", "$", "metadata", "[", "'Subject'", "]", "=", "$", "queue", ";", "$", "notification", "=", "new", "Notification", "(", "$", "notification", "[", "'MessageId'", "]", ",", "$", "notification", "[", "'Message'", "]", ",", "$", "metadata", ")", ";", "$", "this", "->", "dispatcher", "->", "dispatch", "(", "Events", "::", "Notification", "(", "$", "queue", ")", ",", "new", "NotificationEvent", "(", "$", "queue", ",", "NotificationEvent", "::", "TYPE_MESSAGE", ",", "$", "notification", ")", ")", ";", "return", "\"SNS Message Notification Received.\"", ";", "}", "// For subscription notifications, we need to parse the Queue from", "// the Topic ARN", "$", "arnParts", "=", "explode", "(", "':'", ",", "$", "notification", "[", "'TopicArn'", "]", ")", ";", "$", "last", "=", "end", "(", "$", "arnParts", ")", ";", "$", "queue", "=", "str_replace", "(", "'qpush_'", ",", "''", ",", "$", "last", ")", ";", "// Get the token for the Subscription Confirmation", "$", "metadata", "[", "'Token'", "]", "=", "$", "notification", "[", "'Token'", "]", ";", "$", "notification", "=", "new", "Notification", "(", "$", "notification", "[", "'MessageId'", "]", ",", "$", "notification", "[", "'Message'", "]", ",", "$", "metadata", ")", ";", "$", "this", "->", "dispatcher", "->", "dispatch", "(", "Events", "::", "Notification", "(", "$", "queue", ")", ",", "new", "NotificationEvent", "(", "$", "queue", ",", "NotificationEvent", "::", "TYPE_SUBSCRIPTION", ",", "$", "notification", ")", ")", ";", "return", "\"SNS Subscription Confirmation Received.\"", ";", "}" ]
Handles Notifications sent from AWS SNS @param GetResponseEvent $event The Kernel Request's GetResponseEvent @return string
[ "Handles", "Notifications", "sent", "from", "AWS", "SNS" ]
cf4540278f1344bf7fd3601789cb10da5d706602
https://github.com/uecode/qpush-bundle/blob/cf4540278f1344bf7fd3601789cb10da5d706602/src/EventListener/RequestListener.php#L117-L169
train
uecode/qpush-bundle
src/EventListener/RequestListener.php
RequestListener.getIronMqQueueName
private function getIronMqQueueName(GetResponseEvent $event, array&$message) { if (array_key_exists('_qpush_queue', $message)) { return $message['_qpush_queue']; } else if (null !== ($subscriberUrl = $event->getRequest()->headers->get('iron-subscriber-message-url'))) { if (preg_match('#/queues/([a-z0-9_-]+)/messages/#i', $subscriberUrl, $matches)) { $queue = $matches[1]; if (substr($queue, 0, 6) == 'qpush_') { $queue = substr($queue, 6); } return $queue; } } throw new \RuntimeException('Unable to get queue name'); }
php
private function getIronMqQueueName(GetResponseEvent $event, array&$message) { if (array_key_exists('_qpush_queue', $message)) { return $message['_qpush_queue']; } else if (null !== ($subscriberUrl = $event->getRequest()->headers->get('iron-subscriber-message-url'))) { if (preg_match('#/queues/([a-z0-9_-]+)/messages/#i', $subscriberUrl, $matches)) { $queue = $matches[1]; if (substr($queue, 0, 6) == 'qpush_') { $queue = substr($queue, 6); } return $queue; } } throw new \RuntimeException('Unable to get queue name'); }
[ "private", "function", "getIronMqQueueName", "(", "GetResponseEvent", "$", "event", ",", "array", "&", "$", "message", ")", "{", "if", "(", "array_key_exists", "(", "'_qpush_queue'", ",", "$", "message", ")", ")", "{", "return", "$", "message", "[", "'_qpush_queue'", "]", ";", "}", "else", "if", "(", "null", "!==", "(", "$", "subscriberUrl", "=", "$", "event", "->", "getRequest", "(", ")", "->", "headers", "->", "get", "(", "'iron-subscriber-message-url'", ")", ")", ")", "{", "if", "(", "preg_match", "(", "'#/queues/([a-z0-9_-]+)/messages/#i'", ",", "$", "subscriberUrl", ",", "$", "matches", ")", ")", "{", "$", "queue", "=", "$", "matches", "[", "1", "]", ";", "if", "(", "substr", "(", "$", "queue", ",", "0", ",", "6", ")", "==", "'qpush_'", ")", "{", "$", "queue", "=", "substr", "(", "$", "queue", ",", "6", ")", ";", "}", "return", "$", "queue", ";", "}", "}", "throw", "new", "\\", "RuntimeException", "(", "'Unable to get queue name'", ")", ";", "}" ]
Get the name of the IronMq queue. @param GetResponseEvent $event @param array $message @return string
[ "Get", "the", "name", "of", "the", "IronMq", "queue", "." ]
cf4540278f1344bf7fd3601789cb10da5d706602
https://github.com/uecode/qpush-bundle/blob/cf4540278f1344bf7fd3601789cb10da5d706602/src/EventListener/RequestListener.php#L179-L194
train
brick/date-time
src/DefaultClock.php
DefaultClock.get
public static function get() : Clock { if (self::$clock === null) { self::$clock = new SystemClock(); } return self::$clock; }
php
public static function get() : Clock { if (self::$clock === null) { self::$clock = new SystemClock(); } return self::$clock; }
[ "public", "static", "function", "get", "(", ")", ":", "Clock", "{", "if", "(", "self", "::", "$", "clock", "===", "null", ")", "{", "self", "::", "$", "clock", "=", "new", "SystemClock", "(", ")", ";", "}", "return", "self", "::", "$", "clock", ";", "}" ]
Gets the default clock. @return Clock
[ "Gets", "the", "default", "clock", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/DefaultClock.php#L36-L43
train
brick/date-time
src/DefaultClock.php
DefaultClock.travel
public static function travel(Instant $instant) : void { $clock = self::get(); $offset = Duration::between($clock->getTime(), $instant); self::set(new OffsetClock($clock, $offset)); }
php
public static function travel(Instant $instant) : void { $clock = self::get(); $offset = Duration::between($clock->getTime(), $instant); self::set(new OffsetClock($clock, $offset)); }
[ "public", "static", "function", "travel", "(", "Instant", "$", "instant", ")", ":", "void", "{", "$", "clock", "=", "self", "::", "get", "(", ")", ";", "$", "offset", "=", "Duration", "::", "between", "(", "$", "clock", "->", "getTime", "(", ")", ",", "$", "instant", ")", ";", "self", "::", "set", "(", "new", "OffsetClock", "(", "$", "clock", ",", "$", "offset", ")", ")", ";", "}" ]
Travels to a specific point in time, but allows time to continue moving forward from there. If the current default clock is frozen, you must `reset()` it first, or the time will stay frozen. @param Instant $instant @return void
[ "Travels", "to", "a", "specific", "point", "in", "time", "but", "allows", "time", "to", "continue", "moving", "forward", "from", "there", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/DefaultClock.php#L88-L94
train
brick/date-time
src/DefaultClock.php
DefaultClock.scale
public static function scale(int $timeScale) : void { self::set(new ScaleClock(self::get(), $timeScale)); }
php
public static function scale(int $timeScale) : void { self::set(new ScaleClock(self::get(), $timeScale)); }
[ "public", "static", "function", "scale", "(", "int", "$", "timeScale", ")", ":", "void", "{", "self", "::", "set", "(", "new", "ScaleClock", "(", "self", "::", "get", "(", ")", ",", "$", "timeScale", ")", ")", ";", "}" ]
Makes time move at a given pace. - a scale > 1 makes the time move at an accelerated pace; - a scale == 1 makes the time move at the normal pace; - a scale == 0 freezes the current time; - a scale < 0 makes the time move backwards. If the current default clock is frozen, you must `reset()` it first, or the time will stay frozen. Multiple calls to `scale()` will result in a clock with the combined scales. @param int $timeScale The time scale. @return void
[ "Makes", "time", "move", "at", "a", "given", "pace", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/DefaultClock.php#L111-L114
train
brick/date-time
src/LocalDate.php
LocalDate.of
public static function of(int $year, int $month, int $day) : LocalDate { Field\Year::check($year); Field\MonthOfYear::check($month); Field\DayOfMonth::check($day, $month, $year); return new LocalDate($year, $month, $day); }
php
public static function of(int $year, int $month, int $day) : LocalDate { Field\Year::check($year); Field\MonthOfYear::check($month); Field\DayOfMonth::check($day, $month, $year); return new LocalDate($year, $month, $day); }
[ "public", "static", "function", "of", "(", "int", "$", "year", ",", "int", "$", "month", ",", "int", "$", "day", ")", ":", "LocalDate", "{", "Field", "\\", "Year", "::", "check", "(", "$", "year", ")", ";", "Field", "\\", "MonthOfYear", "::", "check", "(", "$", "month", ")", ";", "Field", "\\", "DayOfMonth", "::", "check", "(", "$", "day", ",", "$", "month", ",", "$", "year", ")", ";", "return", "new", "LocalDate", "(", "$", "year", ",", "$", "month", ",", "$", "day", ")", ";", "}" ]
Obtains an instance of `LocalDate` from a year, month and day. @param int $year The year, from MIN_YEAR to MAX_YEAR. @param int $month The month-of-year, from 1 (January) to 12 (December). @param int $day The day-of-month, from 1 to 31. @return LocalDate The LocalDate instance. @throws DateTimeException If the date is not valid.
[ "Obtains", "an", "instance", "of", "LocalDate", "from", "a", "year", "month", "and", "day", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDate.php#L86-L93
train
brick/date-time
src/LocalDate.php
LocalDate.ofYearDay
public static function ofYearDay(int $year, int $dayOfYear) : LocalDate { Field\Year::check($year); Field\DayOfYear::check($dayOfYear, $year); $isLeap = Field\Year::isLeap($year); $monthOfYear = Month::of(\intdiv($dayOfYear - 1, 31) + 1); $monthEnd = $monthOfYear->getFirstDayOfYear($isLeap) + $monthOfYear->getLength($isLeap) - 1; if ($dayOfYear > $monthEnd) { $monthOfYear = $monthOfYear->plus(1); } $dayOfMonth = $dayOfYear - $monthOfYear->getFirstDayOfYear($isLeap) + 1; return LocalDate::of($year, $monthOfYear->getValue(), $dayOfMonth); }
php
public static function ofYearDay(int $year, int $dayOfYear) : LocalDate { Field\Year::check($year); Field\DayOfYear::check($dayOfYear, $year); $isLeap = Field\Year::isLeap($year); $monthOfYear = Month::of(\intdiv($dayOfYear - 1, 31) + 1); $monthEnd = $monthOfYear->getFirstDayOfYear($isLeap) + $monthOfYear->getLength($isLeap) - 1; if ($dayOfYear > $monthEnd) { $monthOfYear = $monthOfYear->plus(1); } $dayOfMonth = $dayOfYear - $monthOfYear->getFirstDayOfYear($isLeap) + 1; return LocalDate::of($year, $monthOfYear->getValue(), $dayOfMonth); }
[ "public", "static", "function", "ofYearDay", "(", "int", "$", "year", ",", "int", "$", "dayOfYear", ")", ":", "LocalDate", "{", "Field", "\\", "Year", "::", "check", "(", "$", "year", ")", ";", "Field", "\\", "DayOfYear", "::", "check", "(", "$", "dayOfYear", ",", "$", "year", ")", ";", "$", "isLeap", "=", "Field", "\\", "Year", "::", "isLeap", "(", "$", "year", ")", ";", "$", "monthOfYear", "=", "Month", "::", "of", "(", "\\", "intdiv", "(", "$", "dayOfYear", "-", "1", ",", "31", ")", "+", "1", ")", ";", "$", "monthEnd", "=", "$", "monthOfYear", "->", "getFirstDayOfYear", "(", "$", "isLeap", ")", "+", "$", "monthOfYear", "->", "getLength", "(", "$", "isLeap", ")", "-", "1", ";", "if", "(", "$", "dayOfYear", ">", "$", "monthEnd", ")", "{", "$", "monthOfYear", "=", "$", "monthOfYear", "->", "plus", "(", "1", ")", ";", "}", "$", "dayOfMonth", "=", "$", "dayOfYear", "-", "$", "monthOfYear", "->", "getFirstDayOfYear", "(", "$", "isLeap", ")", "+", "1", ";", "return", "LocalDate", "::", "of", "(", "$", "year", ",", "$", "monthOfYear", "->", "getValue", "(", ")", ",", "$", "dayOfMonth", ")", ";", "}" ]
Obtains an instance of `LocalDate` from a year and day-of-year. @param int $year The year, from MIN_YEAR to MAX_YEAR. @param int $dayOfYear The day-of-year, from 1 to 366. @return LocalDate @throws DateTimeException If either value is not valid.
[ "Obtains", "an", "instance", "of", "LocalDate", "from", "a", "year", "and", "day", "-", "of", "-", "year", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDate.php#L105-L122
train
brick/date-time
src/LocalDate.php
LocalDate.fromDateTime
public static function fromDateTime(\DateTimeInterface $dateTime) : LocalDate { return new LocalDate( (int) $dateTime->format('Y'), (int) $dateTime->format('n'), (int) $dateTime->format('j') ); }
php
public static function fromDateTime(\DateTimeInterface $dateTime) : LocalDate { return new LocalDate( (int) $dateTime->format('Y'), (int) $dateTime->format('n'), (int) $dateTime->format('j') ); }
[ "public", "static", "function", "fromDateTime", "(", "\\", "DateTimeInterface", "$", "dateTime", ")", ":", "LocalDate", "{", "return", "new", "LocalDate", "(", "(", "int", ")", "$", "dateTime", "->", "format", "(", "'Y'", ")", ",", "(", "int", ")", "$", "dateTime", "->", "format", "(", "'n'", ")", ",", "(", "int", ")", "$", "dateTime", "->", "format", "(", "'j'", ")", ")", ";", "}" ]
Creates a LocalDate from a native DateTime or DateTimeImmutable object. @param \DateTimeInterface $dateTime @return LocalDate
[ "Creates", "a", "LocalDate", "from", "a", "native", "DateTime", "or", "DateTimeImmutable", "object", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDate.php#L168-L175
train
brick/date-time
src/LocalDate.php
LocalDate.ofEpochDay
public static function ofEpochDay(int $epochDay) : LocalDate { $zeroDay = $epochDay + self::DAYS_0000_TO_1970; // Find the march-based year. $zeroDay -= 60; // Adjust to 0000-03-01 so leap day is at end of four year cycle. $adjust = 0; if ($zeroDay < 0) { // Adjust negative years to positive for calculation. $adjustCycles = \intdiv(($zeroDay + 1), self::DAYS_PER_CYCLE) - 1; $adjust = $adjustCycles * 400; $zeroDay += -$adjustCycles * self::DAYS_PER_CYCLE; } $yearEst = \intdiv(400 * $zeroDay + 591, self::DAYS_PER_CYCLE); $doyEst = $zeroDay - (365 * $yearEst + \intdiv($yearEst, 4) - \intdiv($yearEst, 100) + \intdiv($yearEst, 400)); if ($doyEst < 0) { // Fix estimate. $yearEst--; $doyEst = $zeroDay - (365 * $yearEst + \intdiv($yearEst, 4) - \intdiv($yearEst, 100) + \intdiv($yearEst, 400)); } $yearEst += $adjust; // Reset any negative year. $marchDoy0 = $doyEst; // Convert march-based values back to January-based. $marchMonth0 = \intdiv($marchDoy0 * 5 + 2, 153); $month = ($marchMonth0 + 2) % 12 + 1; $dom = $marchDoy0 - \intdiv($marchMonth0 * 306 + 5, 10) + 1; $yearEst += \intdiv($marchMonth0, 10); // Check year now we are certain it is correct. Field\Year::check($yearEst); return new LocalDate($yearEst, $month, $dom); }
php
public static function ofEpochDay(int $epochDay) : LocalDate { $zeroDay = $epochDay + self::DAYS_0000_TO_1970; // Find the march-based year. $zeroDay -= 60; // Adjust to 0000-03-01 so leap day is at end of four year cycle. $adjust = 0; if ($zeroDay < 0) { // Adjust negative years to positive for calculation. $adjustCycles = \intdiv(($zeroDay + 1), self::DAYS_PER_CYCLE) - 1; $adjust = $adjustCycles * 400; $zeroDay += -$adjustCycles * self::DAYS_PER_CYCLE; } $yearEst = \intdiv(400 * $zeroDay + 591, self::DAYS_PER_CYCLE); $doyEst = $zeroDay - (365 * $yearEst + \intdiv($yearEst, 4) - \intdiv($yearEst, 100) + \intdiv($yearEst, 400)); if ($doyEst < 0) { // Fix estimate. $yearEst--; $doyEst = $zeroDay - (365 * $yearEst + \intdiv($yearEst, 4) - \intdiv($yearEst, 100) + \intdiv($yearEst, 400)); } $yearEst += $adjust; // Reset any negative year. $marchDoy0 = $doyEst; // Convert march-based values back to January-based. $marchMonth0 = \intdiv($marchDoy0 * 5 + 2, 153); $month = ($marchMonth0 + 2) % 12 + 1; $dom = $marchDoy0 - \intdiv($marchMonth0 * 306 + 5, 10) + 1; $yearEst += \intdiv($marchMonth0, 10); // Check year now we are certain it is correct. Field\Year::check($yearEst); return new LocalDate($yearEst, $month, $dom); }
[ "public", "static", "function", "ofEpochDay", "(", "int", "$", "epochDay", ")", ":", "LocalDate", "{", "$", "zeroDay", "=", "$", "epochDay", "+", "self", "::", "DAYS_0000_TO_1970", ";", "// Find the march-based year.", "$", "zeroDay", "-=", "60", ";", "// Adjust to 0000-03-01 so leap day is at end of four year cycle.", "$", "adjust", "=", "0", ";", "if", "(", "$", "zeroDay", "<", "0", ")", "{", "// Adjust negative years to positive for calculation.", "$", "adjustCycles", "=", "\\", "intdiv", "(", "(", "$", "zeroDay", "+", "1", ")", ",", "self", "::", "DAYS_PER_CYCLE", ")", "-", "1", ";", "$", "adjust", "=", "$", "adjustCycles", "*", "400", ";", "$", "zeroDay", "+=", "-", "$", "adjustCycles", "*", "self", "::", "DAYS_PER_CYCLE", ";", "}", "$", "yearEst", "=", "\\", "intdiv", "(", "400", "*", "$", "zeroDay", "+", "591", ",", "self", "::", "DAYS_PER_CYCLE", ")", ";", "$", "doyEst", "=", "$", "zeroDay", "-", "(", "365", "*", "$", "yearEst", "+", "\\", "intdiv", "(", "$", "yearEst", ",", "4", ")", "-", "\\", "intdiv", "(", "$", "yearEst", ",", "100", ")", "+", "\\", "intdiv", "(", "$", "yearEst", ",", "400", ")", ")", ";", "if", "(", "$", "doyEst", "<", "0", ")", "{", "// Fix estimate.", "$", "yearEst", "--", ";", "$", "doyEst", "=", "$", "zeroDay", "-", "(", "365", "*", "$", "yearEst", "+", "\\", "intdiv", "(", "$", "yearEst", ",", "4", ")", "-", "\\", "intdiv", "(", "$", "yearEst", ",", "100", ")", "+", "\\", "intdiv", "(", "$", "yearEst", ",", "400", ")", ")", ";", "}", "$", "yearEst", "+=", "$", "adjust", ";", "// Reset any negative year.", "$", "marchDoy0", "=", "$", "doyEst", ";", "// Convert march-based values back to January-based.", "$", "marchMonth0", "=", "\\", "intdiv", "(", "$", "marchDoy0", "*", "5", "+", "2", ",", "153", ")", ";", "$", "month", "=", "(", "$", "marchMonth0", "+", "2", ")", "%", "12", "+", "1", ";", "$", "dom", "=", "$", "marchDoy0", "-", "\\", "intdiv", "(", "$", "marchMonth0", "*", "306", "+", "5", ",", "10", ")", "+", "1", ";", "$", "yearEst", "+=", "\\", "intdiv", "(", "$", "marchMonth0", ",", "10", ")", ";", "// Check year now we are certain it is correct.", "Field", "\\", "Year", "::", "check", "(", "$", "yearEst", ")", ";", "return", "new", "LocalDate", "(", "$", "yearEst", ",", "$", "month", ",", "$", "dom", ")", ";", "}" ]
Obtains an instance of `LocalDate` from the epoch day count. The Epoch Day count is a simple incrementing count of days where day 0 is 1970-01-01. Negative numbers represent earlier days. @param int $epochDay @return LocalDate @throws DateTimeException If the resulting date has a year out of range.
[ "Obtains", "an", "instance", "of", "LocalDate", "from", "the", "epoch", "day", "count", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDate.php#L189-L221
train
brick/date-time
src/LocalDate.php
LocalDate.now
public static function now(TimeZone $timeZone, Clock $clock = null) : LocalDate { return ZonedDateTime::now($timeZone, $clock)->getDate(); }
php
public static function now(TimeZone $timeZone, Clock $clock = null) : LocalDate { return ZonedDateTime::now($timeZone, $clock)->getDate(); }
[ "public", "static", "function", "now", "(", "TimeZone", "$", "timeZone", ",", "Clock", "$", "clock", "=", "null", ")", ":", "LocalDate", "{", "return", "ZonedDateTime", "::", "now", "(", "$", "timeZone", ",", "$", "clock", ")", "->", "getDate", "(", ")", ";", "}" ]
Returns the current date in the given time-zone, according to the given clock. If no clock is provided, the system clock is used. @param TimeZone $timeZone @param Clock|null $clock @return LocalDate
[ "Returns", "the", "current", "date", "in", "the", "given", "time", "-", "zone", "according", "to", "the", "given", "clock", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDate.php#L233-L236
train
brick/date-time
src/LocalDate.php
LocalDate.minOf
public static function minOf(LocalDate ...$dates) : LocalDate { if (! $dates) { throw new DateTimeException(__METHOD__ . ' does not accept less than 1 parameter.'); } $min = LocalDate::max(); foreach ($dates as $time) { if ($time->isBefore($min)) { $min = $time; } } return $min; }
php
public static function minOf(LocalDate ...$dates) : LocalDate { if (! $dates) { throw new DateTimeException(__METHOD__ . ' does not accept less than 1 parameter.'); } $min = LocalDate::max(); foreach ($dates as $time) { if ($time->isBefore($min)) { $min = $time; } } return $min; }
[ "public", "static", "function", "minOf", "(", "LocalDate", "...", "$", "dates", ")", ":", "LocalDate", "{", "if", "(", "!", "$", "dates", ")", "{", "throw", "new", "DateTimeException", "(", "__METHOD__", ".", "' does not accept less than 1 parameter.'", ")", ";", "}", "$", "min", "=", "LocalDate", "::", "max", "(", ")", ";", "foreach", "(", "$", "dates", "as", "$", "time", ")", "{", "if", "(", "$", "time", "->", "isBefore", "(", "$", "min", ")", ")", "{", "$", "min", "=", "$", "time", ";", "}", "}", "return", "$", "min", ";", "}" ]
Returns the smallest LocalDate among the given values. @param LocalDate[] $dates The LocalDate objects to compare. @return LocalDate The earliest LocalDate object. @throws DateTimeException If the array is empty.
[ "Returns", "the", "smallest", "LocalDate", "among", "the", "given", "values", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDate.php#L271-L286
train
brick/date-time
src/LocalDate.php
LocalDate.maxOf
public static function maxOf(LocalDate ...$dates) : LocalDate { if (! $dates) { throw new DateTimeException(__METHOD__ . ' does not accept less than 1 parameter.'); } $max = LocalDate::min(); foreach ($dates as $time) { if ($time->isAfter($max)) { $max = $time; } } return $max; }
php
public static function maxOf(LocalDate ...$dates) : LocalDate { if (! $dates) { throw new DateTimeException(__METHOD__ . ' does not accept less than 1 parameter.'); } $max = LocalDate::min(); foreach ($dates as $time) { if ($time->isAfter($max)) { $max = $time; } } return $max; }
[ "public", "static", "function", "maxOf", "(", "LocalDate", "...", "$", "dates", ")", ":", "LocalDate", "{", "if", "(", "!", "$", "dates", ")", "{", "throw", "new", "DateTimeException", "(", "__METHOD__", ".", "' does not accept less than 1 parameter.'", ")", ";", "}", "$", "max", "=", "LocalDate", "::", "min", "(", ")", ";", "foreach", "(", "$", "dates", "as", "$", "time", ")", "{", "if", "(", "$", "time", "->", "isAfter", "(", "$", "max", ")", ")", "{", "$", "max", "=", "$", "time", ";", "}", "}", "return", "$", "max", ";", "}" ]
Returns the highest LocalDate among the given values. @param LocalDate[] $dates The LocalDate objects to compare. @return LocalDate The latest LocalDate object. @throws DateTimeException If the array is empty.
[ "Returns", "the", "highest", "LocalDate", "among", "the", "given", "values", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDate.php#L297-L312
train
brick/date-time
src/LocalDate.php
LocalDate.getDayOfYear
public function getDayOfYear() : int { return Month::of($this->month)->getFirstDayOfYear($this->isLeapYear()) + $this->day - 1; }
php
public function getDayOfYear() : int { return Month::of($this->month)->getFirstDayOfYear($this->isLeapYear()) + $this->day - 1; }
[ "public", "function", "getDayOfYear", "(", ")", ":", "int", "{", "return", "Month", "::", "of", "(", "$", "this", "->", "month", ")", "->", "getFirstDayOfYear", "(", "$", "this", "->", "isLeapYear", "(", ")", ")", "+", "$", "this", "->", "day", "-", "1", ";", "}" ]
Returns the day-of-year, from 1 to 365, or 366 in a leap year. @return int
[ "Returns", "the", "day", "-", "of", "-", "year", "from", "1", "to", "365", "or", "366", "in", "a", "leap", "year", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDate.php#L359-L362
train
brick/date-time
src/LocalDate.php
LocalDate.withYear
public function withYear(int $year) : LocalDate { if ($year === $this->year) { return $this; } Field\Year::check($year); return $this->resolvePreviousValid($year, $this->month, $this->day); }
php
public function withYear(int $year) : LocalDate { if ($year === $this->year) { return $this; } Field\Year::check($year); return $this->resolvePreviousValid($year, $this->month, $this->day); }
[ "public", "function", "withYear", "(", "int", "$", "year", ")", ":", "LocalDate", "{", "if", "(", "$", "year", "===", "$", "this", "->", "year", ")", "{", "return", "$", "this", ";", "}", "Field", "\\", "Year", "::", "check", "(", "$", "year", ")", ";", "return", "$", "this", "->", "resolvePreviousValid", "(", "$", "year", ",", "$", "this", "->", "month", ",", "$", "this", "->", "day", ")", ";", "}" ]
Returns a copy of this LocalDate with the year altered. If the day-of-month is invalid for the year, it will be changed to the last valid day of the month. @param int $year @return LocalDate @throws DateTimeException If the year is outside the valid range.
[ "Returns", "a", "copy", "of", "this", "LocalDate", "with", "the", "year", "altered", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDate.php#L394-L403
train
brick/date-time
src/LocalDate.php
LocalDate.withMonth
public function withMonth(int $month) : LocalDate { if ($month === $this->month) { return $this; } Field\MonthOfYear::check($month); return $this->resolvePreviousValid($this->year, $month, $this->day); }
php
public function withMonth(int $month) : LocalDate { if ($month === $this->month) { return $this; } Field\MonthOfYear::check($month); return $this->resolvePreviousValid($this->year, $month, $this->day); }
[ "public", "function", "withMonth", "(", "int", "$", "month", ")", ":", "LocalDate", "{", "if", "(", "$", "month", "===", "$", "this", "->", "month", ")", "{", "return", "$", "this", ";", "}", "Field", "\\", "MonthOfYear", "::", "check", "(", "$", "month", ")", ";", "return", "$", "this", "->", "resolvePreviousValid", "(", "$", "this", "->", "year", ",", "$", "month", ",", "$", "this", "->", "day", ")", ";", "}" ]
Returns a copy of this LocalDate with the month-of-year altered. If the day-of-month is invalid for the month and year, it will be changed to the last valid day of the month. @param int $month @return LocalDate @throws DateTimeException If the month is invalid.
[ "Returns", "a", "copy", "of", "this", "LocalDate", "with", "the", "month", "-", "of", "-", "year", "altered", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDate.php#L416-L425
train
brick/date-time
src/LocalDate.php
LocalDate.withDay
public function withDay(int $day) : LocalDate { if ($day === $this->day) { return $this; } Field\DayOfMonth::check($day, $this->month, $this->year); return new LocalDate($this->year, $this->month, $day); }
php
public function withDay(int $day) : LocalDate { if ($day === $this->day) { return $this; } Field\DayOfMonth::check($day, $this->month, $this->year); return new LocalDate($this->year, $this->month, $day); }
[ "public", "function", "withDay", "(", "int", "$", "day", ")", ":", "LocalDate", "{", "if", "(", "$", "day", "===", "$", "this", "->", "day", ")", "{", "return", "$", "this", ";", "}", "Field", "\\", "DayOfMonth", "::", "check", "(", "$", "day", ",", "$", "this", "->", "month", ",", "$", "this", "->", "year", ")", ";", "return", "new", "LocalDate", "(", "$", "this", "->", "year", ",", "$", "this", "->", "month", ",", "$", "day", ")", ";", "}" ]
Returns a copy of this LocalDate with the day-of-month altered. If the resulting date is invalid, an exception is thrown. @param int $day @return LocalDate @throws DateTimeException If the day is invalid for the current year and month.
[ "Returns", "a", "copy", "of", "this", "LocalDate", "with", "the", "day", "-", "of", "-", "month", "altered", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDate.php#L438-L447
train
brick/date-time
src/LocalDate.php
LocalDate.plusPeriod
public function plusPeriod(Period $period) : LocalDate { return $this ->plusYears($period->getYears()) ->plusMonths($period->getMonths()) ->plusDays($period->getDays()); }
php
public function plusPeriod(Period $period) : LocalDate { return $this ->plusYears($period->getYears()) ->plusMonths($period->getMonths()) ->plusDays($period->getDays()); }
[ "public", "function", "plusPeriod", "(", "Period", "$", "period", ")", ":", "LocalDate", "{", "return", "$", "this", "->", "plusYears", "(", "$", "period", "->", "getYears", "(", ")", ")", "->", "plusMonths", "(", "$", "period", "->", "getMonths", "(", ")", ")", "->", "plusDays", "(", "$", "period", "->", "getDays", "(", ")", ")", ";", "}" ]
Returns a copy of this LocalDate with the specified Period added. @param Period $period @return LocalDate
[ "Returns", "a", "copy", "of", "this", "LocalDate", "with", "the", "specified", "Period", "added", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDate.php#L456-L462
train
brick/date-time
src/LocalDate.php
LocalDate.plusYears
public function plusYears(int $years) : LocalDate { if ($years === 0) { return $this; } return $this->withYear($this->year + $years); }
php
public function plusYears(int $years) : LocalDate { if ($years === 0) { return $this; } return $this->withYear($this->year + $years); }
[ "public", "function", "plusYears", "(", "int", "$", "years", ")", ":", "LocalDate", "{", "if", "(", "$", "years", "===", "0", ")", "{", "return", "$", "this", ";", "}", "return", "$", "this", "->", "withYear", "(", "$", "this", "->", "year", "+", "$", "years", ")", ";", "}" ]
Returns a copy of this LocalDate with the specified period in years added. If the day-of-month is invalid for the resulting year and month, it will be changed to the last valid day of the month. @param int $years @return LocalDate @throws DateTimeException If the resulting year is out of range.
[ "Returns", "a", "copy", "of", "this", "LocalDate", "with", "the", "specified", "period", "in", "years", "added", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDate.php#L476-L483
train
brick/date-time
src/LocalDate.php
LocalDate.plusMonths
public function plusMonths(int $months) : LocalDate { $month = $this->month + $months - 1; $yearDiff = Math::floorDiv($month, 12); $month = Math::floorMod($month, 12) + 1; $year = $this->year + $yearDiff; return $this->resolvePreviousValid($year, $month, $this->day); }
php
public function plusMonths(int $months) : LocalDate { $month = $this->month + $months - 1; $yearDiff = Math::floorDiv($month, 12); $month = Math::floorMod($month, 12) + 1; $year = $this->year + $yearDiff; return $this->resolvePreviousValid($year, $month, $this->day); }
[ "public", "function", "plusMonths", "(", "int", "$", "months", ")", ":", "LocalDate", "{", "$", "month", "=", "$", "this", "->", "month", "+", "$", "months", "-", "1", ";", "$", "yearDiff", "=", "Math", "::", "floorDiv", "(", "$", "month", ",", "12", ")", ";", "$", "month", "=", "Math", "::", "floorMod", "(", "$", "month", ",", "12", ")", "+", "1", ";", "$", "year", "=", "$", "this", "->", "year", "+", "$", "yearDiff", ";", "return", "$", "this", "->", "resolvePreviousValid", "(", "$", "year", ",", "$", "month", ",", "$", "this", "->", "day", ")", ";", "}" ]
Returns a copy of this LocalDate with the specified period in months added. If the day-of-month is invalid for the resulting year and month, it will be changed to the last valid day of the month. @param int $months @return LocalDate
[ "Returns", "a", "copy", "of", "this", "LocalDate", "with", "the", "specified", "period", "in", "months", "added", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDate.php#L495-L505
train
brick/date-time
src/LocalDate.php
LocalDate.plusDays
public function plusDays(int $days) : LocalDate { if ($days === 0) { return $this; } return LocalDate::ofEpochDay($this->toEpochDay() + $days); }
php
public function plusDays(int $days) : LocalDate { if ($days === 0) { return $this; } return LocalDate::ofEpochDay($this->toEpochDay() + $days); }
[ "public", "function", "plusDays", "(", "int", "$", "days", ")", ":", "LocalDate", "{", "if", "(", "$", "days", "===", "0", ")", "{", "return", "$", "this", ";", "}", "return", "LocalDate", "::", "ofEpochDay", "(", "$", "this", "->", "toEpochDay", "(", ")", "+", "$", "days", ")", ";", "}" ]
Returns a copy of this LocalDate with the specified period in days added. @param int $days @return LocalDate
[ "Returns", "a", "copy", "of", "this", "LocalDate", "with", "the", "specified", "period", "in", "days", "added", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDate.php#L530-L537
train
brick/date-time
src/LocalDate.php
LocalDate.until
public function until(LocalDate $endDateExclusive) : Period { $totalMonths = $endDateExclusive->getProlepticMonth() - $this->getProlepticMonth(); $days = $endDateExclusive->day - $this->day; if ($totalMonths > 0 && $days < 0) { $totalMonths--; $calcDate = $this->plusMonths($totalMonths); $days = $endDateExclusive->toEpochDay() - $calcDate->toEpochDay(); } elseif ($totalMonths < 0 && $days > 0) { $totalMonths++; $days -= $endDateExclusive->getLengthOfMonth(); } $years = \intdiv($totalMonths, 12); $months = $totalMonths % 12; return Period::of($years, $months, $days); }
php
public function until(LocalDate $endDateExclusive) : Period { $totalMonths = $endDateExclusive->getProlepticMonth() - $this->getProlepticMonth(); $days = $endDateExclusive->day - $this->day; if ($totalMonths > 0 && $days < 0) { $totalMonths--; $calcDate = $this->plusMonths($totalMonths); $days = $endDateExclusive->toEpochDay() - $calcDate->toEpochDay(); } elseif ($totalMonths < 0 && $days > 0) { $totalMonths++; $days -= $endDateExclusive->getLengthOfMonth(); } $years = \intdiv($totalMonths, 12); $months = $totalMonths % 12; return Period::of($years, $months, $days); }
[ "public", "function", "until", "(", "LocalDate", "$", "endDateExclusive", ")", ":", "Period", "{", "$", "totalMonths", "=", "$", "endDateExclusive", "->", "getProlepticMonth", "(", ")", "-", "$", "this", "->", "getProlepticMonth", "(", ")", ";", "$", "days", "=", "$", "endDateExclusive", "->", "day", "-", "$", "this", "->", "day", ";", "if", "(", "$", "totalMonths", ">", "0", "&&", "$", "days", "<", "0", ")", "{", "$", "totalMonths", "--", ";", "$", "calcDate", "=", "$", "this", "->", "plusMonths", "(", "$", "totalMonths", ")", ";", "$", "days", "=", "$", "endDateExclusive", "->", "toEpochDay", "(", ")", "-", "$", "calcDate", "->", "toEpochDay", "(", ")", ";", "}", "elseif", "(", "$", "totalMonths", "<", "0", "&&", "$", "days", ">", "0", ")", "{", "$", "totalMonths", "++", ";", "$", "days", "-=", "$", "endDateExclusive", "->", "getLengthOfMonth", "(", ")", ";", "}", "$", "years", "=", "\\", "intdiv", "(", "$", "totalMonths", ",", "12", ")", ";", "$", "months", "=", "$", "totalMonths", "%", "12", ";", "return", "Period", "::", "of", "(", "$", "years", ",", "$", "months", ",", "$", "days", ")", ";", "}" ]
Calculates the period between this date and another date. This calculates the period between the two dates in terms of years, months and days. The result will be negative if the end is before the start. The negative sign will be the same in each of year, month and day. The start date is included, but the end date is not. The period is calculated by removing complete months, then calculating the remaining number of days, adjusting to ensure that both have the same sign. The number of months is then normalized into years and months based on a 12 month year. A month is considered to be complete if the end day-of-month is greater than or equal to the start day-of-month. For example, from `2010-01-15` to `2011-03-18` is 1 year, 2 months and 3 days. @param LocalDate $endDateExclusive @return Period
[ "Calculates", "the", "period", "between", "this", "date", "and", "another", "date", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDate.php#L700-L718
train
brick/date-time
src/LocalDate.php
LocalDate.toEpochDay
public function toEpochDay() : int { $y = $this->year; $m = $this->month; $total = 365 * $y; if ($y >= 0) { $total += \intdiv($y + 3, 4) - \intdiv($y + 99, 100) + \intdiv($y + 399, 400); } else { $total -= \intdiv($y, -4) - \intdiv($y, -100) + \intdiv($y, -400); } $total += \intdiv(367 * $m - 362, 12); $total += $this->day - 1; if ($m > 2) { $total--; if (! $this->isLeapYear()) { $total--; } } return $total - self::DAYS_0000_TO_1970; }
php
public function toEpochDay() : int { $y = $this->year; $m = $this->month; $total = 365 * $y; if ($y >= 0) { $total += \intdiv($y + 3, 4) - \intdiv($y + 99, 100) + \intdiv($y + 399, 400); } else { $total -= \intdiv($y, -4) - \intdiv($y, -100) + \intdiv($y, -400); } $total += \intdiv(367 * $m - 362, 12); $total += $this->day - 1; if ($m > 2) { $total--; if (! $this->isLeapYear()) { $total--; } } return $total - self::DAYS_0000_TO_1970; }
[ "public", "function", "toEpochDay", "(", ")", ":", "int", "{", "$", "y", "=", "$", "this", "->", "year", ";", "$", "m", "=", "$", "this", "->", "month", ";", "$", "total", "=", "365", "*", "$", "y", ";", "if", "(", "$", "y", ">=", "0", ")", "{", "$", "total", "+=", "\\", "intdiv", "(", "$", "y", "+", "3", ",", "4", ")", "-", "\\", "intdiv", "(", "$", "y", "+", "99", ",", "100", ")", "+", "\\", "intdiv", "(", "$", "y", "+", "399", ",", "400", ")", ";", "}", "else", "{", "$", "total", "-=", "\\", "intdiv", "(", "$", "y", ",", "-", "4", ")", "-", "\\", "intdiv", "(", "$", "y", ",", "-", "100", ")", "+", "\\", "intdiv", "(", "$", "y", ",", "-", "400", ")", ";", "}", "$", "total", "+=", "\\", "intdiv", "(", "367", "*", "$", "m", "-", "362", ",", "12", ")", ";", "$", "total", "+=", "$", "this", "->", "day", "-", "1", ";", "if", "(", "$", "m", ">", "2", ")", "{", "$", "total", "--", ";", "if", "(", "!", "$", "this", "->", "isLeapYear", "(", ")", ")", "{", "$", "total", "--", ";", "}", "}", "return", "$", "total", "-", "self", "::", "DAYS_0000_TO_1970", ";", "}" ]
Returns the number of days since the UNIX epoch of 1st January 1970. @return int
[ "Returns", "the", "number", "of", "days", "since", "the", "UNIX", "epoch", "of", "1st", "January", "1970", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDate.php#L782-L806
train
brick/date-time
src/LocalDate.php
LocalDate.resolvePreviousValid
private function resolvePreviousValid(int $year, int $month, int $day) : LocalDate { if ($day > 28) { $day = \min($day, YearMonth::of($year, $month)->getLengthOfMonth()); } return new LocalDate($year, $month, $day); }
php
private function resolvePreviousValid(int $year, int $month, int $day) : LocalDate { if ($day > 28) { $day = \min($day, YearMonth::of($year, $month)->getLengthOfMonth()); } return new LocalDate($year, $month, $day); }
[ "private", "function", "resolvePreviousValid", "(", "int", "$", "year", ",", "int", "$", "month", ",", "int", "$", "day", ")", ":", "LocalDate", "{", "if", "(", "$", "day", ">", "28", ")", "{", "$", "day", "=", "\\", "min", "(", "$", "day", ",", "YearMonth", "::", "of", "(", "$", "year", ",", "$", "month", ")", "->", "getLengthOfMonth", "(", ")", ")", ";", "}", "return", "new", "LocalDate", "(", "$", "year", ",", "$", "month", ",", "$", "day", ")", ";", "}" ]
Resolves the date, resolving days past the end of month. @param int $year The year to represent, validated from MIN_YEAR to MAX_YEAR. @param int $month The month-of-year to represent, validated from 1 to 12. @param int $day The day-of-month to represent, validated from 1 to 31. @return LocalDate
[ "Resolves", "the", "date", "resolving", "days", "past", "the", "end", "of", "month", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDate.php#L849-L856
train
brick/date-time
src/YearWeek.php
YearWeek.of
public static function of(int $year, int $week) : YearWeek { Field\Year::check($year); Field\WeekOfYear::check($week, $year); return new YearWeek($year, $week); }
php
public static function of(int $year, int $week) : YearWeek { Field\Year::check($year); Field\WeekOfYear::check($week, $year); return new YearWeek($year, $week); }
[ "public", "static", "function", "of", "(", "int", "$", "year", ",", "int", "$", "week", ")", ":", "YearWeek", "{", "Field", "\\", "Year", "::", "check", "(", "$", "year", ")", ";", "Field", "\\", "WeekOfYear", "::", "check", "(", "$", "week", ",", "$", "year", ")", ";", "return", "new", "YearWeek", "(", "$", "year", ",", "$", "week", ")", ";", "}" ]
Obtains an instance of `YearWeek` from a year and week number. @param int $year The year, from MIN_YEAR to MAX_YEAR. @param int $week The week number, from 1 to 53. @return YearWeek @throws DateTimeException
[ "Obtains", "an", "instance", "of", "YearWeek", "from", "a", "year", "and", "week", "number", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/YearWeek.php#L48-L54
train
brick/date-time
src/YearWeek.php
YearWeek.withYear
public function withYear(int $year) : YearWeek { if ($year === $this->year) { return $this; } Field\Year::check($year); $week = $this->week; if ($week === 53 && ! Field\WeekOfYear::is53WeekYear($year)) { $week = 52; } return new YearWeek($year, $week); }
php
public function withYear(int $year) : YearWeek { if ($year === $this->year) { return $this; } Field\Year::check($year); $week = $this->week; if ($week === 53 && ! Field\WeekOfYear::is53WeekYear($year)) { $week = 52; } return new YearWeek($year, $week); }
[ "public", "function", "withYear", "(", "int", "$", "year", ")", ":", "YearWeek", "{", "if", "(", "$", "year", "===", "$", "this", "->", "year", ")", "{", "return", "$", "this", ";", "}", "Field", "\\", "Year", "::", "check", "(", "$", "year", ")", ";", "$", "week", "=", "$", "this", "->", "week", ";", "if", "(", "$", "week", "===", "53", "&&", "!", "Field", "\\", "WeekOfYear", "::", "is53WeekYear", "(", "$", "year", ")", ")", "{", "$", "week", "=", "52", ";", "}", "return", "new", "YearWeek", "(", "$", "year", ",", "$", "week", ")", ";", "}" ]
Returns a copy of this YearWeek with the year altered. If the week is 53 and the new year does not have 53 weeks, the week will be adjusted to be 52. @param int $year @return YearWeek @throws DateTimeException If the year is not valid.
[ "Returns", "a", "copy", "of", "this", "YearWeek", "with", "the", "year", "altered", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/YearWeek.php#L167-L182
train
brick/date-time
src/YearWeek.php
YearWeek.withWeek
public function withWeek(int $week) : YearWeek { if ($week === $this->week) { return $this; } Field\WeekOfYear::check($week); $year = $this->year; if ($week === 53 && ! Field\WeekOfYear::is53WeekYear($year)) { $year++; $week = 1; } return new YearWeek($year, $week); }
php
public function withWeek(int $week) : YearWeek { if ($week === $this->week) { return $this; } Field\WeekOfYear::check($week); $year = $this->year; if ($week === 53 && ! Field\WeekOfYear::is53WeekYear($year)) { $year++; $week = 1; } return new YearWeek($year, $week); }
[ "public", "function", "withWeek", "(", "int", "$", "week", ")", ":", "YearWeek", "{", "if", "(", "$", "week", "===", "$", "this", "->", "week", ")", "{", "return", "$", "this", ";", "}", "Field", "\\", "WeekOfYear", "::", "check", "(", "$", "week", ")", ";", "$", "year", "=", "$", "this", "->", "year", ";", "if", "(", "$", "week", "===", "53", "&&", "!", "Field", "\\", "WeekOfYear", "::", "is53WeekYear", "(", "$", "year", ")", ")", "{", "$", "year", "++", ";", "$", "week", "=", "1", ";", "}", "return", "new", "YearWeek", "(", "$", "year", ",", "$", "week", ")", ";", "}" ]
Returns a copy of this YearWeek with the week altered. If the new week is 53 and the year does not have 53 weeks, week one of the following year is selected. @param int $week @return YearWeek @throws DateTimeException If the week is not valid.
[ "Returns", "a", "copy", "of", "this", "YearWeek", "with", "the", "week", "altered", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/YearWeek.php#L195-L211
train
brick/date-time
src/YearWeek.php
YearWeek.atDay
public function atDay(int $dayOfWeek) : LocalDate { Field\DayOfWeek::check($dayOfWeek); $correction = LocalDate::of($this->year, 1, 4)->getDayOfWeek()->getValue() + 3; $dayOfYear = $this->week * 7 + $dayOfWeek - $correction; $maxDaysOfYear = Field\Year::isLeap($this->year) ? 366 : 365; if ($dayOfYear > $maxDaysOfYear) { return LocalDate::ofYearDay($this->year + 1, $dayOfYear - $maxDaysOfYear); } if ($dayOfYear > 0) { return LocalDate::ofYearDay($this->year, $dayOfYear); } $daysOfPreviousYear = Field\Year::isLeap($this->year - 1) ? 366 : 365; return LocalDate::ofYearDay($this->year - 1, $daysOfPreviousYear + $dayOfYear); }
php
public function atDay(int $dayOfWeek) : LocalDate { Field\DayOfWeek::check($dayOfWeek); $correction = LocalDate::of($this->year, 1, 4)->getDayOfWeek()->getValue() + 3; $dayOfYear = $this->week * 7 + $dayOfWeek - $correction; $maxDaysOfYear = Field\Year::isLeap($this->year) ? 366 : 365; if ($dayOfYear > $maxDaysOfYear) { return LocalDate::ofYearDay($this->year + 1, $dayOfYear - $maxDaysOfYear); } if ($dayOfYear > 0) { return LocalDate::ofYearDay($this->year, $dayOfYear); } $daysOfPreviousYear = Field\Year::isLeap($this->year - 1) ? 366 : 365; return LocalDate::ofYearDay($this->year - 1, $daysOfPreviousYear + $dayOfYear); }
[ "public", "function", "atDay", "(", "int", "$", "dayOfWeek", ")", ":", "LocalDate", "{", "Field", "\\", "DayOfWeek", "::", "check", "(", "$", "dayOfWeek", ")", ";", "$", "correction", "=", "LocalDate", "::", "of", "(", "$", "this", "->", "year", ",", "1", ",", "4", ")", "->", "getDayOfWeek", "(", ")", "->", "getValue", "(", ")", "+", "3", ";", "$", "dayOfYear", "=", "$", "this", "->", "week", "*", "7", "+", "$", "dayOfWeek", "-", "$", "correction", ";", "$", "maxDaysOfYear", "=", "Field", "\\", "Year", "::", "isLeap", "(", "$", "this", "->", "year", ")", "?", "366", ":", "365", ";", "if", "(", "$", "dayOfYear", ">", "$", "maxDaysOfYear", ")", "{", "return", "LocalDate", "::", "ofYearDay", "(", "$", "this", "->", "year", "+", "1", ",", "$", "dayOfYear", "-", "$", "maxDaysOfYear", ")", ";", "}", "if", "(", "$", "dayOfYear", ">", "0", ")", "{", "return", "LocalDate", "::", "ofYearDay", "(", "$", "this", "->", "year", ",", "$", "dayOfYear", ")", ";", "}", "$", "daysOfPreviousYear", "=", "Field", "\\", "Year", "::", "isLeap", "(", "$", "this", "->", "year", "-", "1", ")", "?", "366", ":", "365", ";", "return", "LocalDate", "::", "ofYearDay", "(", "$", "this", "->", "year", "-", "1", ",", "$", "daysOfPreviousYear", "+", "$", "dayOfYear", ")", ";", "}" ]
Combines this year-week with a day-of-week to create a LocalDate. @param int $dayOfWeek @return LocalDate
[ "Combines", "this", "year", "-", "week", "with", "a", "day", "-", "of", "-", "week", "to", "create", "a", "LocalDate", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/YearWeek.php#L220-L239
train
brick/date-time
src/YearWeek.php
YearWeek.plusYears
public function plusYears(int $years) : YearWeek { if ($years === 0) { return $this; } return $this->withYear($this->year + $years); }
php
public function plusYears(int $years) : YearWeek { if ($years === 0) { return $this; } return $this->withYear($this->year + $years); }
[ "public", "function", "plusYears", "(", "int", "$", "years", ")", ":", "YearWeek", "{", "if", "(", "$", "years", "===", "0", ")", "{", "return", "$", "this", ";", "}", "return", "$", "this", "->", "withYear", "(", "$", "this", "->", "year", "+", "$", "years", ")", ";", "}" ]
Returns a copy of this YearWeek with the specified period in years added. If the week is 53 and the new year does not have 53 weeks, the week will be adjusted to be 52. @param int $years @return YearWeek
[ "Returns", "a", "copy", "of", "this", "YearWeek", "with", "the", "specified", "period", "in", "years", "added", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/YearWeek.php#L270-L277
train
brick/date-time
src/YearWeek.php
YearWeek.plusWeeks
public function plusWeeks(int $weeks) : YearWeek { if ($weeks === 0) { return $this; } $mondayOfWeek = $this->atDay(DayOfWeek::MONDAY)->plusWeeks($weeks); return $mondayOfWeek->getYearWeek(); }
php
public function plusWeeks(int $weeks) : YearWeek { if ($weeks === 0) { return $this; } $mondayOfWeek = $this->atDay(DayOfWeek::MONDAY)->plusWeeks($weeks); return $mondayOfWeek->getYearWeek(); }
[ "public", "function", "plusWeeks", "(", "int", "$", "weeks", ")", ":", "YearWeek", "{", "if", "(", "$", "weeks", "===", "0", ")", "{", "return", "$", "this", ";", "}", "$", "mondayOfWeek", "=", "$", "this", "->", "atDay", "(", "DayOfWeek", "::", "MONDAY", ")", "->", "plusWeeks", "(", "$", "weeks", ")", ";", "return", "$", "mondayOfWeek", "->", "getYearWeek", "(", ")", ";", "}" ]
Returns a copy of this YearWeek with the specified period in weeks added. @param int $weeks @return YearWeek
[ "Returns", "a", "copy", "of", "this", "YearWeek", "with", "the", "specified", "period", "in", "weeks", "added", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/YearWeek.php#L286-L295
train
brick/date-time
src/YearMonth.php
YearMonth.of
public static function of(int $year, int $month) : YearMonth { Field\Year::check($year); Field\MonthOfYear::check($month); return new YearMonth($year, $month); }
php
public static function of(int $year, int $month) : YearMonth { Field\Year::check($year); Field\MonthOfYear::check($month); return new YearMonth($year, $month); }
[ "public", "static", "function", "of", "(", "int", "$", "year", ",", "int", "$", "month", ")", ":", "YearMonth", "{", "Field", "\\", "Year", "::", "check", "(", "$", "year", ")", ";", "Field", "\\", "MonthOfYear", "::", "check", "(", "$", "month", ")", ";", "return", "new", "YearMonth", "(", "$", "year", ",", "$", "month", ")", ";", "}" ]
Obtains an instance of `YearMonth` from a year and month. @param int $year The year, from MIN_YEAR to MAX_YEAR. @param int $month The month-of-year, from 1 (January) to 12 (December). @return YearMonth @throws DateTimeException
[ "Obtains", "an", "instance", "of", "YearMonth", "from", "a", "year", "and", "month", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/YearMonth.php#L54-L60
train
brick/date-time
src/YearMonth.php
YearMonth.parse
public static function parse(string $text, DateTimeParser $parser = null) : YearMonth { if (! $parser) { $parser = IsoParsers::yearMonth(); } return YearMonth::from($parser->parse($text)); }
php
public static function parse(string $text, DateTimeParser $parser = null) : YearMonth { if (! $parser) { $parser = IsoParsers::yearMonth(); } return YearMonth::from($parser->parse($text)); }
[ "public", "static", "function", "parse", "(", "string", "$", "text", ",", "DateTimeParser", "$", "parser", "=", "null", ")", ":", "YearMonth", "{", "if", "(", "!", "$", "parser", ")", "{", "$", "parser", "=", "IsoParsers", "::", "yearMonth", "(", ")", ";", "}", "return", "YearMonth", "::", "from", "(", "$", "parser", "->", "parse", "(", "$", "text", ")", ")", ";", "}" ]
Obtains an instance of `YearMonth` from a text string. @param string $text The text to parse, such as `2007-12`. @param DateTimeParser|null $parser The parser to use, defaults to the ISO 8601 parser. @return YearMonth @throws DateTimeException If the date is not valid. @throws DateTimeParseException If the text string does not follow the expected format.
[ "Obtains", "an", "instance", "of", "YearMonth", "from", "a", "text", "string", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/YearMonth.php#L89-L96
train
brick/date-time
src/YearMonth.php
YearMonth.now
public static function now(TimeZone $timeZone, Clock $clock = null) : YearMonth { $localDate = LocalDate::now($timeZone, $clock); return new YearMonth($localDate->getYear(), $localDate->getMonth()); }
php
public static function now(TimeZone $timeZone, Clock $clock = null) : YearMonth { $localDate = LocalDate::now($timeZone, $clock); return new YearMonth($localDate->getYear(), $localDate->getMonth()); }
[ "public", "static", "function", "now", "(", "TimeZone", "$", "timeZone", ",", "Clock", "$", "clock", "=", "null", ")", ":", "YearMonth", "{", "$", "localDate", "=", "LocalDate", "::", "now", "(", "$", "timeZone", ",", "$", "clock", ")", ";", "return", "new", "YearMonth", "(", "$", "localDate", "->", "getYear", "(", ")", ",", "$", "localDate", "->", "getMonth", "(", ")", ")", ";", "}" ]
Returns the current year-month in the given time-zone, according to the given clock. If no clock is provided, the system clock is used. @param TimeZone $timeZone @param Clock|null $clock @return YearMonth
[ "Returns", "the", "current", "year", "-", "month", "in", "the", "given", "time", "-", "zone", "according", "to", "the", "given", "clock", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/YearMonth.php#L108-L113
train
brick/date-time
src/YearMonth.php
YearMonth.withYear
public function withYear(int $year) : YearMonth { if ($year === $this->year) { return $this; } Field\Year::check($year); return new YearMonth($year, $this->month); }
php
public function withYear(int $year) : YearMonth { if ($year === $this->year) { return $this; } Field\Year::check($year); return new YearMonth($year, $this->month); }
[ "public", "function", "withYear", "(", "int", "$", "year", ")", ":", "YearMonth", "{", "if", "(", "$", "year", "===", "$", "this", "->", "year", ")", "{", "return", "$", "this", ";", "}", "Field", "\\", "Year", "::", "check", "(", "$", "year", ")", ";", "return", "new", "YearMonth", "(", "$", "year", ",", "$", "this", "->", "month", ")", ";", "}" ]
Returns a copy of this YearMonth with the year altered. @param int $year @return YearMonth @throws DateTimeException If the year is not valid.
[ "Returns", "a", "copy", "of", "this", "YearMonth", "with", "the", "year", "altered", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/YearMonth.php#L243-L252
train
brick/date-time
src/YearMonth.php
YearMonth.withMonth
public function withMonth(int $month) : YearMonth { if ($month === $this->month) { return $this; } Field\MonthOfYear::check($month); return new YearMonth($this->year, $month); }
php
public function withMonth(int $month) : YearMonth { if ($month === $this->month) { return $this; } Field\MonthOfYear::check($month); return new YearMonth($this->year, $month); }
[ "public", "function", "withMonth", "(", "int", "$", "month", ")", ":", "YearMonth", "{", "if", "(", "$", "month", "===", "$", "this", "->", "month", ")", "{", "return", "$", "this", ";", "}", "Field", "\\", "MonthOfYear", "::", "check", "(", "$", "month", ")", ";", "return", "new", "YearMonth", "(", "$", "this", "->", "year", ",", "$", "month", ")", ";", "}" ]
Returns a copy of this YearMonth with the month-of-year altered. @param int $month @return YearMonth @throws DateTimeException If the month-of-year is not valid.
[ "Returns", "a", "copy", "of", "this", "YearMonth", "with", "the", "month", "-", "of", "-", "year", "altered", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/YearMonth.php#L263-L272
train
brick/date-time
src/YearMonth.php
YearMonth.atDay
public function atDay(int $day) : LocalDate { return LocalDate::of($this->year, $this->month, $day); }
php
public function atDay(int $day) : LocalDate { return LocalDate::of($this->year, $this->month, $day); }
[ "public", "function", "atDay", "(", "int", "$", "day", ")", ":", "LocalDate", "{", "return", "LocalDate", "::", "of", "(", "$", "this", "->", "year", ",", "$", "this", "->", "month", ",", "$", "day", ")", ";", "}" ]
Combines this year-month with a day-of-month to create a LocalDate. @param int $day The day-of-month to use, valid for the year-month. @return LocalDate The date formed from this year-month and the specified day. @throws DateTimeException If the day is not valid for this year-month.
[ "Combines", "this", "year", "-", "month", "with", "a", "day", "-", "of", "-", "month", "to", "create", "a", "LocalDate", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/YearMonth.php#L299-L302
train
brick/date-time
src/YearMonth.php
YearMonth.plusYears
public function plusYears(int $years) : YearMonth { if ($years === 0) { return $this; } return $this->withYear($this->year + $years); }
php
public function plusYears(int $years) : YearMonth { if ($years === 0) { return $this; } return $this->withYear($this->year + $years); }
[ "public", "function", "plusYears", "(", "int", "$", "years", ")", ":", "YearMonth", "{", "if", "(", "$", "years", "===", "0", ")", "{", "return", "$", "this", ";", "}", "return", "$", "this", "->", "withYear", "(", "$", "this", "->", "year", "+", "$", "years", ")", ";", "}" ]
Returns a copy of this YearMonth with the specified period in years added. @param int $years @return YearMonth
[ "Returns", "a", "copy", "of", "this", "YearMonth", "with", "the", "specified", "period", "in", "years", "added", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/YearMonth.php#L311-L318
train
brick/date-time
src/YearMonth.php
YearMonth.plusMonths
public function plusMonths(int $months) : YearMonth { if ($months === 0) { return $this; } $month = $this->month + $months - 1; $yearDiff = Math::floorDiv($month, 12); $month = Math::floorMod($month, 12) + 1; $year = $this->year + $yearDiff; return new YearMonth($year, $month); }
php
public function plusMonths(int $months) : YearMonth { if ($months === 0) { return $this; } $month = $this->month + $months - 1; $yearDiff = Math::floorDiv($month, 12); $month = Math::floorMod($month, 12) + 1; $year = $this->year + $yearDiff; return new YearMonth($year, $month); }
[ "public", "function", "plusMonths", "(", "int", "$", "months", ")", ":", "YearMonth", "{", "if", "(", "$", "months", "===", "0", ")", "{", "return", "$", "this", ";", "}", "$", "month", "=", "$", "this", "->", "month", "+", "$", "months", "-", "1", ";", "$", "yearDiff", "=", "Math", "::", "floorDiv", "(", "$", "month", ",", "12", ")", ";", "$", "month", "=", "Math", "::", "floorMod", "(", "$", "month", ",", "12", ")", "+", "1", ";", "$", "year", "=", "$", "this", "->", "year", "+", "$", "yearDiff", ";", "return", "new", "YearMonth", "(", "$", "year", ",", "$", "month", ")", ";", "}" ]
Returns a copy of this YearMonth with the specified period in months added. @param int $months @return YearMonth
[ "Returns", "a", "copy", "of", "this", "YearMonth", "with", "the", "specified", "period", "in", "months", "added", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/YearMonth.php#L327-L341
train
brick/date-time
src/MonthDay.php
MonthDay.of
public static function of(int $month, int $day) : MonthDay { Field\MonthOfYear::check($month); Field\DayOfMonth::check($day, $month); return new MonthDay($month, $day); }
php
public static function of(int $month, int $day) : MonthDay { Field\MonthOfYear::check($month); Field\DayOfMonth::check($day, $month); return new MonthDay($month, $day); }
[ "public", "static", "function", "of", "(", "int", "$", "month", ",", "int", "$", "day", ")", ":", "MonthDay", "{", "Field", "\\", "MonthOfYear", "::", "check", "(", "$", "month", ")", ";", "Field", "\\", "DayOfMonth", "::", "check", "(", "$", "day", ",", "$", "month", ")", ";", "return", "new", "MonthDay", "(", "$", "month", ",", "$", "day", ")", ";", "}" ]
Obtains an instance of MonthDay. @param int $month The month-of-year, from 1 (January) to 12 (December). @param int $day The day-of-month, from 1 to 31. @return MonthDay @throws DateTimeException If the month-day is not valid.
[ "Obtains", "an", "instance", "of", "MonthDay", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/MonthDay.php#L53-L59
train
brick/date-time
src/MonthDay.php
MonthDay.now
public static function now(TimeZone $timeZone, Clock $clock = null) : MonthDay { $date = LocalDate::now($timeZone, $clock); return new MonthDay($date->getMonth(), $date->getDay()); }
php
public static function now(TimeZone $timeZone, Clock $clock = null) : MonthDay { $date = LocalDate::now($timeZone, $clock); return new MonthDay($date->getMonth(), $date->getDay()); }
[ "public", "static", "function", "now", "(", "TimeZone", "$", "timeZone", ",", "Clock", "$", "clock", "=", "null", ")", ":", "MonthDay", "{", "$", "date", "=", "LocalDate", "::", "now", "(", "$", "timeZone", ",", "$", "clock", ")", ";", "return", "new", "MonthDay", "(", "$", "date", "->", "getMonth", "(", ")", ",", "$", "date", "->", "getDay", "(", ")", ")", ";", "}" ]
Returns the current month-day in the given time-zone, according to the given clock. If no clock is provided, the system clock is used. @param TimeZone $timeZone @param Clock|null $clock @return MonthDay
[ "Returns", "the", "current", "month", "-", "day", "in", "the", "given", "time", "-", "zone", "according", "to", "the", "given", "clock", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/MonthDay.php#L107-L112
train
brick/date-time
src/MonthDay.php
MonthDay.isValidYear
public function isValidYear(int $year) : bool { return $this->month !== 2 || $this->day !== 29 || Field\Year::isLeap($year); }
php
public function isValidYear(int $year) : bool { return $this->month !== 2 || $this->day !== 29 || Field\Year::isLeap($year); }
[ "public", "function", "isValidYear", "(", "int", "$", "year", ")", ":", "bool", "{", "return", "$", "this", "->", "month", "!==", "2", "||", "$", "this", "->", "day", "!==", "29", "||", "Field", "\\", "Year", "::", "isLeap", "(", "$", "year", ")", ";", "}" ]
Returns whether the given year is valid for this month-day. This method checks whether this month and day and the input year form a valid date. This can only return false for February 29th. @param int $year @return bool
[ "Returns", "whether", "the", "given", "year", "is", "valid", "for", "this", "month", "-", "day", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/MonthDay.php#L205-L208
train
brick/date-time
src/MonthDay.php
MonthDay.withMonth
public function withMonth(int $month) : MonthDay { if ($month === $this->month) { return $this; } Field\MonthOfYear::check($month); $lastDay = Field\MonthOfYear::getLength($month); return new MonthDay($month, ($lastDay < $this->day) ? $lastDay : $this->day); }
php
public function withMonth(int $month) : MonthDay { if ($month === $this->month) { return $this; } Field\MonthOfYear::check($month); $lastDay = Field\MonthOfYear::getLength($month); return new MonthDay($month, ($lastDay < $this->day) ? $lastDay : $this->day); }
[ "public", "function", "withMonth", "(", "int", "$", "month", ")", ":", "MonthDay", "{", "if", "(", "$", "month", "===", "$", "this", "->", "month", ")", "{", "return", "$", "this", ";", "}", "Field", "\\", "MonthOfYear", "::", "check", "(", "$", "month", ")", ";", "$", "lastDay", "=", "Field", "\\", "MonthOfYear", "::", "getLength", "(", "$", "month", ")", ";", "return", "new", "MonthDay", "(", "$", "month", ",", "(", "$", "lastDay", "<", "$", "this", "->", "day", ")", "?", "$", "lastDay", ":", "$", "this", "->", "day", ")", ";", "}" ]
Returns a copy of this MonthDay with the month-of-year altered. If the day-of-month is invalid for the specified month, the day will be adjusted to the last valid day-of-month. @param int $month @return MonthDay @throws DateTimeException If the month is invalid.
[ "Returns", "a", "copy", "of", "this", "MonthDay", "with", "the", "month", "-", "of", "-", "year", "altered", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/MonthDay.php#L222-L233
train
brick/date-time
src/MonthDay.php
MonthDay.withDay
public function withDay(int $day) : MonthDay { if ($day === $this->day) { return $this; } Field\DayOfMonth::check($day, $this->month); return new MonthDay($this->month, $day); }
php
public function withDay(int $day) : MonthDay { if ($day === $this->day) { return $this; } Field\DayOfMonth::check($day, $this->month); return new MonthDay($this->month, $day); }
[ "public", "function", "withDay", "(", "int", "$", "day", ")", ":", "MonthDay", "{", "if", "(", "$", "day", "===", "$", "this", "->", "day", ")", "{", "return", "$", "this", ";", "}", "Field", "\\", "DayOfMonth", "::", "check", "(", "$", "day", ",", "$", "this", "->", "month", ")", ";", "return", "new", "MonthDay", "(", "$", "this", "->", "month", ",", "$", "day", ")", ";", "}" ]
Returns a copy of this MonthDay with the day-of-month altered. If the day-of-month is invalid for the month, an exception is thrown. @param int $day @return MonthDay @throws DateTimeException If the day-of-month is invalid for the month.
[ "Returns", "a", "copy", "of", "this", "MonthDay", "with", "the", "day", "-", "of", "-", "month", "altered", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/MonthDay.php#L246-L255
train
brick/date-time
src/MonthDay.php
MonthDay.atYear
public function atYear(int $year) : LocalDate { return LocalDate::of($year, $this->month, $this->isValidYear($year) ? $this->day : 28); }
php
public function atYear(int $year) : LocalDate { return LocalDate::of($year, $this->month, $this->isValidYear($year) ? $this->day : 28); }
[ "public", "function", "atYear", "(", "int", "$", "year", ")", ":", "LocalDate", "{", "return", "LocalDate", "::", "of", "(", "$", "year", ",", "$", "this", "->", "month", ",", "$", "this", "->", "isValidYear", "(", "$", "year", ")", "?", "$", "this", "->", "day", ":", "28", ")", ";", "}" ]
Combines this month-day with a year to create a LocalDate. This returns a LocalDate formed from this month-day and the specified year. A month-day of February 29th will be adjusted to February 28th in the resulting date if the year is not a leap year. @param int $year @return LocalDate @throws DateTimeException If the year is invalid.
[ "Combines", "this", "month", "-", "day", "with", "a", "year", "to", "create", "a", "LocalDate", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/MonthDay.php#L271-L274
train
brick/date-time
src/LocalDateTime.php
LocalDateTime.now
public static function now(TimeZone $timeZone, Clock $clock = null) : LocalDateTime { return ZonedDateTime::now($timeZone, $clock)->getDateTime(); }
php
public static function now(TimeZone $timeZone, Clock $clock = null) : LocalDateTime { return ZonedDateTime::now($timeZone, $clock)->getDateTime(); }
[ "public", "static", "function", "now", "(", "TimeZone", "$", "timeZone", ",", "Clock", "$", "clock", "=", "null", ")", ":", "LocalDateTime", "{", "return", "ZonedDateTime", "::", "now", "(", "$", "timeZone", ",", "$", "clock", ")", "->", "getDateTime", "(", ")", ";", "}" ]
Returns the current local date-time in the given time-zone, according to the given clock. If no clock is provided, the system clock is used. @param TimeZone $timeZone @param Clock|null $clock @return LocalDateTime
[ "Returns", "the", "current", "local", "date", "-", "time", "in", "the", "given", "time", "-", "zone", "according", "to", "the", "given", "clock", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDateTime.php#L73-L76
train
brick/date-time
src/LocalDateTime.php
LocalDateTime.parse
public static function parse(string $text, DateTimeParser $parser = null) : LocalDateTime { if (! $parser) { $parser = IsoParsers::localDateTime(); } return LocalDateTime::from($parser->parse($text)); }
php
public static function parse(string $text, DateTimeParser $parser = null) : LocalDateTime { if (! $parser) { $parser = IsoParsers::localDateTime(); } return LocalDateTime::from($parser->parse($text)); }
[ "public", "static", "function", "parse", "(", "string", "$", "text", ",", "DateTimeParser", "$", "parser", "=", "null", ")", ":", "LocalDateTime", "{", "if", "(", "!", "$", "parser", ")", "{", "$", "parser", "=", "IsoParsers", "::", "localDateTime", "(", ")", ";", "}", "return", "LocalDateTime", "::", "from", "(", "$", "parser", "->", "parse", "(", "$", "text", ")", ")", ";", "}" ]
Obtains an instance of `LocalDateTime` from a text string. @param string $text The text to parse, such as `2007-12-03T10:15:30`. @param DateTimeParser|null $parser The parser to use, defaults to the ISO 8601 parser. @return LocalDateTime @throws DateTimeException If the date-time is not valid. @throws DateTimeParseException If the text string does not follow the expected format.
[ "Obtains", "an", "instance", "of", "LocalDateTime", "from", "a", "text", "string", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDateTime.php#L105-L112
train
brick/date-time
src/LocalDateTime.php
LocalDateTime.fromDateTime
public static function fromDateTime(\DateTimeInterface $dateTime) : LocalDateTime { return new LocalDateTime( LocalDate::fromDateTime($dateTime), LocalTime::fromDateTime($dateTime) ); }
php
public static function fromDateTime(\DateTimeInterface $dateTime) : LocalDateTime { return new LocalDateTime( LocalDate::fromDateTime($dateTime), LocalTime::fromDateTime($dateTime) ); }
[ "public", "static", "function", "fromDateTime", "(", "\\", "DateTimeInterface", "$", "dateTime", ")", ":", "LocalDateTime", "{", "return", "new", "LocalDateTime", "(", "LocalDate", "::", "fromDateTime", "(", "$", "dateTime", ")", ",", "LocalTime", "::", "fromDateTime", "(", "$", "dateTime", ")", ")", ";", "}" ]
Creates a LocalDateTime from a native DateTime or DateTimeImmutable object. @param \DateTimeInterface $dateTime @return LocalDateTime
[ "Creates", "a", "LocalDateTime", "from", "a", "native", "DateTime", "or", "DateTimeImmutable", "object", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDateTime.php#L121-L127
train
brick/date-time
src/LocalDateTime.php
LocalDateTime.minOf
public static function minOf(LocalDateTime ...$times) : LocalDateTime { if (! $times) { throw new DateTimeException(__METHOD__ . ' does not accept less than 1 parameter.'); } $min = LocalDateTime::max(); foreach ($times as $time) { if ($time->isBefore($min)) { $min = $time; } } return $min; }
php
public static function minOf(LocalDateTime ...$times) : LocalDateTime { if (! $times) { throw new DateTimeException(__METHOD__ . ' does not accept less than 1 parameter.'); } $min = LocalDateTime::max(); foreach ($times as $time) { if ($time->isBefore($min)) { $min = $time; } } return $min; }
[ "public", "static", "function", "minOf", "(", "LocalDateTime", "...", "$", "times", ")", ":", "LocalDateTime", "{", "if", "(", "!", "$", "times", ")", "{", "throw", "new", "DateTimeException", "(", "__METHOD__", ".", "' does not accept less than 1 parameter.'", ")", ";", "}", "$", "min", "=", "LocalDateTime", "::", "max", "(", ")", ";", "foreach", "(", "$", "times", "as", "$", "time", ")", "{", "if", "(", "$", "time", "->", "isBefore", "(", "$", "min", ")", ")", "{", "$", "min", "=", "$", "time", ";", "}", "}", "return", "$", "min", ";", "}" ]
Returns the smallest LocalDateTime among the given values. @param LocalDateTime[] $times The LocalDateTime objects to compare. @return LocalDateTime The earliest LocalDateTime object. @throws DateTimeException If the array is empty.
[ "Returns", "the", "smallest", "LocalDateTime", "among", "the", "given", "values", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDateTime.php#L158-L173
train
brick/date-time
src/LocalDateTime.php
LocalDateTime.maxOf
public static function maxOf(LocalDateTime ...$times) : LocalDateTime { if (! $times) { throw new DateTimeException(__METHOD__ . ' does not accept less than 1 parameter.'); } $max = LocalDateTime::min(); foreach ($times as $time) { if ($time->isAfter($max)) { $max = $time; } } return $max; }
php
public static function maxOf(LocalDateTime ...$times) : LocalDateTime { if (! $times) { throw new DateTimeException(__METHOD__ . ' does not accept less than 1 parameter.'); } $max = LocalDateTime::min(); foreach ($times as $time) { if ($time->isAfter($max)) { $max = $time; } } return $max; }
[ "public", "static", "function", "maxOf", "(", "LocalDateTime", "...", "$", "times", ")", ":", "LocalDateTime", "{", "if", "(", "!", "$", "times", ")", "{", "throw", "new", "DateTimeException", "(", "__METHOD__", ".", "' does not accept less than 1 parameter.'", ")", ";", "}", "$", "max", "=", "LocalDateTime", "::", "min", "(", ")", ";", "foreach", "(", "$", "times", "as", "$", "time", ")", "{", "if", "(", "$", "time", "->", "isAfter", "(", "$", "max", ")", ")", "{", "$", "max", "=", "$", "time", ";", "}", "}", "return", "$", "max", ";", "}" ]
Returns the highest LocalDateTime among the given values. @param LocalDateTime[] $times The LocalDateTime objects to compare. @return LocalDateTime The latest LocalDateTime object. @throws DateTimeException If the array is empty.
[ "Returns", "the", "highest", "LocalDateTime", "among", "the", "given", "values", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDateTime.php#L184-L199
train
brick/date-time
src/LocalDateTime.php
LocalDateTime.withDate
public function withDate(LocalDate $date) : LocalDateTime { if ($date->isEqualTo($this->date)) { return $this; } return new LocalDateTime($date, $this->time); }
php
public function withDate(LocalDate $date) : LocalDateTime { if ($date->isEqualTo($this->date)) { return $this; } return new LocalDateTime($date, $this->time); }
[ "public", "function", "withDate", "(", "LocalDate", "$", "date", ")", ":", "LocalDateTime", "{", "if", "(", "$", "date", "->", "isEqualTo", "(", "$", "this", "->", "date", ")", ")", "{", "return", "$", "this", ";", "}", "return", "new", "LocalDateTime", "(", "$", "date", ",", "$", "this", "->", "time", ")", ";", "}" ]
Returns a copy of this LocalDateTime with the date altered. @param LocalDate $date @return LocalDateTime
[ "Returns", "a", "copy", "of", "this", "LocalDateTime", "with", "the", "date", "altered", "." ]
a1bbf608816baff12181b6c06f976ef00ca29c76
https://github.com/brick/date-time/blob/a1bbf608816baff12181b6c06f976ef00ca29c76/src/LocalDateTime.php#L296-L303
train