Another fix for dates when using addMonth()
This commit is contained in:
parent
45c93283fb
commit
b01976a6ae
@ -172,7 +172,7 @@ class Adsl extends ServiceType implements ServiceItem,ServiceUsage
|
|||||||
->where('date','>=',$start->format('Y-m-d'))
|
->where('date','>=',$start->format('Y-m-d'))
|
||||||
->where('date','<=',$maxdate->date->format('Y-m-d'))
|
->where('date','<=',$maxdate->date->format('Y-m-d'))
|
||||||
->get()->groupBy(function($item) {
|
->get()->groupBy(function($item) {
|
||||||
return sprintf('%s-%s',$item->trafficMonthStart->format('M-d'),$item->trafficMonthEnd->format('M-d'));
|
return sprintf('%s->%s',$item->trafficMonthStart->format('d M'),$item->trafficMonthEnd->format('d M'));
|
||||||
}) as $key => $o) {
|
}) as $key => $o) {
|
||||||
$result->put($key,$o->sum('total'));
|
$result->put($key,$o->sum('total'));
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ class AdslTraffic extends Model
|
|||||||
public function getTrafficMonthEndAttribute() {
|
public function getTrafficMonthEndAttribute() {
|
||||||
if ($this->date->day > $this->traffic_end) {
|
if ($this->date->day > $this->traffic_end) {
|
||||||
// If we are the last day of the month, we'll temporarily take 3 days since Jan 31 and addMonth() results in March.
|
// If we are the last day of the month, we'll temporarily take 3 days since Jan 31 and addMonth() results in March.
|
||||||
if ($this->date->isLastOfMonth())
|
if ($this->date->addMonth()->day != $this->date->day)
|
||||||
$this->date=$this->date->subDays(3);
|
$this->date=$this->date->subDays(3);
|
||||||
|
|
||||||
return Carbon::createFromFormat('Y-m-d',$this->date->addMonth()->format('Y-m-').$this->traffic_end);
|
return Carbon::createFromFormat('Y-m-d',$this->date->addMonth()->format('Y-m-').$this->traffic_end);
|
||||||
|
Loading…
Reference in New Issue
Block a user