Add a Carbon helper function

This commit is contained in:
Jonny Barnes 2017-09-13 16:13:58 +01:00
parent 4057abb7e7
commit 27904658c6
3 changed files with 9 additions and 4 deletions

View file

@ -37,7 +37,7 @@ class NoteService
); );
if (array_key_exists('published', $data) && empty($data['published']) === false) { 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(); $note->created_at = $note->updated_at = $carbon->toDateTimeString();
} }

View file

@ -5,7 +5,6 @@ namespace App;
use Cache; use Cache;
use Twitter; use Twitter;
use HTMLPurifier; use HTMLPurifier;
use Carbon\Carbon;
use HTMLPurifier_Config; use HTMLPurifier_Config;
use Illuminate\Filesystem\Filesystem; use Illuminate\Filesystem\Filesystem;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
@ -63,10 +62,9 @@ class WebMention extends Model
public function getPublishedAttribute() public function getPublishedAttribute()
{ {
$microformats = json_decode($this->mf2, true); $microformats = json_decode($this->mf2, true);
$carbon = new Carbon();
if (isset($microformats['items'][0]['properties']['published'][0])) { if (isset($microformats['items'][0]['properties']['published'][0])) {
try { try {
$published = $carbon->parse( $published = carbon()->parse(
$microformats['items'][0]['properties']['published'][0] $microformats['items'][0]['properties']['published'][0]
)->toDayDateTimeString(); )->toDayDateTimeString();
} catch (\Exception $exception) { } catch (\Exception $exception) {

View file

@ -204,3 +204,10 @@ if (! function_exists('prettyPrintJson')) {
return str_replace("\t", ' ', $result); 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);
}
}