3 declare(strict_types=1);
15 $ui = $DIC->ui()->factory();
16 $data = new \ILIAS\Data\Factory();
17 $renderer = $DIC->ui()->renderer();
18 $request = $DIC->http()->request();
22 $date = $ui->input()->field()->dateTime(
"Pick a date",
"Pick any date you want. It will be shown in format YYYY-MM-DD");
24 $date_now = new \DateTimeImmutable(
'now');
26 ->withMinValue($date_now)
27 ->withFormat(
$data->dateFormat()->germanShort())
28 ->withLabel(
'future only')
29 ->withByline(
'Only allows to pick a date in the future. It will be shown in format DD.MM.YYYY');
31 $time = $date->withTimeOnly(
true)
32 ->withLabel(
'time only')
33 ->withByline(
'Only pick a time. It will be shown in format HH:mm');
35 $both = $date->withUseTime(
true)
36 ->withLabel(
'both date and time')
37 ->withByline(
'Pick any date and time you want. It will be shown in format YYYY-MM-DD HH:mm and be saved for your local time zone.');
41 $timezoned = $both->withTimezone($tz)
43 ->withLabel(
'to Tokyo time')
44 ->withByline(
'Pick any date and time you want. It will be shown in format YYYY-MM-DD HH:mm and be saved for Tokyo time zone.');
47 $date_now = new \DateTime(
'now');
48 $date_zoned = new \DateTime(
'now',
new \
DateTimeZone($tz));
51 $format = $timezoned->getFormat()->toString() .
' H:i';
52 $timezoned_preset1 = $timezoned
53 ->withValue($date_now->format($format))
54 ->withLabel(
'to Tokyo time with local preset')
55 ->withByline(
'Local time+date is preset. However, output will be in Tokyo timezone');
56 $timezoned_preset2 = $timezoned
57 ->withValue($date_zoned->format($format))
58 ->withLabel(
'Tokyo time, both preset and output')
59 ->withByline(
'Tokyo time+date is preset. Output is also Tokyo time.');
62 ->withValue($date_now->format($timezoned->getFormat()->toString()))
64 ->withLabel(
'disabled')
65 ->withByline(
'You cannot pick anything, as the field is disabled');
67 $required = $date->withRequired(
true);
70 $form = $ui->input()->container()->form()->standard(
'#', [
72 'formatted' => $formatted,
74 'both_datetime' => $both,
75 'to_tokyotime' => $timezoned,
76 'tokyotime_local_preset' => $timezoned_preset1,
77 'tokyotime' => $timezoned_preset2,
78 'disabled' => $disabled,
79 'required' => $required
83 if ($request->getMethod() ==
"POST") {
84 $form = $form->withRequest($request);
85 $result = $form->getData();
87 $result =
"No result yet.";
92 "<pre>" . print_r($result,
true) .
"</pre><br/>" .
93 $renderer->render($form);