Skip to content

feature(DatePickerSetupControl): improved resolution of the alternati…#1307

Merged
JohnVillalovos merged 1 commit intoLibreBooking:developfrom
labmecanicatec:flatpickr
Apr 5, 2026
Merged

feature(DatePickerSetupControl): improved resolution of the alternati…#1307
JohnVillalovos merged 1 commit intoLibreBooking:developfrom
labmecanicatec:flatpickr

Conversation

@labmecanicatec
Copy link
Copy Markdown
Collaborator

…ve format and documentation.

Add comprehensive class docblock and examples, and refactor alt-format handling for the DatePicker setup control. Introduce ResolvePhpAltFormat() to resolve AltFormat either as a resource key or raw PHP format, compute phpAltFormat and convert it to Flatpickr format, and base 24hr time detection on the resolved alt format. Also adjust default PHP alt format to include time when HasTimepicker is true and expose Time24Hr and DateFormat appropriately.

Copilot AI review requested due to automatic review settings April 4, 2026 20:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances DatePickerSetupControl by documenting its public inputs and refactoring how the control resolves and converts the alternate display format (AltFormat) for Flatpickr, including improved 24-hour time detection.

Changes:

  • Add a comprehensive class docblock describing supported inputs and providing Smarty usage examples.
  • Refactor alt-format handling to resolve AltFormat as either a Resources key or a raw PHP date format, then convert it to Flatpickr format.
  • Introduce ResolvePhpAltFormat() and base Time24Hr detection on the resolved PHP alt format.

Comment thread Controls/DatePickerSetupControl.php
Comment thread Controls/DatePickerSetupControl.php Outdated
Comment thread Controls/DatePickerSetupControl.php Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread Controls/DatePickerSetupControl.php
Comment thread Controls/DatePickerSetupControl.php
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread Controls/DatePickerSetupControl.php
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread Controls/DatePickerSetupControl.php
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

Comment on lines +247 to +251
if ($isEscaped) {
// PHP and Flatpickr both use backslash to escape literals.
$result .= '\\' . $c;
$isEscaped = false;
continue;
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When $isEscaped is true, this appends '\\' . $c, which evaluates to two backslashes plus the char. For Flatpickr escaping you typically want to emit a single backslash character before the literal (the JSON encoding step will take care of escaping it for JS). Consider appending a single backslash instead so escaped literals like \T round-trip correctly.

Copilot uses AI. Check for mistakes.
Comment on lines +254 to +257
if ($c === '\\') {
$isEscaped = true;
continue;
}
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if ($c === '\\') will never match because $c from str_split() is a single-character string (\), while '\\' evaluates to two backslashes. This prevents escape detection and will break formats that contain escaped literals (and also impacts the time/AMPM detection helpers below). Compare against a single backslash character instead.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Copilot is wrong about this. '\\' is converted to a single backslash.

}

if ($isEscaped) {
$result .= '\\\\';
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the PHP format ends with a trailing backslash, $result .= '\\\\'; adds multiple backslashes (this literal evaluates to more than one \). Given Flatpickr escaping rules, this likely over-escapes; after fixing the single-backslash detection above, also adjust this to emit the intended number of backslashes (usually \\ in the Flatpickr format to represent a literal \).

Suggested change
$result .= '\\\\';
$result .= str_repeat('\\', 2);

Copilot uses AI. Check for mistakes.
Comment on lines +316 to +319
if ($c === '\\') {
$isEscaped = true;
continue;
}
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In HasTimeComponentInPhpFormat(), if ($c === '\\') won’t ever match a single backslash character from str_split(), so $isEscaped is never set. That makes escaped literals (e.g. \H, \A) incorrectly count as time/AMPM tokens. Update the check to compare against a single backslash.

Copilot uses AI. Check for mistakes.
Comment on lines +340 to +343
if ($c === '\\') {
$isEscaped = true;
continue;
}
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same escape-handling issue here: if ($c === '\\') will never match a single backslash from str_split(), so escaped literals aren’t skipped and a/A can be mis-detected even when escaped. Compare against a single backslash so $isEscaped works as intended.

Copilot uses AI. Check for mistakes.
…format and documentation.

Add comprehensive class docblock and examples, and refactor alt-format handling for the DatePicker setup control. Introduce ResolvePhpAltFormat() to resolve AltFormat either as a resource key or raw PHP format, compute phpAltFormat and convert it to Flatpickr format, and base 24hr time detection on the resolved alt format. Also adjust default PHP alt format to include time when HasTimepicker is true and expose Time24Hr and DateFormat appropriately.
Add HasDateFormat($key) to IResourceLocalization/Resources and use it from DatePickerSetupControl to resolve AltFormat without relying on the "?" fallback.
Copy link
Copy Markdown
Collaborator

@JohnVillalovos JohnVillalovos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @labmecanicatec

LGTM

@JohnVillalovos JohnVillalovos enabled auto-merge (rebase) April 5, 2026 17:52
@JohnVillalovos JohnVillalovos merged commit e9e6a3f into LibreBooking:develop Apr 5, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants