3 declare(strict_types=1);
16 $ui = $DIC->ui()->factory();
17 $data = new \ILIAS\Data\Factory();
18 $renderer = $DIC->ui()->renderer();
19 $request = $DIC->http()->request();
23 $date = $ui->input()->field()->dateTime(
"Pick a date/time",
"Pick any date you want. It will be shown in format YYYY-MM-DD");
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(
$format))
64 ->withLabel(
'disabled')
65 ->withByline(
'You cannot pick anything, as the field is disabled');
68 $form = $ui->input()->container()->form()->standard(
'#', [
70 'formatted' => $formatted,
72 'both_datetime' => $both,
73 'to_tokyotime' => $timezoned,
74 'tokyotime_local_preset' => $timezoned_preset1,
75 'tokyotime' => $timezoned_preset2,
76 'disabled' => $disabled
80 if ($request->getMethod() ==
"POST") {
81 $form = $form->withRequest($request);
82 $result = $form->getData();
84 $result =
"No result yet.";
89 "<pre>" . print_r($result,
true) .
"</pre><br/>" .
90 $renderer->render($form);