_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q13800
Date.getIsoFormats
train
public function getIsoFormats($locale = null) { return [ 'LT' => $this->getTranslationMessage('formats.LT', $locale, 'h:mm A'), 'LTS' => $this->getTranslationMessage('formats.LTS', $locale, 'h:mm:ss A'), 'L' => $this->getTranslationMessage('formats.L', $locale, 'MM/DD/YYYY'), 'LL' => $this->getTranslationMessage('formats.LL', $locale, 'MMMM D, YYYY'), 'LLL' => $this->getTranslationMessage('formats.LLL', $locale, 'MMMM D, YYYY h:mm A'), 'LLLL' => $this->getTranslationMessage('formats.LLLL', $locale, 'dddd, MMMM D, YYYY h:mm A'), ]; }
php
{ "resource": "" }
q13801
Date.getCalendarFormats
train
public function getCalendarFormats($locale = null) { return [ 'sameDay' => $this->getTranslationMessage('calendar.sameDay', $locale, '[Today at] LT'), 'nextDay' => $this->getTranslationMessage('calendar.nextDay', $locale, '[Tomorrow at] LT'), 'nextWeek' => $this->getTranslationMessage('calendar.nextWeek', $locale, 'dddd [at] LT'), 'lastDay' => $this->getTranslationMessage('calendar.lastDay', $locale, '[Yesterday at] LT'), 'lastWeek' => $this->getTranslationMessage('calendar.lastWeek', $locale, '[Last] dddd [at] LT'), 'sameElse' => $this->getTranslationMessage('calendar.sameElse', $locale, 'L'), ]; }
php
{ "resource": "" }
q13802
Date.getPaddedUnit
train
public function getPaddedUnit($unit, $length = 2, $padString = '0', $padType = STR_PAD_LEFT) { return ($this->$unit < 0 ? '-' : '').str_pad(abs($this->$unit), $length, $padString, $padType); }
php
{ "resource": "" }
q13803
Date.ordinal
train
public function ordinal(string $key, string $period = null): string { $number = $this->$key; $result = $this->translate('ordinal', [ ':number' => $number, ':period' => $period, ]); return strval($result === 'ordinal' ? $number : $result); }
php
{ "resource": "" }
q13804
Date.meridiem
train
public function meridiem(bool $isLower = false): string { $hour = $this->hour; $index = $hour < 12 ? 0 : 1; if ($isLower) { $key = 'meridiem.'.($index + 2); $result = $this->translate($key); if ($result !== $key) { return $result; } } $key = "meridiem.$index"; $result = $this->translate($key); if ($result === $key) { $result = $this->translate('meridiem', [ ':hour' => $this->hour, ':minute' => $this->minute, ':isLower' => $isLower, ]); if ($result === 'meridiem') { return $isLower ? $this->latinMeridiem : $this->latinUpperMeridiem; } } elseif ($isLower) { $result = mb_strtolower($result); } return $result; }
php
{ "resource": "" }
q13805
Date.getAltNumber
train
public function getAltNumber(string $key): string { $number = strlen($key) > 1 ? $this->$key : $this->rawFormat('h'); $translateKey = "alt_numbers.$number"; $symbol = $this->translate($translateKey); if ($symbol !== $translateKey) { return $symbol; } if ($number > 99 && $this->translate('alt_numbers.99') !== 'alt_numbers.99') { $start = ''; foreach ([10000, 1000, 100] as $exp) { $key = "alt_numbers_pow.$exp"; if ($number >= $exp && $number < $exp * 10 && ($pow = $this->translate($key)) !== $key) { $unit = floor($number / $exp); $number -= $unit * $exp; $start .= ($unit > 1 ? $this->translate("alt_numbers.$unit") : '').$pow; } } $result = ''; while ($number) { $chunk = $number % 100; $result = $this->translate("alt_numbers.$chunk").$result; $number = floor($number / 100); } return "$start$result"; } if ($number > 9 && $this->translate('alt_numbers.9') !== 'alt_numbers.9') { $result = ''; while ($number) { $chunk = $number % 10; $result = $this->translate("alt_numbers.$chunk").$result; $number = floor($number / 10); } return $result; } return $number; }
php
{ "resource": "" }
q13806
Date.setUnit
train
public function setUnit($unit, $value = null) { $unit = static::singularUnit($unit); $dateUnits = ['year', 'month', 'day']; if (in_array($unit, $dateUnits)) { return $this->setDate(...array_map(function ($name) use ($unit, $value) { return $name === $unit ? $value : $this->$name; }, $dateUnits)); } $units = ['hour', 'minute', 'second', 'micro']; if ($unit === 'millisecond' || $unit === 'milli') { $value *= 1000; $unit = 'micro'; } elseif ($unit === 'microsecond') { $unit = 'micro'; } return $this->setTime(...array_map(function ($name) use ($unit, $value) { return $name === $unit ? $value : $this->$name; }, $units)); }
php
{ "resource": "" }
q13807
Localization.setFallbackLocale
train
public static function setFallbackLocale($locale) { $translator = static::getTranslator(); if (method_exists($translator, 'setFallbackLocales')) { $translator->setFallbackLocales([$locale]); if ($translator instanceof Translator) { $preferredLocale = $translator->getLocale(); $translator->setMessages($preferredLocale, array_replace_recursive( $translator->getMessages()[$locale] ?? [], Translator::get($locale)->getMessages()[$locale] ?? [], $translator->getMessages($preferredLocale) )); } } }
php
{ "resource": "" }
q13808
Localization.localeHasShortUnits
train
public static function localeHasShortUnits($locale) { return static::executeWithLocale($locale, function ($newLocale, TranslatorInterface $translator) { return $newLocale && ( ($y = static::translateWith($translator, 'y')) !== 'y' && $y !== static::translateWith($translator, 'year') ) || ( ($y = static::translateWith($translator, 'd')) !== 'd' && $y !== static::translateWith($translator, 'day') ) || ( ($y = static::translateWith($translator, 'h')) !== 'h' && $y !== static::translateWith($translator, 'hour') ); }); }
php
{ "resource": "" }
q13809
Localization.getAvailableLocalesInfo
train
public static function getAvailableLocalesInfo() { $languages = []; foreach (static::getAvailableLocales() as $id) { $languages[$id] = new Language($id); } return $languages; }
php
{ "resource": "" }
q13810
Creator.createFromDate
train
public static function createFromDate($year = null, $month = null, $day = null, $tz = null) { return static::create($year, $month, $day, null, null, null, $tz); }
php
{ "resource": "" }
q13811
Creator.createMidnightDate
train
public static function createMidnightDate($year = null, $month = null, $day = null, $tz = null) { return static::create($year, $month, $day, 0, 0, 0, $tz); }
php
{ "resource": "" }
q13812
Creator.createFromLocaleFormat
train
public static function createFromLocaleFormat($format, $locale, $time, $tz = null) { return static::rawCreateFromFormat($format, static::translateTimeString($time, $locale, 'en'), $tz); }
php
{ "resource": "" }
q13813
Creator.createFromLocaleIsoFormat
train
public static function createFromLocaleIsoFormat($format, $locale, $time, $tz = null) { $time = static::translateTimeString($time, $locale, 'en', CarbonInterface::TRANSLATE_MONTHS | CarbonInterface::TRANSLATE_DAYS | CarbonInterface::TRANSLATE_MERIDIEM); return static::createFromIsoFormat($format, $time, $tz, $locale); }
php
{ "resource": "" }
q13814
Creator.make
train
public static function make($var) { if ($var instanceof DateTimeInterface) { return static::instance($var); } $date = null; if (is_string($var)) { $var = trim($var); $first = substr($var, 0, 1); if (is_string($var) && $first !== 'P' && $first !== 'R' && preg_match('/[a-z0-9]/i', $var)) { $date = static::parse($var); } } return $date; }
php
{ "resource": "" }
q13815
Converter.toArray
train
public function toArray() { return [ 'year' => $this->year, 'month' => $this->month, 'day' => $this->day, 'dayOfWeek' => $this->dayOfWeek, 'dayOfYear' => $this->dayOfYear, 'hour' => $this->hour, 'minute' => $this->minute, 'second' => $this->second, 'micro' => $this->micro, 'timestamp' => $this->timestamp, 'formatted' => $this->rawFormat(defined('static::DEFAULT_TO_STRING_FORMAT') ? static::DEFAULT_TO_STRING_FORMAT : CarbonInterface::DEFAULT_TO_STRING_FORMAT), 'timezone' => $this->timezone, ]; }
php
{ "resource": "" }
q13816
CarbonTimeZone.instance
train
public static function instance($object = null, $objectDump = null) { $tz = $object; if ($tz instanceof static) { return $tz; } if ($tz === null) { return new static(); } if (!$tz instanceof DateTimeZone) { $tz = static::getDateTimeZoneFromName($object); } if ($tz === false) { if (Carbon::isStrictModeEnabled()) { throw new InvalidArgumentException('Unknown or bad timezone ('.($objectDump ?: $object).')'); } return false; } return new static($tz->getName()); }
php
{ "resource": "" }
q13817
CarbonTimeZone.getAbbreviatedName
train
public function getAbbreviatedName($dst = false) { $name = $this->getName(); foreach ($this->listAbbreviations() as $abbreviation => $zones) { foreach ($zones as $zone) { if ($zone['timezone_id'] === $name && $zone['dst'] == $dst) { return $abbreviation; } } } return 'unknown'; }
php
{ "resource": "" }
q13818
CarbonTimeZone.toRegionTimeZone
train
public function toRegionTimeZone(DateTimeInterface $date = null) { $tz = $this->toRegionName($date); if ($tz === false) { if (Carbon::isStrictModeEnabled()) { throw new InvalidArgumentException('Unknown timezone for offset '.$this->getOffset($date ?: Carbon::now($this)).' seconds.'); } return false; } return new static($tz); }
php
{ "resource": "" }
q13819
CarbonPeriod.createFromIso
train
public static function createFromIso($iso, $options = null) { $params = static::parseIso8601($iso); $instance = static::createFromArray($params); if ($options !== null) { $instance->setOptions($options); } return $instance; }
php
{ "resource": "" }
q13820
CarbonPeriod.intervalHasTime
train
protected static function intervalHasTime(DateInterval $interval) { // The array_key_exists and get_object_vars are used as a workaround to check microsecond support. // Both isset and property_exists will fail on PHP 7.0.14 - 7.0.21 due to the following bug: // https://bugs.php.net/bug.php?id=74852 return $interval->h || $interval->i || $interval->s || array_key_exists('f', get_object_vars($interval)) && $interval->f; }
php
{ "resource": "" }
q13821
CarbonPeriod.parseIso8601
train
protected static function parseIso8601($iso) { $result = []; $interval = null; $start = null; $end = null; foreach (explode('/', $iso) as $key => $part) { if ($key === 0 && preg_match('/^R([0-9]*)$/', $part, $match)) { $parsed = strlen($match[1]) ? (int) $match[1] : null; } elseif ($interval === null && $parsed = CarbonInterval::make($part)) { $interval = $part; } elseif ($start === null && $parsed = Carbon::make($part)) { $start = $part; } elseif ($end === null && $parsed = Carbon::make(static::addMissingParts($start, $part))) { $end = $part; } else { throw new InvalidArgumentException("Invalid ISO 8601 specification: $iso."); } $result[] = $parsed; } return $result; }
php
{ "resource": "" }
q13822
CarbonPeriod.addMissingParts
train
protected static function addMissingParts($source, $target) { $pattern = '/'.preg_replace('/[0-9]+/', '[0-9]+', preg_quote($target, '/')).'$/'; $result = preg_replace($pattern, $target, $source, 1, $count); return $count ? $result : $target; }
php
{ "resource": "" }
q13823
CarbonPeriod.setDateClass
train
public function setDateClass(string $dateClass) { if (!is_a($dateClass, CarbonInterface::class, true)) { throw new InvalidArgumentException(sprintf( 'Given class does not implement %s: %s', CarbonInterface::class, $dateClass )); } $this->dateClass = $dateClass; if (is_a($dateClass, Carbon::class, true)) { $this->toggleOptions(static::IMMUTABLE, false); } elseif (is_a($dateClass, CarbonImmutable::class, true)) { $this->toggleOptions(static::IMMUTABLE, true); } return $this; }
php
{ "resource": "" }
q13824
CarbonPeriod.setDateInterval
train
public function setDateInterval($interval) { if (!$interval = CarbonInterval::make($interval)) { throw new InvalidArgumentException('Invalid interval.'); } if ($interval->spec() === 'PT0S') { throw new InvalidArgumentException('Empty interval is not accepted.'); } $this->dateInterval = $interval; $this->isDefaultInterval = false; $this->handleChangedParameters(); return $this; }
php
{ "resource": "" }
q13825
CarbonPeriod.setDates
train
public function setDates($start, $end) { $this->setStartDate($start); $this->setEndDate($end); return $this; }
php
{ "resource": "" }
q13826
CarbonPeriod.setOptions
train
public function setOptions($options) { if (!is_int($options) && !is_null($options)) { throw new InvalidArgumentException('Invalid options.'); } $this->options = $options ?: 0; $this->handleChangedParameters(); return $this; }
php
{ "resource": "" }
q13827
CarbonPeriod.toggleOptions
train
public function toggleOptions($options, $state = null) { if ($state === null) { $state = ($this->options & $options) !== $options; } return $this->setOptions( $state ? $this->options | $options : $this->options & ~$options ); }
php
{ "resource": "" }
q13828
CarbonPeriod.addFilter
train
public function addFilter($callback, $name = null) { $tuple = $this->createFilterTuple(func_get_args()); $this->filters[] = $tuple; $this->handleChangedParameters(); return $this; }
php
{ "resource": "" }
q13829
CarbonPeriod.prependFilter
train
public function prependFilter($callback, $name = null) { $tuple = $this->createFilterTuple(func_get_args()); array_unshift($this->filters, $tuple); $this->handleChangedParameters(); return $this; }
php
{ "resource": "" }
q13830
CarbonPeriod.createFilterTuple
train
protected function createFilterTuple(array $parameters) { $method = array_shift($parameters); if (!$this->isCarbonPredicateMethod($method)) { return [$method, array_shift($parameters)]; } return [function ($date) use ($method, $parameters) { return call_user_func_array([$date, $method], $parameters); }, $method]; }
php
{ "resource": "" }
q13831
CarbonPeriod.removeFilter
train
public function removeFilter($filter) { $key = is_callable($filter) ? 0 : 1; $this->filters = array_values(array_filter( $this->filters, function ($tuple) use ($key, $filter) { return $tuple[$key] !== $filter; } )); $this->updateInternalState(); $this->handleChangedParameters(); return $this; }
php
{ "resource": "" }
q13832
CarbonPeriod.hasFilter
train
public function hasFilter($filter) { $key = is_callable($filter) ? 0 : 1; foreach ($this->filters as $tuple) { if ($tuple[$key] === $filter) { return true; } } return false; }
php
{ "resource": "" }
q13833
CarbonPeriod.setFilters
train
public function setFilters(array $filters) { $this->filters = $filters; $this->updateInternalState(); $this->handleChangedParameters(); return $this; }
php
{ "resource": "" }
q13834
CarbonPeriod.resetFilters
train
public function resetFilters() { $this->filters = []; if ($this->endDate !== null) { $this->filters[] = [static::END_DATE_FILTER, null]; } if ($this->recurrences !== null) { $this->filters[] = [static::RECURRENCES_FILTER, null]; } $this->handleChangedParameters(); return $this; }
php
{ "resource": "" }
q13835
CarbonPeriod.updateInternalState
train
protected function updateInternalState() { if (!$this->hasFilter(static::END_DATE_FILTER)) { $this->endDate = null; } if (!$this->hasFilter(static::RECURRENCES_FILTER)) { $this->recurrences = null; } }
php
{ "resource": "" }
q13836
CarbonPeriod.setStartDate
train
public function setStartDate($date, $inclusive = null) { if (!$date = call_user_func([$this->dateClass, 'make'], $date)) { throw new InvalidArgumentException('Invalid start date.'); } $this->startDate = $date; if ($inclusive !== null) { $this->toggleOptions(static::EXCLUDE_START_DATE, !$inclusive); } return $this; }
php
{ "resource": "" }
q13837
CarbonPeriod.setEndDate
train
public function setEndDate($date, $inclusive = null) { if (!is_null($date) && !$date = call_user_func([$this->dateClass, 'make'], $date)) { throw new InvalidArgumentException('Invalid end date.'); } if (!$date) { return $this->removeFilter(static::END_DATE_FILTER); } $this->endDate = $date; if ($inclusive !== null) { $this->toggleOptions(static::EXCLUDE_END_DATE, !$inclusive); } if (!$this->hasFilter(static::END_DATE_FILTER)) { return $this->addFilter(static::END_DATE_FILTER); } $this->handleChangedParameters(); return $this; }
php
{ "resource": "" }
q13838
CarbonPeriod.filterEndDate
train
protected function filterEndDate($current) { if (!$this->isEndExcluded() && $current == $this->endDate) { return true; } if ($this->dateInterval->invert ? $current > $this->endDate : $current < $this->endDate) { return true; } return static::END_ITERATION; }
php
{ "resource": "" }
q13839
CarbonPeriod.handleChangedParameters
train
protected function handleChangedParameters() { if (($this->getOptions() & static::IMMUTABLE) && $this->dateClass === Carbon::class) { $this->setDateClass(CarbonImmutable::class); } elseif (!($this->getOptions() & static::IMMUTABLE) && $this->dateClass === CarbonImmutable::class) { $this->setDateClass(Carbon::class); } $this->validationResult = null; }
php
{ "resource": "" }
q13840
CarbonPeriod.validateCurrentDate
train
protected function validateCurrentDate() { if ($this->current === null) { $this->rewind(); } // Check after the first rewind to avoid repeating the initial validation. if ($this->validationResult !== null) { return $this->validationResult; } return $this->validationResult = $this->checkFilters(); }
php
{ "resource": "" }
q13841
CarbonPeriod.checkFilters
train
protected function checkFilters() { $current = $this->prepareForReturn($this->current); foreach ($this->filters as $tuple) { $result = call_user_func( $tuple[0], $current->copy(), $this->key, $this ); if ($result === static::END_ITERATION) { return static::END_ITERATION; } if (!$result) { return false; } } return true; }
php
{ "resource": "" }
q13842
CarbonPeriod.prepareForReturn
train
protected function prepareForReturn(CarbonInterface $date) { $date = call_user_func([$this->dateClass, 'make'], $date); if ($this->timezone) { $date = $date->setTimezone($this->timezone); } return $date; }
php
{ "resource": "" }
q13843
CarbonPeriod.next
train
public function next() { if ($this->current === null) { $this->rewind(); } if ($this->validationResult !== static::END_ITERATION) { $this->key++; $this->incrementCurrentDateUntilValid(); } }
php
{ "resource": "" }
q13844
CarbonPeriod.rewind
train
public function rewind() { $this->key = 0; $this->current = call_user_func([$this->dateClass, 'make'], $this->startDate); $settings = $this->getSettings(); $locale = $this->getLocalTranslator()->getLocale(); if ($locale) { $settings['locale'] = $locale; } $this->current->settings($settings); $this->timezone = static::intervalHasTime($this->dateInterval) ? $this->current->getTimezone() : null; if ($this->timezone) { $this->current = $this->current->utc(); } $this->validationResult = null; if ($this->isStartExcluded() || $this->validateCurrentDate() === false) { $this->incrementCurrentDateUntilValid(); } }
php
{ "resource": "" }
q13845
CarbonPeriod.incrementCurrentDateUntilValid
train
protected function incrementCurrentDateUntilValid() { $attempts = 0; do { $this->current = $this->current->add($this->dateInterval); $this->validationResult = null; if (++$attempts > static::NEXT_MAX_ATTEMPTS) { throw new RuntimeException('Could not find next valid date.'); } } while ($this->validateCurrentDate() === false); }
php
{ "resource": "" }
q13846
CarbonPeriod.toIso8601String
train
public function toIso8601String() { $parts = []; if ($this->recurrences !== null) { $parts[] = 'R'.$this->recurrences; } $parts[] = $this->startDate->toIso8601String(); $parts[] = $this->dateInterval->spec(); if ($this->endDate !== null) { $parts[] = $this->endDate->toIso8601String(); } return implode('/', $parts); }
php
{ "resource": "" }
q13847
CarbonPeriod.toString
train
public function toString() { $translator = call_user_func([$this->dateClass, 'getTranslator']); $parts = []; $format = !$this->startDate->isStartOfDay() || $this->endDate && !$this->endDate->isStartOfDay() ? 'Y-m-d H:i:s' : 'Y-m-d'; if ($this->recurrences !== null) { $parts[] = $this->translate('period_recurrences', [], $this->recurrences, $translator); } $parts[] = $this->translate('period_interval', [':interval' => $this->dateInterval->forHumans([ 'join' => true, ])], null, $translator); $parts[] = $this->translate('period_start_date', [':date' => $this->startDate->rawFormat($format)], null, $translator); if ($this->endDate !== null) { $parts[] = $this->translate('period_end_date', [':date' => $this->endDate->rawFormat($format)], null, $translator); } $result = implode(' ', $parts); return mb_strtoupper(mb_substr($result, 0, 1)).mb_substr($result, 1); }
php
{ "resource": "" }
q13848
CarbonPeriod.toArray
train
public function toArray() { $state = [ $this->key, $this->current ? $this->current->copy() : null, $this->validationResult, ]; $result = iterator_to_array($this); [ $this->key, $this->current, $this->validationResult ] = $state; return $result; }
php
{ "resource": "" }
q13849
CarbonPeriod.callMacro
train
protected function callMacro($name, $parameters) { $macro = static::$macros[$name]; if ($macro instanceof Closure) { return call_user_func_array($macro->bindTo($this, static::class), $parameters); } return call_user_func_array($macro, $parameters); }
php
{ "resource": "" }
q13850
CarbonInterval.getCascadeFactors
train
public static function getCascadeFactors() { return static::$cascadeFactors ?: [ 'milliseconds' => [Carbon::MICROSECONDS_PER_MILLISECOND, 'microseconds'], 'seconds' => [Carbon::MILLISECONDS_PER_SECOND, 'milliseconds'], 'minutes' => [Carbon::SECONDS_PER_MINUTE, 'seconds'], 'hours' => [Carbon::MINUTES_PER_HOUR, 'minutes'], 'dayz' => [Carbon::HOURS_PER_DAY, 'hours'], 'months' => [Carbon::DAYS_PER_WEEK * Carbon::WEEKS_PER_MONTH, 'dayz'], 'years' => [Carbon::MONTHS_PER_YEAR, 'months'], ]; }
php
{ "resource": "" }
q13851
CarbonInterval.getFactor
train
public static function getFactor($source, $target) { $source = self::standardizeUnit($source); $target = self::standardizeUnit($target); $factors = static::getFlipCascadeFactors(); if (isset($factors[$source])) { [$to, $factor] = $factors[$source]; if ($to === $target) { return $factor; } } return null; }
php
{ "resource": "" }
q13852
CarbonInterval.make
train
public static function make($var) { if ($var instanceof DateInterval) { return static::instance($var); } if (!is_string($var)) { return null; } $var = trim($var); if (preg_match('/^P[T0-9]/', $var)) { return new static($var); } if (preg_match('/^(?:\h*\d+(?:\.\d+)?\h*[a-z]+)+$/i', $var)) { return static::fromString($var); } /** @var static $interval */ $interval = static::createFromDateString($var); return $interval->isEmpty() ? null : $interval; }
php
{ "resource": "" }
q13853
CarbonInterval.createFromDateString
train
public static function createFromDateString($time) { $interval = parent::createFromDateString($time); if ($interval instanceof DateInterval && !($interval instanceof static)) { $interval = static::instance($interval); } return static::instance($interval); }
php
{ "resource": "" }
q13854
CarbonInterval.isEmpty
train
public function isEmpty() { return $this->years === 0 && $this->months === 0 && $this->dayz === 0 && !$this->days && $this->hours === 0 && $this->minutes === 0 && $this->seconds === 0 && $this->microseconds === 0; }
php
{ "resource": "" }
q13855
CarbonInterval.sub
train
public function sub($unit, $value = 1) { if (is_numeric($unit)) { $_unit = $value; $value = $unit; $unit = $_unit; unset($_unit); } return $this->add($unit, -floatval($value)); }
php
{ "resource": "" }
q13856
CarbonInterval.times
train
public function times($factor) { if ($factor < 0) { $this->invert = $this->invert ? 0 : 1; $factor = -$factor; } $this->years = (int) round($this->years * $factor); $this->months = (int) round($this->months * $factor); $this->dayz = (int) round($this->dayz * $factor); $this->hours = (int) round($this->hours * $factor); $this->minutes = (int) round($this->minutes * $factor); $this->seconds = (int) round($this->seconds * $factor); $this->microseconds = (int) round($this->microseconds * $factor); return $this; }
php
{ "resource": "" }
q13857
CarbonInterval.getDateIntervalSpec
train
public static function getDateIntervalSpec(DateInterval $interval) { $date = array_filter([ static::PERIOD_YEARS => abs($interval->y), static::PERIOD_MONTHS => abs($interval->m), static::PERIOD_DAYS => abs($interval->d), ]); $time = array_filter([ static::PERIOD_HOURS => abs($interval->h), static::PERIOD_MINUTES => abs($interval->i), static::PERIOD_SECONDS => abs($interval->s), ]); $specString = static::PERIOD_PREFIX; foreach ($date as $key => $value) { $specString .= $value.$key; } if (count($time) > 0) { $specString .= static::PERIOD_TIME_PREFIX; foreach ($time as $key => $value) { $specString .= $value.$key; } } return $specString === static::PERIOD_PREFIX ? 'PT0S' : $specString; }
php
{ "resource": "" }
q13858
CarbonInterval.cascade
train
public function cascade() { foreach (static::getFlipCascadeFactors() as $source => [$target, $factor]) { if ($source === 'dayz' && $target === 'weeks') { continue; } $value = $this->$source; $this->$source = $modulo = ($factor + ($value % $factor)) % $factor; $this->$target += ($value - $modulo) / $factor; if ($this->$source > 0 && $this->$target < 0) { $this->$source -= $factor; $this->$target++; } } return $this->solveNegativeInterval(); }
php
{ "resource": "" }
q13859
CarbonInterval.total
train
public function total($unit) { $realUnit = $unit = strtolower($unit); if (in_array($unit, ['days', 'weeks'])) { $realUnit = 'dayz'; } elseif (!in_array($unit, ['microseconds', 'milliseconds', 'seconds', 'minutes', 'hours', 'dayz', 'months', 'years'])) { throw new InvalidArgumentException("Unknown unit '$unit'."); } $result = 0; $cumulativeFactor = 0; $unitFound = false; $factors = static::getFlipCascadeFactors(); foreach ($factors as $source => [$target, $factor]) { if ($source === $realUnit) { $unitFound = true; $value = $this->$source; if ($source === 'microseconds' && isset($factors['milliseconds'])) { $value %= Carbon::MICROSECONDS_PER_MILLISECOND; } $result += $value; $cumulativeFactor = 1; } if ($factor === false) { if ($unitFound) { break; } $result = 0; $cumulativeFactor = 0; continue; } if ($target === $realUnit) { $unitFound = true; } if ($cumulativeFactor) { $cumulativeFactor *= $factor; $result += $this->$target * $cumulativeFactor; continue; } $value = $this->$source; if ($source === 'microseconds' && isset($factors['milliseconds'])) { $value %= Carbon::MICROSECONDS_PER_MILLISECOND; } $result = ($result + $value) / $factor; } if (isset($target) && !$cumulativeFactor) { $result += $this->$target; } if (!$unitFound) { throw new \InvalidArgumentException("Unit $unit have no configuration to get total from other units."); } if ($unit === 'weeks') { return $result / static::getDaysPerWeek(); } return $result; }
php
{ "resource": "" }
q13860
Language.getNames
train
public function getNames(): array { if (!$this->names) { $this->names = static::all()[$this->code] ?? [ 'isoName' => $this->code, 'nativeName' => $this->code, ]; } return $this->names; }
php
{ "resource": "" }
q13861
Language.getRegionName
train
public function getRegionName(): ?string { return $this->region ? (static::regions()[$this->region] ?? $this->region) : null; }
php
{ "resource": "" }
q13862
Language.getFullIsoName
train
public function getFullIsoName(): string { if (!$this->isoName) { $this->isoName = $this->getNames()['isoName']; } return $this->isoName; }
php
{ "resource": "" }
q13863
Language.getFullNativeName
train
public function getFullNativeName(): string { if (!$this->nativeName) { $this->nativeName = $this->getNames()['nativeName']; } return $this->nativeName; }
php
{ "resource": "" }
q13864
Language.getIsoName
train
public function getIsoName(): string { $name = $this->getFullIsoName(); return trim(strstr($name, ',', true) ?: $name); }
php
{ "resource": "" }
q13865
Language.getNativeName
train
public function getNativeName(): string { $name = $this->getFullNativeName(); return trim(strstr($name, ',', true) ?: $name); }
php
{ "resource": "" }
q13866
Language.getIsoDescription
train
public function getIsoDescription() { $region = $this->getRegionName(); $variant = $this->getVariantName(); return $this->getIsoName().($region ? ' ('.$region.')' : '').($variant ? ' ('.$variant.')' : ''); }
php
{ "resource": "" }
q13867
Language.getNativeDescription
train
public function getNativeDescription() { $region = $this->getRegionName(); $variant = $this->getVariantName(); return $this->getNativeName().($region ? ' ('.$region.')' : '').($variant ? ' ('.$variant.')' : ''); }
php
{ "resource": "" }
q13868
Language.getFullIsoDescription
train
public function getFullIsoDescription() { $region = $this->getRegionName(); $variant = $this->getVariantName(); return $this->getFullIsoName().($region ? ' ('.$region.')' : '').($variant ? ' ('.$variant.')' : ''); }
php
{ "resource": "" }
q13869
Language.getFullNativeDescription
train
public function getFullNativeDescription() { $region = $this->getRegionName(); $variant = $this->getVariantName(); return $this->getFullNativeName().($region ? ' ('.$region.')' : '').($variant ? ' ('.$variant.')' : ''); }
php
{ "resource": "" }
q13870
Translator.get
train
public static function get($locale = null) { $locale = $locale ?: 'en'; if (!isset(static::$singletons[$locale])) { static::$singletons[$locale] = new static($locale ?: 'en'); } return static::$singletons[$locale]; }
php
{ "resource": "" }
q13871
Translator.removeDirectory
train
public function removeDirectory(string $directory) { $search = rtrim(strtr($directory, '\\', '/'), '/'); return $this->setDirectories(array_filter($this->getDirectories(), function ($item) use ($search) { return rtrim(strtr($item, '\\', '/'), '/') !== $search; })); }
php
{ "resource": "" }
q13872
Translator.loadMessagesFromFile
train
protected function loadMessagesFromFile($locale) { if (isset($this->messages[$locale])) { return true; } return $this->resetMessages($locale); }
php
{ "resource": "" }
q13873
Translator.setMessages
train
public function setMessages($locale, $messages) { $this->loadMessagesFromFile($locale); $this->addResource('array', $messages, $locale); $this->messages[$locale] = array_merge( isset($this->messages[$locale]) ? $this->messages[$locale] : [], $messages ); return $this; }
php
{ "resource": "" }
q13874
Translator.getMessages
train
public function getMessages($locale = null) { return $locale === null ? $this->messages : $this->messages[$locale]; }
php
{ "resource": "" }
q13875
Options.getSettings
train
public function getSettings() { $settings = []; $map = [ 'localStrictModeEnabled' => 'strictMode', 'localMonthsOverflow' => 'monthOverflow', 'localYearsOverflow' => 'yearOverflow', 'localHumanDiffOptions' => 'humanDiffOptions', 'localToStringFormat' => 'toStringFormat', 'localSerializer' => 'toJsonFormat', 'localMacros' => 'macros', 'localGenericMacros' => 'genericMacros', 'locale' => 'locale', 'tzName' => 'timezone', 'localFormatFunction' => 'formatFunction', ]; foreach ($map as $property => $key) { $value = $this->$property ?? null; if ($value !== null) { $settings[$key] = $value; } } return $settings; }
php
{ "resource": "" }
q13876
Macro.genericMacro
train
public static function genericMacro($macro, $priority = 0) { if (!isset(static::$globalGenericMacros[$priority])) { static::$globalGenericMacros[$priority] = []; krsort(static::$globalGenericMacros, SORT_NUMERIC); } static::$globalGenericMacros[$priority][] = $macro; }
php
{ "resource": "" }
q13877
Difference.diffInMonths
train
public function diffInMonths($date = null, $absolute = true) { $date = $this->resolveCarbon($date); return $this->diffInYears($date, $absolute) * static::MONTHS_PER_YEAR + (int) $this->diff($date, $absolute)->format('%r%m'); }
php
{ "resource": "" }
q13878
Difference.diffInHoursFiltered
train
public function diffInHoursFiltered(Closure $callback, $date = null, $absolute = true) { return $this->diffFiltered(CarbonInterval::hour(), $callback, $date, $absolute); }
php
{ "resource": "" }
q13879
Difference.diffInWeekdays
train
public function diffInWeekdays($date = null, $absolute = true) { return $this->diffInDaysFiltered(function (CarbonInterface $date) { return $date->isWeekday(); }, $date, $absolute); }
php
{ "resource": "" }
q13880
Difference.diffInWeekendDays
train
public function diffInWeekendDays($date = null, $absolute = true) { return $this->diffInDaysFiltered(function (CarbonInterface $date) { return $date->isWeekend(); }, $date, $absolute); }
php
{ "resource": "" }
q13881
Difference.diffInRealHours
train
public function diffInRealHours($date = null, $absolute = true) { return (int) ($this->diffInRealSeconds($date, $absolute) / static::SECONDS_PER_MINUTE / static::MINUTES_PER_HOUR); }
php
{ "resource": "" }
q13882
Difference.diffInRealMinutes
train
public function diffInRealMinutes($date = null, $absolute = true) { return (int) ($this->diffInRealSeconds($date, $absolute) / static::SECONDS_PER_MINUTE); }
php
{ "resource": "" }
q13883
Difference.diffInMicroseconds
train
public function diffInMicroseconds($date = null, $absolute = true) { $diff = $this->diff($this->resolveCarbon($date)); $value = (int) round((((($diff->days * static::HOURS_PER_DAY) + $diff->h) * static::MINUTES_PER_HOUR + $diff->i) * static::SECONDS_PER_MINUTE + ($diff->f + $diff->s)) * static::MICROSECONDS_PER_SECOND); return $absolute || !$diff->invert ? $value : -$value; }
php
{ "resource": "" }
q13884
Difference.diffInMilliseconds
train
public function diffInMilliseconds($date = null, $absolute = true) { return (int) ($this->diffInMicroseconds($date, $absolute) / static::MICROSECONDS_PER_MILLISECOND); }
php
{ "resource": "" }
q13885
Difference.diffInRealSeconds
train
public function diffInRealSeconds($date = null, $absolute = true) { /** @var CarbonInterface $date */ $date = $this->resolveCarbon($date); $value = $date->getTimestamp() - $this->getTimestamp(); return $absolute ? abs($value) : $value; }
php
{ "resource": "" }
q13886
Difference.diffInRealMicroseconds
train
public function diffInRealMicroseconds($date = null, $absolute = true) { /** @var CarbonInterface $date */ $date = $this->resolveCarbon($date); $value = ($date->timestamp - $this->timestamp) * static::MICROSECONDS_PER_SECOND + $date->micro - $this->micro; return $absolute ? abs($value) : $value; }
php
{ "resource": "" }
q13887
Difference.diffInRealMilliseconds
train
public function diffInRealMilliseconds($date = null, $absolute = true) { return (int) ($this->diffInRealMicroseconds($date, $absolute) / static::MICROSECONDS_PER_MILLISECOND); }
php
{ "resource": "" }
q13888
Boundaries.endOfSecond
train
public function endOfSecond() { return $this->setTime($this->hour, $this->minute, $this->second, static::MICROSECONDS_PER_SECOND - 1); }
php
{ "resource": "" }
q13889
Boundaries.startOf
train
public function startOf($unit, ...$params) { $ucfUnit = ucfirst(static::singularUnit($unit)); $method = "startOf$ucfUnit"; if (!method_exists($this, $method)) { throw new InvalidArgumentException("Unknown unit '$unit'"); } return $this->$method(...$params); }
php
{ "resource": "" }
q13890
Units.add
train
public function add($unit, $value = 1, $overflow = null) { if (is_string($unit) && func_num_args() === 1) { $unit = CarbonInterval::make($unit); } if ($unit instanceof DateInterval) { return parent::add($unit); } if (is_numeric($unit)) { $tempUnit = $value; $value = $unit; $unit = $tempUnit; } return $this->addUnit($unit, $value, $overflow); }
php
{ "resource": "" }
q13891
Units.subUnit
train
public function subUnit($unit, $value = 1, $overflow = null) { return $this->addUnit($unit, -$value, $overflow); }
php
{ "resource": "" }
q13892
Rounding.roundUnit
train
public function roundUnit($unit, $precision = 1, $function = 'round') { $metaUnits = [ // @call roundUnit 'millennium' => [static::YEARS_PER_MILLENNIUM, 'year'], // @call roundUnit 'century' => [static::YEARS_PER_CENTURY, 'year'], // @call roundUnit 'decade' => [static::YEARS_PER_DECADE, 'year'], // @call roundUnit 'quarter' => [static::MONTHS_PER_QUARTER, 'month'], // @call roundUnit 'millisecond' => [1000, 'microsecond'], ]; $normalizedUnit = static::singularUnit($unit); $ranges = array_merge(static::getRangesByUnit(), [ // @call roundUnit 'microsecond' => [0, 999999], ]); $factor = 1; if (isset($metaUnits[$normalizedUnit])) { [$factor, $normalizedUnit] = $metaUnits[$normalizedUnit]; } $precision *= $factor; if (!isset($ranges[$normalizedUnit])) { throw new InvalidArgumentException("Unknown unit '$unit' to floor"); } $found = false; $fraction = 0; $arguments = null; $factor = $this->year < 0 ? -1 : 1; $changes = []; foreach ($ranges as $unit => [$minimum, $maximum]) { if ($normalizedUnit === $unit) { $arguments = [$this->$unit, $minimum]; $fraction = $precision - floor($precision); $found = true; continue; } if ($found) { $delta = $maximum + 1 - $minimum; $factor /= $delta; $fraction *= $delta; $arguments[0] += $this->$unit * $factor; $changes[$unit] = round($minimum + ($fraction ? $fraction * call_user_func($function, ($this->$unit - $minimum) / $fraction) : 0)); // Cannot use modulo as it lose double precision while ($changes[$unit] >= $delta) { $changes[$unit] -= $delta; } $fraction -= floor($fraction); } } [$value, $minimum] = $arguments; /** @var CarbonInterface $result */ $result = $this->$normalizedUnit(floor(call_user_func($function, ($value - $minimum) / $precision) * $precision + $minimum)); foreach ($changes as $unit => $value) { $result = $result->$unit($value); } return $result; }
php
{ "resource": "" }
q13893
Rounding.roundWeek
train
public function roundWeek($weekStartsAt = null) { return $this->closest($this->copy()->floorWeek($weekStartsAt), $this->copy()->ceilWeek($weekStartsAt)); }
php
{ "resource": "" }
q13894
Rounding.ceilWeek
train
public function ceilWeek($weekStartsAt = null) { if ($this->isMutable()) { $startOfWeek = $this->copy()->startOfWeek($weekStartsAt); return $startOfWeek != $this ? $this->startOfWeek($weekStartsAt)->addWeek() : $this; } $startOfWeek = $this->startOfWeek($weekStartsAt); return $startOfWeek != $this ? $startOfWeek->addWeek() : $this->copy(); }
php
{ "resource": "" }
q13895
Comparison.isSameUnit
train
public function isSameUnit($unit, $date = null) { $units = [ // @call isSameUnit 'year' => 'Y', // @call isSameUnit 'week' => 'o-W', // @call isSameUnit 'day' => 'Y-m-d', // @call isSameUnit 'hour' => 'Y-m-d H', // @call isSameUnit 'minute' => 'Y-m-d H:i', // @call isSameUnit 'second' => 'Y-m-d H:i:s', // @call isSameUnit 'micro' => 'Y-m-d H:i:s.u', // @call isSameUnit 'microsecond' => 'Y-m-d H:i:s.u', ]; if (!isset($units[$unit])) { if (isset($this->$unit)) { $date = $date ? static::instance($date) : static::now($this->tz); static::expectDateTime($date); return $this->$unit === $date->$unit; } if ($this->localStrictModeEnabled ?? static::isStrictModeEnabled()) { throw new InvalidArgumentException("Bad comparison unit: '$unit'"); } return false; } return $this->isSameAs($units[$unit], $date); }
php
{ "resource": "" }
q13896
Comparison.isDayOfWeek
train
public function isDayOfWeek($dayOfWeek) { if (is_string($dayOfWeek) && defined($constant = static::class.'::'.strtoupper($dayOfWeek))) { $dayOfWeek = constant($constant); } return $this->dayOfWeek === $dayOfWeek; }
php
{ "resource": "" }
q13897
Autoloader.autoload
train
public function autoload($className) { if (0 === strpos($className, $this->prefix)) { $parts = explode('\\', substr($className, $this->prefixLength)); $filepath = $this->directory.DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $parts).'.php'; if (is_file($filepath)) { require $filepath; } } }
php
{ "resource": "" }
q13898
ReplicationStrategy.isReadOperation
train
public function isReadOperation(CommandInterface $command) { if (isset($this->disallowed[$id = $command->getId()])) { throw new NotSupportedException( "The command '$id' is not allowed in replication mode." ); } if (isset($this->readonly[$id])) { if (true === $readonly = $this->readonly[$id]) { return true; } return call_user_func($readonly, $command); } if (($eval = $id === 'EVAL') || $id === 'EVALSHA') { $sha1 = $eval ? sha1($command->getArgument(0)) : $command->getArgument(0); if (isset($this->readonlySHA1[$sha1])) { if (true === $readonly = $this->readonlySHA1[$sha1]) { return true; } return call_user_func($readonly, $command); } } return false; }
php
{ "resource": "" }
q13899
ReplicationStrategy.isSortReadOnly
train
protected function isSortReadOnly(CommandInterface $command) { $arguments = $command->getArguments(); $argc = count($arguments); if ($argc > 1) { for ($i = 1; $i < $argc; ++$i) { $argument = strtoupper($arguments[$i]); if ($argument === 'STORE') { return false; } } } return true; }
php
{ "resource": "" }