From 27904658c6b47c7578d581b292ea1d2a97fc9558 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Wed, 13 Sep 2017 16:13:58 +0100 Subject: [PATCH] Add a Carbon helper function --- app/Services/NoteService.php | 2 +- app/WebMention.php | 4 +--- helpers.php | 7 +++++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/Services/NoteService.php b/app/Services/NoteService.php index e2b91773..a858089f 100644 --- a/app/Services/NoteService.php +++ b/app/Services/NoteService.php @@ -37,7 +37,7 @@ class NoteService ); if (array_key_exists('published', $data) && empty($data['published']) === false) { - $carbon = new \Carbon\Carbon($data['published']); + $carbon = carbon($data['published']); $note->created_at = $note->updated_at = $carbon->toDateTimeString(); } diff --git a/app/WebMention.php b/app/WebMention.php index 3c1ee3a7..5e3d570f 100644 --- a/app/WebMention.php +++ b/app/WebMention.php @@ -5,7 +5,6 @@ namespace App; use Cache; use Twitter; use HTMLPurifier; -use Carbon\Carbon; use HTMLPurifier_Config; use Illuminate\Filesystem\Filesystem; use Illuminate\Database\Eloquent\Model; @@ -63,10 +62,9 @@ class WebMention extends Model public function getPublishedAttribute() { $microformats = json_decode($this->mf2, true); - $carbon = new Carbon(); if (isset($microformats['items'][0]['properties']['published'][0])) { try { - $published = $carbon->parse( + $published = carbon()->parse( $microformats['items'][0]['properties']['published'][0] )->toDayDateTimeString(); } catch (\Exception $exception) { diff --git a/helpers.php b/helpers.php index aeec0625..7e5a0852 100644 --- a/helpers.php +++ b/helpers.php @@ -204,3 +204,10 @@ if (! function_exists('prettyPrintJson')) { return str_replace("\t", ' ', $result); } } + +// sourced from https://twitter.com/jrubsc/status/907776591320764416/photo/1 +if (! function_exists('carbon')) { + function carbon(...$args) { + return new Carbon\Carbon(...$args); + } +}