Skip to content

Commit

Permalink
Merging diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmurray committed Nov 8, 2020
2 parents a2c096d + 0499908 commit 8401f92
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 90 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ I needed to get the diffrence of time, and while the [very good Carbon](https://

You can install this package via composer:

``` bash
```bash
$ composer require jpmurray/laravel-countdown
```

Unless you are using Laravel 5.5 (in which case, package auto-discovery will do it's magic), you will have to add the service provider and facade to your `config/app.php` file.
## Usage with Laravel <= 5.5

You should be using versions of this package that are <= 3.0.0.

If you are using a version of Laravel that doesn't support package autodiscovery, you will have to add the service provider and facade to your `config/app.php` file.

Edit file: `config/app.php`

```php
'providers' => [
// ...
Expand All @@ -36,7 +41,7 @@ Edit file: `config/app.php`

## Usage

``` php
```php

use jpmurray\LaravelCountdown\Countdown;

Expand All @@ -63,7 +68,7 @@ $countdown->seconds; // 23
$countdown = Countdown::from($now)
->to($now->copy()->addYears(5))
->get();

// To return to humans string
$countdown->toHuman(); // 18 years, 33 weeks, 2 days, 18 hours, 4 minutes and 35 seconds

Expand All @@ -85,7 +90,9 @@ class User extends Authenticatable
//...
}
```

#### Example to use Trait:

```php
// This enables the following:
// You should have casted your attributes to dates beforehand
Expand All @@ -102,7 +109,7 @@ composer run test

## Change log

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
Please see [CHANGELOG](changelog.MD) for more information on what has changed recently.

## Credits

Expand Down
14 changes: 14 additions & 0 deletions changelog.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,30 @@ All Notable changes to `laravel-countdown` will be documented in this file.

Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.

## 3.0.0

- Dropping support for Laravel <= 5. Those users should be using earlier versions of the package.

## 2.0.0 - 2020-04-07

- Updated dependencies to work for more recent version of Laravel.
- Updated Carbon dependency to `^2.0`.

## 1.3.0 - 2018-06-29

- Should insure compatibility with Laravel up to 5.6.

## 1.2.0 - 2017-08-02

### Added

- Added a `toHuman` method to return a string that is human readable (@juniorb2ss)
- The `toHuman` method accepts a custom string to parse so the returned readable string can be customized / localized (@juniorb2ss)

## 1.1.0 -2017-08-01

### Added

- Tests! Thank you [Junior](https://github.com/juniorb2ss)!

## 1.0.1 - 2017-07-31
Expand All @@ -31,9 +39,15 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
First release!

## Please ignore below this line!

## Unreleased - YYYY-MM-DD

### Added

### Deprecated

### Fixed

### Removed

### Security
122 changes: 61 additions & 61 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
{
"name": "jpmurray/laravel-countdown",
"type": "library",
"description": "Provide an easy class easy way to get the time difference between two dates, with an extra bonus trait for eloquent",
"keywords": [
"jpmurray",
"countdown",
"time",
"dates",
"elapsed",
"until"
],
"homepage": "https://github.com/jpmurray/laravel-countdown",
"license": "MIT",
"authors": [
{
"name": "Jean-Philippe Murray",
"email": "[email protected]",
"homepage": "https://github.com/jpmurray/",
"role": "Developer"
}
],
"require": {
"php": "^7.0",
"ext-bcmath": "*",
"nesbot/carbon": "^2.0",
"illuminate/support": "5.* || 6.* || 7.*"
},
"require-dev": {
"orchestra/testbench": "~3.0",
"phpunit/phpunit" : "~4.0||~5.0",
"squizlabs/php_codesniffer": "^2.3",
"nesbot/carbon": "^2.0",
"mockery/mockery": "dev-master@dev"
},
"autoload": {
"psr-4": {
"jpmurray\\LaravelCountdown\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"extra": {
"laravel": {
"providers": [
"jpmurray\\LaravelCountdown\\CountdownServiceProvider"
],
"aliases": {
"Countdown": "jpmurray\\LaravelCountdown\\Facades\\CountdownFacade"
}
}
},
"scripts": {
"test": "phpunit",
"coverage": "phpunit --coverage-text --coverage-clover=coverage.clover",
"check-style": "phpcs -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests",
"fix-style": "phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests",
"build": "composer run test && composer run check-style && composer run fix-style && composer run coverage"
"name": "jpmurray/laravel-countdown",
"type": "library",
"description": "Provide an easy class easy way to get the time difference between two dates, with an extra bonus trait for eloquent",
"keywords": [
"jpmurray",
"countdown",
"time",
"dates",
"elapsed",
"until"
],
"homepage": "https://github.com/jpmurray/laravel-countdown",
"license": "MIT",
"authors": [
{
"name": "Jean-Philippe Murray",
"email": "[email protected]",
"homepage": "https://github.com/jpmurray/",
"role": "Developer"
}
],
"require": {
"php": "^7.0",
"ext-bcmath": "*",
"nesbot/carbon": "^2.0",
"illuminate/support": "6.* || 7.* || 8.*"
},
"require-dev": {
"orchestra/testbench": "~3.0",
"phpunit/phpunit": "~4.0||~5.0",
"squizlabs/php_codesniffer": "^2.3",
"nesbot/carbon": "^2.0",
"mockery/mockery": "dev-master@dev"
},
"autoload": {
"psr-4": {
"jpmurray\\LaravelCountdown\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"extra": {
"laravel": {
"providers": [
"jpmurray\\LaravelCountdown\\CountdownServiceProvider"
],
"aliases": {
"Countdown": "jpmurray\\LaravelCountdown\\Facades\\CountdownFacade"
}
}
},
"scripts": {
"test": "phpunit",
"coverage": "phpunit --coverage-text --coverage-clover=coverage.clover",
"check-style": "phpcs -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests",
"fix-style": "phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests",
"build": "composer run test && composer run check-style && composer run fix-style && composer run coverage"
}
}
38 changes: 18 additions & 20 deletions src/Countdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use Exception;
use Carbon\Carbon;
use DateTimeInterface;
use Illuminate\Foundation\Application;
use jpmurray\LaravelCountdown\Exceptions\InvalidArgumentToCountdown;
use jpmurray\LaravelCountdown\Exceptions\InvalidDateFormatToCountdown;
use jpmurray\LaravelCountdown\Exceptions\InvalidPropertyStringForHumanException;

Expand All @@ -22,7 +20,7 @@ class Countdown
const SECONDS_PER_WEEK = 604800;
const SECONDS_PER_YEAR = 31449600;
const STRING_FOR_HUMAN = '{hours} years, {weeks} weeks, {days} days,'
. ' {hours} hours, {minutes} minutes and {seconds} seconds';
. ' {hours} hours, {minutes} minutes and {seconds} seconds';

private $from = null;
private $to = null;
Expand Down Expand Up @@ -51,7 +49,7 @@ public function __construct(string $timezone, Carbon $carbon)
*
* @return self
*/
public function from($time) : self
public function from($time): self
{
$this->from = $this->asDateTime($time);

Expand All @@ -65,7 +63,7 @@ public function from($time) : self
*
* @return self
*/
public function to($time = null) : self
public function to($time = null): self
{
$time ?: $this->carbon;

Expand All @@ -90,13 +88,13 @@ public function get()
}

$this->delta = $this->from->diffInSeconds($this->to);

$this->computeYears()
->computeWeeks()
->computeDays()
->computeHours()
->computeMinutes()
->computeSeconds();
->computeWeeks()
->computeDays()
->computeHours()
->computeMinutes()
->computeSeconds();

return $this;
}
Expand Down Expand Up @@ -151,7 +149,7 @@ protected function asDateTime($value)
*
* @return bool
*/
protected function isStandardDateFormat(string $value) : int
protected function isStandardDateFormat(string $value): int
{
return preg_match('/^(\d{4})-(\d{1,2})-(\d{1,2})$/', $value);
}
Expand All @@ -161,7 +159,7 @@ protected function isStandardDateFormat(string $value) : int
*
* @return self
*/
private function computeSeconds() : self
private function computeSeconds(): self
{
$this->seconds = intval(bcmod(intval($this->delta), self::SECONDS_PER_MINUTE));

Expand All @@ -173,7 +171,7 @@ private function computeSeconds() : self
*
* @return self
*/
private function computeMinutes() : self
private function computeMinutes(): self
{
$this->minutes = intval(bcmod((intval($this->delta) / self::SECONDS_PER_MINUTE), self::MINUTES_PER_HOUR));

Expand All @@ -185,7 +183,7 @@ private function computeMinutes() : self
*
* @return self
*/
private function computeHours() : self
private function computeHours(): self
{
$this->hours = intval(bcmod((intval($this->delta) / self::SECONDS_PER_HOUR), self::HOURS_PER_DAY));

Expand All @@ -197,7 +195,7 @@ private function computeHours() : self
*
* @return self
*/
private function computeDays() : self
private function computeDays(): self
{
$this->days = intval(bcmod((intval($this->delta) / self::SECONDS_PER_DAY), self::DAYS_PER_WEEK));

Expand All @@ -209,7 +207,7 @@ private function computeDays() : self
*
* @return self
*/
private function computeWeeks() : self
private function computeWeeks(): self
{
$this->weeks = intval(bcmod((intval($this->delta) / self::SECONDS_PER_WEEK), self::WEEKS_PER_YEAR));

Expand All @@ -221,7 +219,7 @@ private function computeWeeks() : self
*
* @return self
*/
private function computeYears() : self
private function computeYears(): self
{
$this->years = intval(intval($this->delta) / self::SECONDS_PER_YEAR);

Expand All @@ -235,7 +233,7 @@ private function computeYears() : self
* @throws \jpmurray\LaravelCountdown\Exceptions\InvalidPropertyStringForHumanException
* @return string
*/
private function getStringForHumanRead(string $string) : string
private function getStringForHumanRead(string $string): string
{
// search regex
preg_match_all(
Expand Down Expand Up @@ -267,7 +265,7 @@ private function getStringForHumanRead(string $string) : string
* @param string $custom Custom string to parse
* @return string
*/
public function toHuman(string $custom = null) : string
public function toHuman(string $custom = null): string
{
$sentence = ($custom ?: static::STRING_FOR_HUMAN);

Expand Down
6 changes: 2 additions & 4 deletions src/Traits/CalculateTimeDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace jpmurray\LaravelCountdown\Traits;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use jpmurray\LaravelCountdown\Countdown;

trait CalculateTimeDiff
{
Expand All @@ -21,7 +19,7 @@ public function elapsed($attribute)
$now = Carbon::now();

return $countdown->from($attribute)
->to($now)->get();
->to($now)->get();
}

/**
Expand All @@ -37,6 +35,6 @@ public function until($attribute)
$now = Carbon::now();

return $countdown->from($now)
->to($attribute)->get();
->to($attribute)->get();
}
}

0 comments on commit 8401f92

Please sign in to comment.