auth->getInfo('user_tz'))); return $d ? date_format($d->setTimezone(new DateTimeZone('UTC')), $format) : ''; } /** * Format a date from user TZ to UTC */ public static function toUser(string $date, string $format = 'Y-m-d\TH:i'): string { $d = date_create($date, new DateTimeZone('UTC')); return $d ? date_format($d->setTimezone(new DateTimeZone(dcCore::app()->auth->getInfo('user_tz'))), $format) : ''; } /** * Format a date to specific TZ (UTC by default) from another format */ public static function toDate(int|string $date = 'now', string $format = 'Y-m-d H:i:00', string $to_tz = 'UTC'): string { $d = is_int($date) ? date_create_from_format('U', (string) $date, new DateTimeZone('UTC')) : date_create($date, new DateTimeZone('UTC')); return $d ? date_format($d->setTimeZone(new DateTimeZone($to_tz)), $format) : ''; } /** * Get next timestamp from a period */ public static function getNextTime(int $ts, string $period): int { $dt = date_create_from_format('U', (string) $ts); if ($dt === false) { return $ts; } switch($period) { case 'hour': $dt->modify('+1 hour'); break; case 'halfday': $dt->modify('+12 hours'); break; case 'day': $dt->modify('+1 day'); break; case 'week': $dt->modify('+1 week'); break; case 'month': $dt->modify('+1 month'); break; default: throw new Exception(__('Unknow frequence')); } return (int) $dt->format('U'); } }