3 declare(strict_types=1);
49 $ui = $DIC->ui()->factory();
50 $data = new \ILIAS\Data\Factory();
52 $request = $DIC->http()->request();
56 $date = $ui->input()->field()->dateTime(
"Pick a date",
"Pick any date you want. It will be shown in format YYYY-MM-DD");
58 $date_now = new \DateTimeImmutable(
'now');
60 ->withMinValue($date_now)
61 ->withFormat(
$data->dateFormat()->germanShort())
62 ->withLabel(
'future only')
63 ->withByline(
'Only allows to pick a date in the future. It will be shown in format DD.MM.YYYY');
65 $time = $date->withTimeOnly(
true)
66 ->withLabel(
'time only')
67 ->withByline(
'Only pick a time. It will be shown in format HH:mm');
69 $both = $date->withUseTime(
true)
70 ->withLabel(
'both date and time')
71 ->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.');
75 $timezoned = $both->withTimezone($tz)
77 ->withLabel(
'to Tokyo time')
78 ->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.');
81 $date_now = new \DateTime(
'now');
82 $date_zoned = new \DateTime(
'now',
new \
DateTimeZone($tz));
85 $format = $timezoned->getFormat()->toString() .
' H:i';
86 $timezoned_preset1 = $timezoned
87 ->withValue($date_now->format($format))
88 ->withLabel(
'to Tokyo time with local preset')
89 ->withByline(
'Local time+date is preset. However, output will be in Tokyo timezone');
90 $timezoned_preset2 = $timezoned
91 ->withValue($date_zoned->format($format))
92 ->withLabel(
'Tokyo time, both preset and output')
93 ->withByline(
'Tokyo time+date is preset. Output is also Tokyo time.');
96 ->withValue($date_now->format($timezoned->getFormat()->toString()))
98 ->withLabel(
'disabled')
99 ->withByline(
'You cannot pick anything, as the field is disabled');
101 $required = $date->withRequired(
true);
104 $form = $ui->input()->container()->form()->standard(
'#', [
106 'formatted' => $formatted,
107 'time_only' => $time,
108 'both_datetime' => $both,
109 'to_tokyotime' => $timezoned,
110 'tokyotime_local_preset' => $timezoned_preset1,
111 'tokyotime' => $timezoned_preset2,
112 'disabled' => $disabled,
113 'required' => $required
117 if ($request->getMethod() ==
"POST") {
118 $form = $form->withRequest($request);
119 $result = $form->getData();
121 $result =
"No result yet.";
126 "<pre>" . print_r($result,
true) .
"</pre><br/>" .