Skip to content

Commit

Permalink
Merge pull request laravel#299 from Francismori7/6.0
Browse files Browse the repository at this point in the history
Dates improved
  • Loading branch information
taylorotwell committed Jun 1, 2016
2 parents 9cf65cd + 07f8a57 commit 9047692
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
5 changes: 4 additions & 1 deletion resources/views/receipt.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@
@foreach ($invoice->subscriptions() as $subscription)
<tr>
<td>Subscription ({{ $subscription->quantity }})</td>
<td>{{ $subscription->startDate() }} - {{ $subscription->endDate() }}</td>
<td>
{{ $subscription->startDateAsCarbon()->formatLocalized('%B %e, %Y') }} -
{{ $subscription->endDateAsCarbon()->formatLocalized('%B %e, %Y') }}
</td>
<td>{{ $subscription->total() }}</td>
</tr>
@endforeach
Expand Down
2 changes: 1 addition & 1 deletion src/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct($user, StripeInvoice $invoice)
*/
public function date($timezone = null)
{
$carbon = Carbon::createFromTimestamp($this->invoice->date);
$carbon = Carbon::createFromTimestampUTC($this->invoice->date);

return $timezone ? $carbon->setTimezone($timezone) : $carbon;
}
Expand Down
30 changes: 28 additions & 2 deletions src/InvoiceItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Laravel\Cashier;

use Carbon\Carbon;

class InvoiceItem
{
/**
Expand Down Expand Up @@ -49,7 +51,7 @@ public function total()
public function startDate()
{
if ($this->isSubscription()) {
return date('M j, Y', $this->item->period->start);
return $this->startDateAsCarbon()->toFormattedDateString();
}
}

Expand All @@ -61,7 +63,31 @@ public function startDate()
public function endDate()
{
if ($this->isSubscription()) {
return date('M j, Y', $this->item->period->end);
return $this->endDateAsCarbon()->toFormattedDateString();
}
}

/**
* Get a Carbon instance for the start date.
*
* @return \Carbon\Carbon
*/
public function startDateAsCarbon()
{
if ($this->isSubscription()) {
return Carbon::createFromTimestampUTC($this->item->period->start);
}
}

/**
* Get a Carbon instance for the end date.
*
* @return \Carbon\Carbon
*/
public function endDateAsCarbon()
{
if ($this->isSubscription()) {
return Carbon::createFromTimestampUTC($this->item->period->end);
}
}

Expand Down

0 comments on commit 9047692

Please sign in to comment.