@@ -92,6 +92,7 @@ public function create(string $name, string $version = 'latest', string $db = 'm
9292 'admin_pass ' => 'password ' ,
9393 'admin_email ' => 'admin@example.test ' ,
9494 'board_email ' => 'board@example.test ' ,
95+ 'board_timezone ' => $ this ->hostTimezone (),
9596 'extensions ' => [],
9697 'styles ' => [],
9798 ];
@@ -124,6 +125,7 @@ public function create(string $name, string $version = 'latest', string $db = 'm
124125 'path ' => $ boardDir ,
125126 'populate ' => $ populate ,
126127 'debug ' => $ debug ,
128+ 'board_timezone ' => $ config ['board_timezone ' ],
127129 'extensions ' => [],
128130 'styles ' => [],
129131 'created_at ' => gmdate ('c ' ),
@@ -142,6 +144,53 @@ public function create(string $name, string $version = 'latest', string $db = 'm
142144 return ['board ' => $ board , 'paths ' => $ paths ];
143145 }
144146
147+ /** Returns the host's PHP-supported timezone identifier, falling back to UTC. */
148+ protected function hostTimezone (): string
149+ {
150+ $ candidates = [];
151+ $ environment = getenv ('TZ ' );
152+ if (is_string ($ environment ))
153+ {
154+ $ candidates [] = ltrim (trim ($ environment ), ': ' );
155+ }
156+
157+ $ localtime = realpath ('/etc/localtime ' );
158+ if (is_string ($ localtime ) && preg_match ('#/zoneinfo/(.+)$# ' , $ localtime , $ match ))
159+ {
160+ $ candidates [] = $ match [1 ];
161+ }
162+
163+ if (is_readable ('/etc/timezone ' ))
164+ {
165+ $ timezone = file_get_contents ('/etc/timezone ' );
166+ if (is_string ($ timezone ))
167+ {
168+ $ candidates [] = trim ($ timezone );
169+ }
170+ }
171+
172+ $ candidates [] = date_default_timezone_get ();
173+ foreach ($ candidates as $ candidate )
174+ {
175+ if ($ candidate === '' )
176+ {
177+ continue ;
178+ }
179+
180+ try
181+ {
182+ // Match phpBB's own timezone validation semantics.
183+ new \DateTimeZone ($ candidate );
184+ return $ candidate ;
185+ }
186+ catch (\Exception $ e )
187+ {
188+ }
189+ }
190+
191+ return 'UTC ' ;
192+ }
193+
145194 private function backupBoardState (string $ name ): array
146195 {
147196 $ token = str_replace ('. ' , '' , uniqid ('replace- ' , true ));
0 commit comments