Skip to content

Commit

Permalink
Fix briannesbitt#1967 handle global translator to pick the start of week
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed May 19, 2020
1 parent 72488c2 commit c4474e8
Show file tree
Hide file tree
Showing 20 changed files with 243 additions and 417 deletions.
102 changes: 39 additions & 63 deletions src/Carbon/CarbonInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ interface CarbonInterface extends DateTimeInterface, JsonSerializable
* @param string $method magic method name called
* @param array $parameters parameters list
*
* @throws \BadMethodCallException|\ReflectionException
* @throws UnknownMethodException|BadMethodCallException|ReflectionException|Throwable
*
* @return mixed
*/
Expand All @@ -628,7 +628,7 @@ public function __call($method, $parameters);
* @param string $method magic method name called
* @param array $parameters parameters list
*
* @throws \BadMethodCallException
* @throws BadMethodCallException
*
* @return mixed
*/
Expand All @@ -647,6 +647,8 @@ public function __clone();
*
* @param string|null $time
* @param DateTimeZone|string|null $tz
*
* @throws InvalidFormatException
*/
public function __construct($time = null, $tz = null);

Expand All @@ -662,7 +664,7 @@ public function __debugInfo();
*
* @param string $name
*
* @throws InvalidArgumentException|ReflectionException
* @throws UnknownGetterException
*
* @return string|int|bool|DateTimeZone|null
*/
Expand All @@ -683,7 +685,7 @@ public function __isset($name);
* @param string $name
* @param string|int|DateTimeZone $value
*
* @throws InvalidArgumentException|ReflectionException
* @throws UnknownSetterException|ReflectionException
*
* @return void
*/
Expand Down Expand Up @@ -876,7 +878,7 @@ public function calendar($referenceTime = null, array $formats = []);
* Return the Carbon instance passed through, a now instance in the same timezone
* if null given or parse the input if string given.
*
* @param \Carbon\Carbon|\Carbon\CarbonPeriod|\Carbon\CarbonInterval|\DateInterval|\DatePeriod|\DateTimeInterface|string|null $date
* @param Carbon|\Carbon\CarbonPeriod|\Carbon\CarbonInterval|\DateInterval|\DatePeriod|DateTimeInterface|string|null $date
*
* @return static
*/
Expand Down Expand Up @@ -990,7 +992,7 @@ public function copy();
* @param int|null $second
* @param DateTimeZone|string|null $tz
*
* @throws Exception|InvalidArgumentException
* @throws InvalidFormatException
*
* @return static
*/
Expand All @@ -1004,7 +1006,7 @@ public static function create($year = 0, $month = 1, $day = 1, $hour = 0, $minut
* @param int|null $day
* @param DateTimeZone|string|null $tz
*
* @throws Exception|InvalidArgumentException
* @throws InvalidFormatException
*
* @return static
*/
Expand All @@ -1017,7 +1019,7 @@ public static function createFromDate($year = null, $month = null, $day = null,
* @param string $time
* @param DateTimeZone|string|false|null $tz
*
* @throws InvalidArgumentException
* @throws InvalidFormatException
*
* @return static|false
*/
Expand All @@ -1032,11 +1034,11 @@ public static function createFromFormat($format, $time, $tz = null);
* @param string|null $locale locale to be used for LTS, LT, LL, LLL, etc. macro-formats (en by fault, unneeded if no such macro-format in use)
* @param TranslatorInterface $translator optional custom translator to use for macro-formats
*
* @throws InvalidArgumentException
* @throws InvalidFormatException
*
* @return static|false
*/
public static function createFromIsoFormat($format, $time, $tz = null, $locale = self::DEFAULT_LOCALE, $translator = null);
public static function createFromIsoFormat($format, $time, $tz = null, $locale = 'en', $translator = null);

/**
* Create a Carbon instance from a specific format and a string in a given language.
Expand All @@ -1046,7 +1048,7 @@ public static function createFromIsoFormat($format, $time, $tz = null, $locale =
* @param string $time
* @param DateTimeZone|string|false|null $tz
*
* @throws InvalidArgumentException
* @throws InvalidFormatException
*
* @return static|false
*/
Expand All @@ -1060,7 +1062,7 @@ public static function createFromLocaleFormat($format, $locale, $time, $tz = nul
* @param string $time
* @param DateTimeZone|string|false|null $tz
*
* @throws InvalidArgumentException
* @throws InvalidFormatException
*
* @return static|false
*/
Expand All @@ -1074,7 +1076,7 @@ public static function createFromLocaleIsoFormat($format, $locale, $time, $tz =
* @param int|null $second
* @param DateTimeZone|string|null $tz
*
* @throws Exception|InvalidArgumentException
* @throws InvalidFormatException
*
* @return static
*/
Expand All @@ -1086,7 +1088,7 @@ public static function createFromTime($hour = 0, $minute = 0, $second = 0, $tz =
* @param string $time
* @param DateTimeZone|string|null $tz
*
* @throws InvalidArgumentException
* @throws InvalidFormatException
*
* @return static
*/
Expand Down Expand Up @@ -1129,7 +1131,7 @@ public static function createFromTimestampUTC($timestamp);
* @param int|null $day
* @param DateTimeZone|string|null $tz
*
* @throws Exception
* @throws InvalidFormatException
*
* @return static
*/
Expand All @@ -1147,7 +1149,7 @@ public static function createMidnightDate($year = null, $month = null, $day = nu
* If $hour is not null then the default values for $minute and $second
* will be 0.
*
* If one of the set values is not valid, an \InvalidArgumentException
* If one of the set values is not valid, an InvalidDateException
* will be thrown.
*
* @param int|null $year
Expand All @@ -1158,7 +1160,7 @@ public static function createMidnightDate($year = null, $month = null, $day = nu
* @param int|null $second
* @param DateTimeZone|string|null $tz
*
* @throws Exception
* @throws InvalidDateException
*
* @return static|false
*/
Expand Down Expand Up @@ -1924,7 +1926,7 @@ public function fromNow($syntax = null, $short = false, $parts = 1, $options = n
*
* @param string $value
*
* @throws \InvalidArgumentException
* @throws InvalidFormatException
*
* @return static
*/
Expand All @@ -1945,7 +1947,7 @@ public static function genericMacro($macro, $priority = 0);
*
* @param string $name
*
* @throws InvalidArgumentException|ReflectionException
* @throws UnknownGetterException
*
* @return string|int|bool|DateTimeZone|null
*/
Expand Down Expand Up @@ -2224,18 +2226,20 @@ public static function getTranslationMessageWith($translator, string $key, strin
public static function getTranslator();

/**
* Get the last day of week
* Get the last day of week.
*
* @param string $locale local to consider the last day of week.
*
* @return int
*/
public static function getWeekEndsAt();
public static function getWeekEndsAt(string $locale = null): int;

/**
* Get the first day of week
* Get the first day of week.
*
* @return int
*/
public static function getWeekStartsAt();
public static function getWeekStartsAt(string $locale = null): int;

/**
* Get weekend days
Expand Down Expand Up @@ -3076,7 +3080,7 @@ public static function macro($name, $macro);
*
* @param mixed $var
*
* @throws Exception
* @throws InvalidFormatException
*
* @return static|null
*/
Expand Down Expand Up @@ -3327,7 +3331,7 @@ public function ordinal(string $key, string $period = null): string;
* @param string|null $time
* @param DateTimeZone|string|null $tz
*
* @throws Exception
* @throws InvalidFormatException
*
* @return static
*/
Expand All @@ -3340,7 +3344,7 @@ public static function parse($time = null, $tz = null);
* @param string $locale
* @param DateTimeZone|string|null $tz
*
* @throws Exception
* @throws InvalidFormatException
*
* @return static
*/
Expand Down Expand Up @@ -3399,7 +3403,7 @@ public function range($end = null, $interval = null, $unit = null);
* @param string $time
* @param DateTimeZone|string|false|null $tz
*
* @throws InvalidArgumentException
* @throws InvalidFormatException
*
* @return static|false
*/
Expand All @@ -3424,7 +3428,7 @@ public function rawFormat($format);
* @param string|null $time
* @param DateTimeZone|string|null $tz
*
* @throws Exception
* @throws InvalidFormatException
*
* @return static
*/
Expand Down Expand Up @@ -3537,7 +3541,7 @@ public static function serializeUsing($callback);
* @param string|array $name
* @param string|int|DateTimeZone $value
*
* @throws InvalidArgumentException|ReflectionException
* @throws ImmutableException|UnknownSetterException
*
* @return $this
*/
Expand All @@ -3559,7 +3563,7 @@ public function setDate($year, $month, $day);
/**
* Set the year, month, and date for this instance to that of the passed instance.
*
* @param \Carbon\Carbon|\DateTimeInterface $date now if null
* @param Carbon|DateTimeInterface $date now if null
*
* @return static
*/
Expand All @@ -3583,7 +3587,7 @@ public function setDateTime($year, $month, $day, $hour, $minute, $second = 0, $m
/**
* Set the date and time for this instance to that of the passed instance.
*
* @param \Carbon\Carbon|\DateTimeInterface $date
* @param Carbon|DateTimeInterface $date
*
* @return static
*/
Expand Down Expand Up @@ -3693,7 +3697,7 @@ public function setTime($hour, $minute, $second = 0, $microseconds = 0);
/**
* Set the hour, minute, second and microseconds for this instance to that of the passed instance.
*
* @param \Carbon\Carbon|\DateTimeInterface $date now if null
* @param Carbon|DateTimeInterface $date now if null
*
* @return static
*/
Expand Down Expand Up @@ -3782,34 +3786,6 @@ public function setUnitNoOverflow($valueUnit, $value, $overflowUnit);
*/
public static function setUtf8($utf8);

/**
* @deprecated To avoid conflict between different third-party libraries, static setters should not be used.
* Use $weekStartsAt optional parameter instead when using startOfWeek, floorWeek, ceilWeek
* or roundWeek method. You can also use the 'first_day_of_week' locale setting to change the
* start of week according to current locale selected and implicitly the end of week.
*
* Set the last day of week
*
* @param int $day
*
* @return void
*/
public static function setWeekEndsAt($day);

/**
* @deprecated To avoid conflict between different third-party libraries, static setters should not be used.
* Use $weekEndsAt optional parameter instead when using endOfWeek method. You can also use the
* 'first_day_of_week' locale setting to change the start of week according to current locale
* selected and implicitly the end of week.
*
* Set the first day of week
*
* @param int $day week start day
*
* @return void
*/
public static function setWeekStartsAt($day);

/**
* @deprecated To avoid conflict between different third-party libraries, static setters should not be used.
* You should rather consider week-end is always saturday and sunday, and if you have some custom
Expand Down Expand Up @@ -4604,7 +4580,7 @@ public static function tomorrow($tz = null);
*
* @return string
*/
public function translate(string $key, array $parameters = [], $number = null, \Symfony\Contracts\Translation\TranslatorInterface $translator = null, bool $altNumbers = false): string;
public function translate(string $key, array $parameters = [], $number = null, \Symfony\Contracts\Translation\TranslatorInterface $translator = null, bool $altNumbers = false);

/**
* Returns the alternative number for a given integer if available in the current locale.
Expand All @@ -4631,7 +4607,7 @@ public function translateNumber(int $number): string;
*
* @return string
*/
public static function translateTimeString($timeString, $from = null, $to = null, $mode = 15);
public static function translateTimeString(string $timeString, $from = null, $to = null, $mode = 15): string;

/**
* Translate a time string from the current locale (`$date->locale()`) to an other.
Expand All @@ -4653,7 +4629,7 @@ public function translateTimeStringTo($timeString, $to = null);
*
* @return string
*/
public static function translateWith(\Symfony\Contracts\Translation\TranslatorInterface $translator, string $key, array $parameters = [], $number = null): string;
public static function translateWith(\Symfony\Contracts\Translation\TranslatorInterface $translator, string $key, array $parameters = [], $number = null);

/**
* Format as ->format() do (using date replacements patterns from http://php.net/manual/fr/function.date.php)
Expand Down

0 comments on commit c4474e8

Please sign in to comment.