19 declare(strict_types=1);
65 $ui = $DIC->ui()->factory();
66 $data = new \ILIAS\Data\Factory();
68 $request = $DIC->http()->request();
72 $date = $ui->input()->field()->dateTime(
"Pick a date",
"Pick any date you want. It will be shown in format YYYY-MM-DD");
74 $date_now = new \DateTimeImmutable(
'now');
76 ->withMinValue($date_now)
77 ->withFormat(
$data->dateFormat()->germanShort())
78 ->withLabel(
'future only')
79 ->withByline(
'Only allows to pick a date in the future. It will be shown in format DD.MM.YYYY');
81 $time = $date->withTimeOnly(
true)
82 ->withLabel(
'time only')
83 ->withByline(
'Only pick a time. It will be shown in format HH:mm');
85 $both = $date->withUseTime(
true)
86 ->withLabel(
'both date and time')
87 ->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.');
91 $timezoned = $both->withTimezone($tz)
93 ->withLabel(
'to Tokyo time')
94 ->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.');
97 $date_now = new \DateTime(
'now');
98 $date_zoned = new \DateTime(
'now',
new \
DateTimeZone($tz));
101 $format = $timezoned->getFormat()->toString() .
' H:i';
102 $timezoned_preset1 = $timezoned
103 ->withValue($date_now->format($format))
104 ->withLabel(
'to Tokyo time with local preset')
105 ->withByline(
'Local time+date is preset. However, output will be in Tokyo timezone');
106 $timezoned_preset2 = $timezoned
107 ->withValue($date_zoned->format($format))
108 ->withLabel(
'Tokyo time, both preset and output')
109 ->withByline(
'Tokyo time+date is preset. Output is also Tokyo time.');
112 ->withValue($date_now->format($timezoned->getFormat()->toString()))
114 ->withLabel(
'disabled')
115 ->withByline(
'You cannot pick anything, as the field is disabled');
117 $required = $date->withRequired(
true);
120 $form = $ui->input()->container()->form()->standard(
'#', [
122 'formatted' => $formatted,
123 'time_only' => $time,
124 'both_datetime' => $both,
125 'to_tokyotime' => $timezoned,
126 'tokyotime_local_preset' => $timezoned_preset1,
127 'tokyotime' => $timezoned_preset2,
128 'disabled' => $disabled,
129 'required' => $required
133 if ($request->getMethod() ==
"POST") {
134 $form = $form->withRequest($request);
135 $result = $form->getData();
137 $result =
"No result yet.";
142 "<pre>" . print_r($result,
true) .
"</pre><br/>" .