Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

archboard/tidal-ptc

4 stars
3 code files
View archboard/tidal-ptc on GitHub

app/Traits/HasTimezone.php

Open in GitHub
use Carbon\CarbonImmutable;
use Carbon\FactoryImmutable as Factory;
 
trait HasTimezone
{
public function getCarbonSettings(): array
{
return [
'locale' => app()->getLocale(),
'timezone' => $this->timezone ?? config('app.timezone'),
];
}
 
public function getCarbonFactory(): Factory
{
return new Factory($this->getCarbonSettings());
}
 
public function now(): CarbonImmutable
{
return $this->getCarbonFactory()
->now($this->getCarbonSettings()['timezone']);
}
 
public function today(): CarbonImmutable
{
return $this->getCarbonFactory()
->today();
}
 
public function dateToApp(string|CarbonImmutable $date): CarbonImmutable
{
return $this->getCarbonFactory()
->parse($date)
->setTimezone(config('app.timezone'));
}
 
public function dateFromApp(string|CarbonImmutable $date): CarbonImmutable
{
return CarbonImmutable::parse($date)
->setTimezone($this->timezone ?? config('app.timezone'))
->settings($this->getCarbonSettings());
}
}

app/Models/User.php

Open in GitHub
use App\Traits\HasTimezone;
 
class User extends Authenticatable implements ExistsInSis
{
use HasTimezone;
 
// ...
}

app/Models/School.php

Open in GitHub
use App\Traits\HasTimezone;
 
class School extends Model implements ExistsInSis
{
use HasTimeSlots;
 
// ...
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.