Problem/Motivation

Since 1.9 the time slot validation is broken.
Closing hours are earlier than Opening hours. is always shown if you add a time slot like 09:00am - 04:00pm (09:00 - 16:00)

Steps to reproduce

  1. Add a office_hours field to a node
  2. Enter the time slot 09:00am - 04:00pm
  3. try to save the node / media
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

sunlix created an issue. See original summary.

sunlix’s picture

At OfficeHoursBaseSlot, where the validation happens, the information about am/pm is lost.
Because of that the elseif condition is false-valid.

$start = OfficeHoursDateHelper::format($input['starthours'], 'H:i', FALSE); // "09:00"
$end = OfficeHoursDateHelper::format($input['endhours'], 'H:i', TRUE); // "04:00"

elseif ($validate_hours && $end < $start) {
  // Both Start and End must be entered. That is validated above already.
  $error_text = 'Closing hours are earlier than Opening hours.';
  $erroneous_element = &$element;
}

lukasz.tyc made their first commit to this issue’s fork.

luk.tc’s picture

QUick fix for validate hours

luk.tc’s picture

StatusFileSize
new732 bytes
johnv’s picture

I have a problem reproducing this error: it seems I cannot create a HTML5 time input element with [Hours:Minutes am/pm]. Even if fields settings says so, the am/pm part is not shown, and always 24hrs is used.
Using a Windows 11 PC, with Edge, Chrome, Firefox .
What is your environment?

msupko’s picture

StatusFileSize
new609 bytes

Patch #5 did not work for me; it evaluates the previous value of the input rather than the current one, so it only works as long as you are not changing the hours.

The root of the problem seems to be in the new formatters introduced in 1.9; here is a patch that targets this specifically. This resolves the validation issue for me, and may resolve other (as yet unidentified) issues as well.

  • johnv committed aef44f56 on 8.x-1.x
    Issue #3363479: Select-List Time-Slot validation is broken since 1.9
    

  • johnv committed 4c1d0888 on 8.x-1.x
    Issue #3363479: Select-List Time-Slot validation is broken since 1.9
    

  • johnv committed 960ce670 on 8.x-1.x
    Issue #3363479 by msupko: Time-Slot-Validation is broken
    
johnv’s picture

Title: Time-Slot-Validation is broken since 1.9 » Select List Time Validation is broken since 1.9
Version: 8.x-1.x-dev » 8.x-1.9
Status: Active » Fixed

Thanks,
should be fixed now.
The last commit contains some housekeeping and better message handling (time format)

johnv’s picture

Status: Fixed » Needs work

Some other check is not always processed correctly.

  • johnv committed cd0ed361 on 8.x-1.x
    Issue #3363479: Select List Time Validation
    
johnv’s picture

Status: Needs work » Fixed
johnv’s picture

Status: Fixed » Needs work

There is an error in some PHP version "string * int" is not possible.

  • johnv committed 1fdc050d on 8.x-1.x
    Issue #3363479: Select List Time Validation is broken since 1.9
    
johnv’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.