Skip to content

Commit

Permalink
Merge pull request #1412 from briannesbitt/master
Browse files Browse the repository at this point in the history
Update version-1.next with master changes
  • Loading branch information
kylekatarnls authored Aug 7, 2018
2 parents 296d63c + 972c7a4 commit be1d6cf
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 54 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ cache:
directories:
- $HOME/.composer/cache

addons:
apt:
packages:
- language-pack-fr

env:
global:
- setup=basic
Expand All @@ -14,7 +19,6 @@ env:
sudo: false

before_install:
- sudo apt-get update && sudo apt-get --reinstall install -qq language-pack-fr
- if [[ $coverage = 'false' ]]; then phpenv config-rm xdebug.ini; fi

install:
Expand Down
59 changes: 44 additions & 15 deletions src/Carbon/Carbon.php
Original file line number Diff line number Diff line change
Expand Up @@ -1015,17 +1015,24 @@ public function nowWithSameTz()
}

/**
* Throws an exception if the given object is not a DateTime and does not implement DateTimeInterface.
* Throws an exception if the given object is not a DateTime and does not implement DateTimeInterface
* and not in $other.
*
* @param mixed $date
* @param mixed $date
* @param string|array $other
*
* @throws \InvalidArgumentException
*/
protected static function expectDateTime($date)
protected static function expectDateTime($date, $other = array())
{
$message = 'Expected ';
foreach ((array) $other as $expect) {
$message .= "{$expect}, ";
}

if (!$date instanceof DateTime && !$date instanceof DateTimeInterface) {
throw new InvalidArgumentException(
'Expected null, string, DateTime or DateTimeInterface, '.
$message.'DateTime or DateTimeInterface, '.
(is_object($date) ? get_class($date) : gettype($date)).' given'
);
}
Expand All @@ -1049,7 +1056,7 @@ protected function resolveCarbon($date = null)
return static::parse($date, $this->getTimezone());
}

static::expectDateTime($date);
static::expectDateTime($date, array('null', 'string'));

return $date instanceof self ? $date : static::instance($date);
}
Expand Down Expand Up @@ -1847,7 +1854,7 @@ public static function resetToStringFormat()
/**
* Set the default format used when type juggling a Carbon instance to a string
*
* @param string $format
* @param string|Closure $format
*
* @return void
*/
Expand All @@ -1863,7 +1870,9 @@ public static function setToStringFormat($format)
*/
public function __toString()
{
return $this->format(static::$toStringFormat);
$format = static::$toStringFormat;

return $this->format($format instanceof Closure ? $format($this) : $format);
}

/**
Expand Down Expand Up @@ -2284,7 +2293,7 @@ public function farthest($date1, $date2)
/**
* Get the minimum instance between a given instance (default now) and the current instance.
*
* @param \Carbon\Carbon|\DateTimeInterface|mixed $date
* @param \Carbon\Carbon|\DateTimeInterface|string|null $date
*
* @return static
*/
Expand Down Expand Up @@ -2312,7 +2321,7 @@ public function minimum($date = null)
/**
* Get the maximum instance between a given instance (default now) and the current instance.
*
* @param \Carbon\Carbon|\DateTimeInterface|mixed $date
* @param \Carbon\Carbon|\DateTimeInterface|string|null $date
*
* @return static
*/
Expand Down Expand Up @@ -2523,7 +2532,7 @@ public function isSameAs($format, $date = null)
{
$date = $date ?: static::now($this->tz);

static::expectDateTime($date);
static::expectDateTime($date, 'null');

return $this->format($format) === $date->format($format);
}
Expand Down Expand Up @@ -2572,7 +2581,7 @@ public function isSameQuarter($date = null, $ofSameYear = null)
{
$date = $date ? static::instance($date) : static::now($this->tz);

static::expectDateTime($date);
static::expectDateTime($date, 'null');

$ofSameYear = is_null($ofSameYear) ? static::shouldCompareYearWithMonth() : $ofSameYear;

Expand Down Expand Up @@ -4164,7 +4173,7 @@ public function startOfDay()
*/
public function endOfDay()
{
return $this->modify('23.59.59.999999');
return $this->modify('23:59:59.999999');
}

/**
Expand Down Expand Up @@ -4322,7 +4331,7 @@ public function startOfHour()
*/
public function endOfHour()
{
return $this->setTime($this->hour, 59, 59);
return $this->modify("$this->hour:59:59.999999");
}

/**
Expand All @@ -4342,7 +4351,27 @@ public function startOfMinute()
*/
public function endOfMinute()
{
return $this->setTime($this->hour, $this->minute, 59);
return $this->modify("$this->hour:$this->minute:59.999999");
}

/**
* Modify to start of current minute, seconds become 0
*
* @return static
*/
public function startOfSecond()
{
return $this->modify("$this->hour:$this->minute:$this->second.0");
}

/**
* Modify to end of current minute, seconds become 59
*
* @return static
*/
public function endOfSecond()
{
return $this->modify("$this->hour:$this->minute:$this->second.999999");
}

/**
Expand Down Expand Up @@ -4616,7 +4645,7 @@ public function nthOfYear($nth, $dayOfWeek)
/**
* Modify the current instance to the average of a given instance (default now) and the current instance.
*
* @param \Carbon\Carbon|\DateTimeInterface|null $date
* @param \Carbon\Carbon|\DateTimeInterface|string|null $date
*
* @return static
*/
Expand Down
9 changes: 9 additions & 0 deletions src/Carbon/Lang/az.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,13 @@
'from_now' => ':time sonra',
'after' => ':time sonra',
'before' => ':time əvvəl',
'diff_now' => 'indi',
'diff_yesterday' => 'dünən',
'diff_tomorrow' => 'sabah',
'diff_before_yesterday' => 'srağagün',
'diff_after_tomorrow' => 'birisi gün',
'period_recurrences' => ':count dəfədən bir',
'period_interval' => 'hər :interval',
'period_start_date' => ':date tarixindən başlayaraq',
'period_end_date' => ':date tarixinədək',
);
2 changes: 1 addition & 1 deletion src/Carbon/Lang/ca.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
'second' => ':count segon|:count segons',
's' => ':count segon|:count segons',
'ago' => 'fa :time',
'from_now' => 'dins de :time',
'from_now' => 'd\'aquí :time',
'after' => ':time després',
'before' => ':time abans',
'diff_now' => 'ara mateix',
Expand Down
2 changes: 1 addition & 1 deletion src/Carbon/Lang/es.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
'diff_now' => 'ahora mismo',
'diff_yesterday' => 'ayer',
'diff_tomorrow' => 'mañana',
'diff_before_yesterday' => 'anteayer',
'diff_before_yesterday' => 'antier',
'diff_after_tomorrow' => 'pasado mañana',
);
4 changes: 4 additions & 0 deletions src/Carbon/Lang/sh.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* file that was distributed with this source code.
*/

\Symfony\Component\Translation\PluralizationRules::set(function ($number) {
return ((1 == $number % 10) && (11 != $number % 100)) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2);
}, 'sh');

return array(
'year' => ':count godina|:count godine|:count godina',
'y' => ':count godina|:count godine|:count godina',
Expand Down
2 changes: 1 addition & 1 deletion tests/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function assertCarbon(Carbon $d, $year, $month, $day, $hour = null, $minu
$actual['seconds'] = $second;
}

if ($micro !== null) {
if (version_compare(PHP_VERSION, '7.1.0-dev', '>=') && $micro !== null) {
$expected['micro'] = $d->micro;
$actual['micro'] = $micro;
}
Expand Down
Loading

0 comments on commit be1d6cf

Please sign in to comment.