Skip to content

Carbon wrapper for extra functionality when dealing with timezones.

License

Notifications You must be signed in to change notification settings

RaphaelBronsveld-zz/timezones

Repository files navigation

Laravel logo Laravel Timezones

Build status GitHub Version Total Downloads License

Laravel package providing easy Timezone functionality.

Made for people who really just want to have an easy way of going about dealing with timezones.

Composer require
"raphaelb/timezones": "~1.4"
Laravel
Raphaelb\Timezones\TimezonesServiceProvider::class,
'Timezones'  => Raphaelb\Timezones\Facades\Timezones::class

use Raphaelb\Timezones\Facades\Timezones;
Examples
class User {

    // Accessors in model class.
    
    /**
     * Get created_at attr.
     * @param $date
     * @return string
     */
    public function getCreatedAtAttribute($date)
    {
        return app('timezones')
            ->toTimezone($date, 'gmt')
            ->format('d-m-Y H:i:s');
    }

    /**
     * Get updated_at attr.
     * 
     * @param $date
     * @return string
     */
    public function getUpdatedAtAttribute($date)
    {
        return app('timezones')
                ->toTimezone($date, 'gmt')
                ->format('d-m-Y H:i:s');
    }
    
    /**
     * Or inject a format when you know the given one. 
     * Otherwise Carbon will fail. 
     */
    public function time()
    {
        // Constructor accepts a different format for your needs.
        $time = new Timezones('m-d-Y H:i:s');
        return $time->toTimezone('09-03-2016 16:00:00', 'EST');
    }
        
}

License

MIT Licensed

About

Carbon wrapper for extra functionality when dealing with timezones.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages