Skip to content

Commit 059e9f7

Browse files
Wolfgang Tischerbgermann
authored andcommitted
CRITICAL FIX: Restore correct timezone handling for form scheduling
🐛 Critical Timezone Fix: - Simplified and corrected convertFormatToTime() method in FormSettings.php - Ensure forms disable at correct LOCAL time, not UTC - Fix 2-hour shift issue that was reintroduced - Use proper WordPress timezone handling with fallback This fixes the core issue where forms would disable 2 hours early due to incorrect UTC/local time conversion. Now forms disable exactly at the time specified in the admin interface.
1 parent 3bf6562 commit 059e9f7

1 file changed

Lines changed: 7 additions & 19 deletions

File tree

FormSettings.php

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,32 +67,20 @@ private function convertFormatToTime($formatted_date)
6767
return 0;
6868
}
6969

70-
// WordPress-Zeitzone verwenden
71-
$timezone_string = get_option('timezone_string');
72-
if (empty($timezone_string)) {
73-
// Fallback für manuelle UTC-Offsets
74-
$gmt_offset = get_option('gmt_offset');
75-
$timezone_string = timezone_name_from_abbr('', $gmt_offset * 3600, 0);
76-
if ($timezone_string === false) {
77-
// Weitere Fallback-Option
78-
$timezone_string = $gmt_offset >= 0 ? '+' . $gmt_offset : $gmt_offset;
79-
$timezone_string = 'Etc/GMT' . $timezone_string;
80-
}
81-
}
82-
8370
try {
84-
$timezone = new \DateTimeZone($timezone_string);
71+
// WordPress-Zeitzone verwenden
72+
$timezone = new \DateTimeZone(get_option('timezone_string') ?: 'UTC');
8573
$dt = \DateTime::createFromFormat('d/m/Y H:i', $formatted_date, $timezone);
8674
if ($dt !== false) {
8775
return $dt->getTimestamp();
8876
}
8977
} catch (\Exception $e) {
90-
// Fallback zur alten Methode bei Fehlern, aber mit current_time
78+
// Fallback: Parse als lokale Zeit und konvertiere zu UTC
9179
$time = str_replace('/', '.', $formatted_date);
92-
$time = strtotime($time);
93-
if ($time !== false) {
94-
// Konvertierung von lokaler Zeit zu UTC-Timestamp
95-
return $time - (get_option('gmt_offset') * 3600) + (current_time('timestamp') - time());
80+
$timestamp = strtotime($time);
81+
if ($timestamp !== false) {
82+
// Korrigiere für WordPress-Zeitzone
83+
return $timestamp - (get_option('gmt_offset') * 3600);
9684
}
9785
}
9886

0 commit comments

Comments
 (0)