Created
December 4, 2013 07:43
-
-
Save Meroje/7783731 to your computer and use it in GitHub Desktop.
TimeDiff For Humans
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Carbon\Carbon; | |
class Comment extends Eloquent { | |
protected $guarded = array(); | |
protected $softDelete = true; | |
public static $rules = array(); | |
public static function publish($token) | |
{ | |
$comment = self::withTrashed()->where('token', $token)->first(); | |
if($comment) | |
{ | |
$comment->restore(); | |
$comment->published_at = new Carbon(); | |
return $comment->save(); | |
} else { | |
return false; | |
} | |
} | |
public function scopePublished($query) | |
{ | |
return $query->whereNotNull('published_at'); | |
} | |
public function getDates() | |
{ | |
return array('created_at', 'updated_at', 'deleted_at', 'published_at'); | |
} | |
public function getPublishedAttribute() | |
{ | |
$txt = 'app.timediff.'; | |
$isNow = true; | |
$other = Carbon::now(); | |
$delta = abs($other->diffInSeconds($this->created_at)); | |
// 30 days per month, 365 days per year... good enough!! | |
$divs = array( | |
'second' => Carbon::SECONDS_PER_MINUTE, | |
'minute' => Carbon::MINUTES_PER_HOUR, | |
'hour' => Carbon::HOURS_PER_DAY, | |
'day' => 30, | |
'month' => Carbon::MONTHS_PER_YEAR | |
); | |
$unit = 'year'; | |
foreach ($divs as $divUnit => $divValue) { | |
if ($delta < $divValue) { | |
$unit = $divUnit; | |
break; | |
} | |
$delta = floor($delta / $divValue); | |
} | |
if ($delta == 0) { | |
$delta = 1; | |
} | |
$txt .= $unit; | |
return Lang::choice($txt, $delta, compact('delta')); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return array( | |
'timediff' => array( | |
'second' => 'Es gibt :delta Sekunde|Es gibt :delta Sekundes', | |
'minute' => 'Es gibt :delta Minute|Es gibt :delta Minutes', | |
'hour' => 'Vor :delta Stunde|Vor :delta Stundes', | |
'day' => '{1} Gestern|{2} Vorgestern|[3,Inf] Vor :delta Tagen', | |
'month' => '[1,Inf] Vor :delta Monat', | |
'year' => 'Vor :delta Jahr|Es geben :delta an Jahr', | |
), | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return array( | |
'timediff' => array( | |
'second' => ':delta second ago|:delta seconds ago', | |
'minute' => ':delta minute ago|:delta minutes ago', | |
'hour' => ':delta hour ago|:delta hours ago', | |
'day' => '{1} Yesterday|{2} Two days ago|[3,Inf] :delta days ago', | |
'month' => '{1} :delta month ago|[2,Inf] :delta month ago', | |
'year' => ':delta year ago|:delta years ago', | |
), | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return array( | |
'timediff' => array( | |
'second' => 'Il y a :delta seconde|Il y a :delta secondes', | |
'minute' => 'Il y a :delta minute|Il y a :delta minutes', | |
'hour' => 'Il y a :delta heure|Il y a :delta heures', | |
'day' => '{1} Hier|{2} Avant-hier|[3,Inf] Il y a :delta jours', | |
'month' => '[1,Inf] Il y a :delta mois', | |
'year' => 'Il y a :delta an|Il y a :delta ans', | |
), | |
); |
fi.php
'second' => ':delta sekunti sitten|:delta sekuntia sitten', 'minute' => ':delta minuutti sitten|:delta minuuttia sitten', 'hour' => ':delta tunti sitten|:delta tuntia sitten', 'day' => '{1} Eilen|{2} Toissa päivänä|[3,Inf] :delta päivää sitten', 'month' => '{1} Kuukausi sitten|[2,Inf] :delta kuukautta sitten', 'year' => 'Vuosi sitten|:delta vuotta sitten',
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
es.php