Skip to content

Commit

Permalink
Use Carbon in a mutator to convert time stamps to local Pacific.
Browse files Browse the repository at this point in the history
  • Loading branch information
colinschoen committed Aug 27, 2015
1 parent c3d584d commit 66e2f8c
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 3 deletions.
10 changes: 9 additions & 1 deletion app/Announcement.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

use Auth;
use Illuminate\Database\Eloquent\Model;

use Carbon\Carbon;
class Announcement extends Model {

protected $tabled = 'announcements';

public function getCreatedAtAttribute($value)
{
return Carbon::createFromTimestamp(strtotime($value))
->timezone('America/Los_Angeles')
->toDateTimeString()
;
}

public function user() {
return $this->hasOne('App\User', 'id', 'author');
}
Expand Down
8 changes: 8 additions & 0 deletions app/Audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

use Auth, Request;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;

class Audit extends Model {

protected $table = 'audits';

public function getCreatedAtAttribute($value)
{
return Carbon::createFromTimestamp(strtotime($value))
->timezone('America/Los_Angeles')
->toDateTimeString();
}

public static function log($action) {
$uid = Auth::user()->id;
$ip = Request::ip();
Expand Down
10 changes: 10 additions & 0 deletions app/Checkin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@

use Auth, Request;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;

class Checkin extends Model {

protected $table = "checkins";


public function getCreatedAtAttribute($value)
{
return Carbon::createFromTimestamp(strtotime($value))
->timezone('America/Los_Angeles')
->toDateTimeString()
;
}

public function ta() {
return $this->hasOne('App\User', 'id', 'gsi');
}
Expand Down
10 changes: 9 additions & 1 deletion app/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

use Auth, Request;
use Illuminate\Database\Eloquent\Model;
use App\User;
use Carbon\Carbon;

class Password extends Model {

protected $table = "passwords";

public function getCreatedAtAttribute($value)
{
return Carbon::createFromTimestamp(strtotime($value))
->timezone('America/Los_Angeles')
->toDateTimeString()
;
}

}
9 changes: 9 additions & 0 deletions app/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

use Auth, Request;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;

class Section extends Model {

protected $table = 'sections';

public function getCreatedAtAttribute($value)
{
return Carbon::createFromTimestamp(strtotime($value))
->timezone('America/Los_Angeles')
->toDateTimeString()
;
}

public static function daysToString($s) {
$dayString = "";
if ($s->mon == 1)
Expand Down
10 changes: 9 additions & 1 deletion app/Type.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
<?php namespace App;

use Illuminate\Database\Eloquent\Model;

use Carbon\Carbon;
class Type extends Model {

protected $table = "types";

public function getCreatedAtAttribute($value)
{
return Carbon::createFromTimestamp(strtotime($value))
->timezone('America/Los_Angeles')
->toDateTimeString()
;
}

}
8 changes: 8 additions & 0 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Carbon\Carbon;

class User extends Model implements AuthenticatableContract, CanResetPasswordContract {

use Authenticatable, CanResetPassword;

public function getCreatedAtAttribute($value)
{
return Carbon::createFromTimestamp(strtotime($value))
->timezone('America/Los_Angeles')
->toDateTimeString();
}

/**
* The database table used by the model.
*
Expand Down

0 comments on commit 66e2f8c

Please sign in to comment.