format('Y-m-d'); $timeString = sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds); $dateTime = new DateTimeImmutable("$dateString $timeString", $timezone); return $dateTime->getTimestamp(); } catch (\Throwable $exception) { throw new RuntimeException( BackendStrings::getExceptionStrings()['time_conversion_failed'] . ': ' . $exception->getMessage() ); } } /** * Format Unix timestamp back to time string (HH:MM). * * @param int $timestamp Unix timestamp * @return string Formatted time string without seconds */ public static function timestampToTime(int $timestamp): string { $timezone = self::getWpTimezone(); $dateTime = new DateTimeImmutable('@' . $timestamp); $dateTime = $dateTime->setTimezone($timezone); return $dateTime->format('H:i'); } /** * Format Unix timestamp back to time string with seconds (HH:MM:SS). * * @param int $timestamp Unix timestamp * @return string Formatted time string with seconds */ public static function timestampToTimeWithSeconds(int $timestamp): string { $timezone = self::getWpTimezone(); $dateTime = new DateTimeImmutable('@' . $timestamp); $dateTime = $dateTime->setTimezone($timezone); return $dateTime->format('H:i:s'); } /** * Get WordPress timezone. * * @return DateTimeZone * @throws RuntimeException If unable to get valid timezone */ public static function getWpTimezone(): DateTimeZone { if (!function_exists('wp_timezone')) { throw new RuntimeException(BackendStrings::getExceptionStrings()['wp_timezone_not_exist']); } return wp_timezone(); } /** * Normalize time values to Unix timestamp format. * * @param int|string|null $value Field value * @return string Normalized value as string */ public static function normalizeTimeValue($value): string { if ($value === null || $value === '') { return ''; } return (string)(self::timeToTimestamp($value) ?? $value); } }