PDOException is thrown when end date is before start date

Created on 1 May 2023, over 1 year ago
Updated 2 May 2023, over 1 year ago

Problem/Motivation

In the function _resource_conflict_get_timespans, when users enter an end date that is the same as or after a start date, both $start and $end are strings. However, when users enter an end date that is before a start date, $start is a string, but $end is a DateObject which causes PDOException at line 227 inside the function _resource_conflict_query_for_conflicts.

This is the exception I got with my data replaced with <data_removed>:

PDOException: SQLSTATE[HY000]: General error: 1525 Incorrect DATETIME value:
'2023-04-21 08:30 America/Vancouver': SELECT DISTINCT n.nid AS nid
FROM
{node} n
INNER JOIN {field_data_field_date} date_table ON n.vid =
date_table.revision_id
WHERE  (bundle IN  (:db_condition_placeholder_0, :db_condition_placeholder_1,
:db_condition_placeholder_2, :db_condition_placeholder_3,
:db_condition_placeholder_4)) AND(( (date_table.field_date_value <=
:db_condition_placeholder_5) AND (date_table.field_date_value2 >
:db_condition_placeholder_6) )OR( (date_table.field_date_value <
:db_condition_placeholder_7) AND (date_table.field_date_value2 >=
:db_condition_placeholder_8) )OR( (date_table.field_date_value >=
:db_condition_placeholder_9) AND (date_table.field_date_value2 <=
:db_condition_placeholder_10) )); Array
(
      [:db_condition_placeholder_0] => event
      [:db_condition_placeholder_1] => <data_removed>
      [:db_condition_placeholder_2] => <data_removed>
      [:db_condition_placeholder_3] => <data_removed>
      [:db_condition_placeholder_4] => <data_removed>
      [:db_condition_placeholder_5] => 2023-04-21 09:00
      [:db_condition_placeholder_6] => 2023-04-21 09:00
      [:db_condition_placeholder_7] => DateObject Object
          (
              [granularity] => Array
                  (
                      [0] => hour
                      [1] => minute
                      [3] => month
                      [4] => day
                      [5] => year
                      [6] => timezone
                  )
 
              [errors] => Array
                  (
                      [invalid] => The value 2023/04/21 12am does not match 
the
expected format.
                  )
 
              [timeOnly] =>
              [dateOnly] => 1
              [originalTime] => 2023/04/21 12am
              [date] => 2023-04-21 08:30:45.000000
              [timezone_type] => 3
              [timezone] => America/Vancouver
          )
 
      [:db_condition_placeholder_8] => DateObject Object
          (
              [granularity] => Array
                  (
                      [0] => hour
                      [1] => minute
                      [3] => month
                      [4] => day
                      [5] => year
                      [6] => timezone
                  )
 
              [errors] => Array
                  (
                      [invalid] => The value 2023/04/21 12am does not match 
the
expected format.
                  )
 
              [timeOnly] =>
              [dateOnly] => 1
              [originalTime] => 2023/04/21 12am
              [date] => 2023-04-21 08:30:45.000000
              [timezone_type] => 3
              [timezone] => America/Vancouver
          )
 
      [:db_condition_placeholder_9] => 2023-04-21 09:00
      [:db_condition_placeholder_10] => DateObject Object
          (
              [granularity] => Array
                  (
                      [0] => hour
                      [1] => minute
                      [3] => month
                      [4] => day
                      [5] => year
                      [6] => timezone
                  )
 
              [errors] => Array
                  (
                      [invalid] => The value 2023/04/21 12am does not match 
the
expected format.
                  )
 
              [timeOnly] =>
              [dateOnly] => 1
              [originalTime] => 2023/04/21 12am
              [date] => 2023-04-21 08:30:45.000000
              [timezone_type] => 3
              [timezone] => America/Vancouver
          )
 
)
   in _resource_conflict_query_for_conflicts() (line 227 of
/.../public/sites/all/modules/contrib/resource_conflict/resource_conflict.module).
🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇨🇦Canada franceslui

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024