Skip to content

Commit

Permalink
Refactor some date functions
Browse files Browse the repository at this point in the history
  • Loading branch information
repat committed Mar 24, 2019
1 parent e335907 commit c7da6fa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ str_icontains('foobar', 'test');
* MIT, see [LICENSE](https://github.com/repat/laravel-helper/blob/master/LICENSE)

## Version
* Version 0.1.12.1
* Version 0.1.13

## Contact
#### repat
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"keywords": ["laravel", "helper", "files", "array", "database", "strings", "date"],
"homepage": "http://repat.de",
"license": "MIT",
"version" : "0.1.12.1",
"version" : "0.1.13",
"authors": [
{"name": "repat", "email": "repat@repat.de"}
],
"require": {
"php": ">=7.0",
"php": ">=7.2",
"illuminate/support": "5.*",
"illuminate/database": "5.*",
"nesbot/carbon": "^1.26.3 || ^2.0",
Expand Down
18 changes: 16 additions & 2 deletions src/date_helpers.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
<?php

if (!function_exists('days_in_month')) {
/**
* How many days are in given month, defaults to current
*
* @return int
*/
function days_in_month(?int $month = null, ?int $year = null) : int
{
$month = $month ?? now()->month;
$year = $year ?? now()->year;
return cal_days_in_month(CAL_GREGORIAN, $month, $year);
}
}

if (!function_exists('days_this_month')) {
/**
* How many days are in current month (28/29/30/31)
Expand All @@ -8,7 +22,7 @@
*/
function days_this_month() : int
{
return cal_days_in_month(CAL_GREGORIAN, now()->month, now()->year);
return days_in_month(now()->month, now()->year);
}
}

Expand All @@ -20,7 +34,7 @@ function days_this_month() : int
*/
function days_next_month() : int
{
return cal_days_in_month(CAL_GREGORIAN, now()->addMonth()->month, now()->year);
return days_in_month(now()->addMonth()->month, now()->addMonth()->year);
}
}

Expand Down

0 comments on commit c7da6fa

Please sign in to comment.