Skip to content

Commit

Permalink
Fixed: DateTimer format24hr() doesn't work #2742 (#2775)
Browse files Browse the repository at this point in the history
  • Loading branch information
lihe6666 authored Dec 19, 2023
1 parent 2b728e5 commit e1c8759
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion resources/js/controllers/datetime_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class extends ApplicationController {

const configsAttributes = {
enableTime: 'enable-time',
time_24hr: 'time-24hr',
time_24hr: 'time_24hr',
allowInput: 'allow-input',
dateFormat: 'date-format',
noCalendar: 'no-calendar',
Expand Down
6 changes: 3 additions & 3 deletions src/Screen/Fields/DateTimer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class DateTimer extends Field
protected $attributes = [
'class' => 'form-control',
'data-datetime-enable-time' => 'false',
'data-datetime-time-24hr' => 'false',
'data-datetime-time_24hr' => 'false',
'data-datetime-allow-input' => 'false',
'data-datetime-date-format' => 'Y-m-d H:i:S',
'data-datetime-no-calendar' => 'false',
Expand Down Expand Up @@ -86,7 +86,7 @@ class DateTimer extends Field
'tabindex',
'value',
'data-datetime-enable-time',
'data-datetime-time-24hr',
'data-datetime-time_24hr',
'data-datetime-allow-input',
'data-datetime-date-format',
'data-datetime-no-calendar',
Expand Down Expand Up @@ -116,7 +116,7 @@ public function enableTime(bool $time = true): self
*/
public function format24hr(bool $time = true): self
{
$this->set('data-datetime-time-24hr', var_export($time, true));
$this->set('data-datetime-time_24hr', var_export($time, true));

return $this;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/Unit/Screen/Fields/DateTimerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,16 @@ public function testWithoutServerFormat(): void

$this->assertStringContainsString('value="2021-02-01 03:45:27"', $view);
}

public function testEnableTimeAndFormat24hr()
{
$field = DateTimer::make('date')
->format('Y-m-d H:i:s')
->enableTime()
->format24hr();

$view = self::renderField($field);

$this->assertStringContainsString('data-datetime-time_24hr="true"', $view);
}
}

0 comments on commit e1c8759

Please sign in to comment.