ILIAS  release_8 Revision v8.23
ilIndividualAssessmentDateFormatter.php
Go to the documentation of this file.
1 <?php
18 declare(strict_types=1);
19 
22 
24 {
26 
27  public function __construct(DataFactory $data_factory)
28  {
29  $this->data_factory = $data_factory;
30  }
31 
32  public function getUserDateFormat(ilObjUser $user, bool $with_time = false): DateFormat
33  {
34  $df = $this->data_factory->dateFormat();
35  switch ($user->getDateFormat()) {
37  $date_format = $df->germanShort();
38  break;
40  //americanShort
41  $date_format = $df->custom()->month()->slash()->day()->slash()->year()->get();
42  break;
44  default:
45  $date_format = $df->standard();
46  }
47  if ($with_time) {
48  switch ($user->getTimeFormat()) {
50  $date_format = $df->withTime12($date_format);
51  break;
53  default:
54  $date_format = $df->withTime24($date_format);
55  }
56  }
57  return $date_format;
58  }
59 
60  public function format(
61  ilObjUser $user,
62  DateTimeImmutable $datetime,
63  bool $with_time = false
64  ): string {
65  return $this->getUserDateFormat($user, $with_time)->applyTo($datetime);
66  }
67 }
getUserDateFormat(ilObjUser $user, bool $with_time=false)
A Date Format provides a format definition akin to PHP&#39;s date formatting options, but stores the sing...
Definition: DateFormat.php:26
format(ilObjUser $user, DateTimeImmutable $datetime, bool $with_time=false)