Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Localize getMonthAndYear
  • Loading branch information
asbiin committed Mar 26, 2018
commit 82019fe01c225e6e0c52f9be62b826fb7dd7e406
22 changes: 15 additions & 7 deletions app/Helpers/DateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,20 @@ public static function addTimeAccordingToFrequencyType(Carbon $date, $frequency,
* @param int $month
* @return string
*/
public static function getMonthAndYear(int $month)
public static function getMonthAndYear(int $month, $locale = null)
{
$month = Carbon::now()->addMonthsNoOverflow($month)->format('M');
$year = Carbon::now()->addMonthsNoOverflow($month)->format('Y');
$date = Date::now()->addMonthsNoOverflow($month);
$locale = self::getLocale($locale);

switch ($locale) {
case 'en':
$format = 'M Y';
break;
default:
$format = 'M Y';
}

return $month.' '.$year;
return $date->format($format);
}

/**
Expand All @@ -202,10 +210,10 @@ public static function getMonthAndYear(int $month)
public static function getNextTheoriticalBillingDate(String $interval)
{
if ($interval == 'monthly') {
return Carbon::now()->addMonth();
return Date::now()->addMonth();
}

return Carbon::now()->addYear();
return Date::now()->addYear();
}

/**
Expand All @@ -215,7 +223,7 @@ public static function getNextTheoriticalBillingDate(String $interval)
*/
public static function getListOfMonths()
{
Date::setLocale(auth()->user()->locale);
self::getLocale();
$months = collect([]);
$currentDate = Date::now();
$currentDate->day = 1;
Expand Down