@@ -319,23 +319,24 @@ protected function send_ajax_response($success, $text)
319319 /**
320320 * Validate advertisement date
321321 *
322- * The date must use the expected format of YYYY-MM-DD.
323- * If the date is valid, convert it to a timestamp and then
324- * make sure the timestamp is less than the current time.
325- *
326322 * @param string $date Advertisement date
327- * @return int The date converted to timestamp if valid, otherwise 0.
323+ * @param string $type Date type
324+ * @return int UTC midnight timestamp if valid, otherwise 0
328325 */
329326 protected function validate_date ($ date , $ type )
330327 {
331328 $ timestamp = 0 ;
332329 if (preg_match ('#^\d{4}-\d{2}-\d{2}$# ' , $ date ))
333330 {
331+ // Create a UTC midnight timestamp for storage consistency
334332 $ datetime = \DateTime::createFromFormat (ext::DATE_FORMAT , $ date , new \DateTimeZone ('UTC ' ));
335- $ datetime ->setTime (0 , 0 , 0 );
333+ $ datetime ->setTime (0 , 0 , 0 ); // Ensure midnight (00:00:00)
336334 $ timestamp = $ datetime ->getTimestamp ();
337335
338- if ($ timestamp < time ())
336+ // Compare against a user's timezone to prevent timezone confusion
337+ // 'today' creates today's date at midnight in the user's timezone
338+ $ user_today = new \DateTime ('today ' , $ this ->user ->timezone );
339+ if ($ timestamp < $ user_today ->getTimestamp ())
339340 {
340341 $ this ->errors [] = 'AD_ ' . $ type . '_DATE_INVALID ' ;
341342 }
0 commit comments