misc_pterodactyl-panel/app/Helpers/Time.php
Matthew Penner 04d83edd36
app: fix getMySQLTimezoneOffset() truncating seconds
Previously the `getMySQLTimezoneOffset()` function would truncate the
seconds part of a time offset (returning `+9:00` instead of `+9:30`) for
example. This only affects timezones with offsets that contain minutes.

Closes https://github.com/pterodactyl/panel/issues/4821
Superseeds https://github.com/pterodactyl/panel/pull/4827

Co-authored-by: danny6167 <daniel@barteck.com.au>
2023-08-22 18:54:59 -06:00

20 lines
594 B
PHP

<?php
namespace Pterodactyl\Helpers;
use Carbon\CarbonImmutable;
final class Time
{
/**
* Gets the time offset from the provided timezone relative to UTC as a number. This
* is used in the database configuration since we can't always rely on there being support
* for named timezones in MySQL.
*
* Returns the timezone as a string like +08:00 or -05:00 depending on the app timezone.
*/
public static function getMySQLTimezoneOffset(string $timezone): string
{
return CarbonImmutable::now($timezone)->getTimezone()->toOffsetName();
}
}