Skip to content

Commit

Permalink
UI: remove DateTime::withFormat
Browse files Browse the repository at this point in the history
This functionality has become obsolete with the introduction of HTML 5 inputs
for datetimes. Formatting will now be determined by the browser.
  • Loading branch information
klees committed Oct 23, 2023
1 parent 8130072 commit 8fb561e
Show file tree
Hide file tree
Showing 25 changed files with 24 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ protected function buildForm(
$this->lng,
$this->refinery_factory,
$this,
$this->user->getDateFormat(),
$this->getPossibleLPStates(),
$may_be_edited,
$this->getObject()->getSettings()->isEventTimePlaceRequired(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ public function toFormInput(
ilLanguage $lng,
Refinery $refinery,
AbstractCtrlAwareUploadHandler $file_handler,
\ILIAS\Data\DateFormat\DateFormat $date_format,
array $grading_options,
bool $may_be_edited = true,
bool $place_required = false,
Expand Down Expand Up @@ -187,7 +186,6 @@ public function toFormInput(
$event_time = $input
->dateTime($lng->txt('iass_event_time'))
->withUseTime(true)
->withFormat($date_format)
->withRequired($place_required)
->withDisabled(!$may_be_edited)
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ public function testToFormInput(): void
$lng,
$refinery,
$file_handler,
$df->dateFormat()->standard(),
[
ilIndividualAssessmentMembers::LP_IN_PROGRESS,
ilIndividualAssessmentMembers::LP_FAILED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,13 @@ protected function getDeadlineSubForm(ilObjStudyProgramme $prg): FormInput

$option = ilObjStudyProgrammeSettingsGUI::OPT_NO_DEADLINE;
$deadline_date = $prg->getSettings()->getDeadlineSettings()->getDeadlineDate();
$format = $this->data_factory->dateFormat()->germanShort();
$deadline_date_sub_form = $ff
->dateTime('', $txt('prg_deadline_date_desc'))
->withFormat($format)
;

if ($deadline_date !== null) {
$deadline_date_sub_form = $deadline_date_sub_form->withValue(
$deadline_date->format($format->toString())
$deadline_date
);
$option = ilObjStudyProgrammeSettingsGUI::OPT_DEADLINE_DATE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,11 @@ protected function getValidityOfQualificationSubForm(ilObjStudyProgramme $prg):
};

$option = ilObjStudyProgrammeSettingsGUI::OPT_NO_VALIDITY_OF_QUALIFICATION;
$format = $this->data_factory->dateFormat()->germanShort();
$vq_date_sub_form = $ff
->dateTime('', $txt('validity_qualification_date_desc'))
->withFormat($format);
->dateTime('', $txt('validity_qualification_date_desc'));
$date = $prg->getSettings()->getValidityOfQualificationSettings()->getQualificationDate();
if ($date !== null) {
$vq_date_sub_form = $vq_date_sub_form->withValue($date->format($format->toString()));
$vq_date_sub_form = $vq_date_sub_form->withValue($date);
$option = ilObjStudyProgrammeSettingsGUI::OPT_VALIDITY_OF_QUALIFICATION_DATE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ public function toFormInput(
Refinery $refinery,
Factory $data_factory
): \ILIAS\UI\Component\Input\Container\Form\FormInput {
$format = $data_factory->dateFormat()->germanShort();

$grp1 = $input->group([], $lng->txt('prg_no_deadline'));
$grp2 = $input->group(
[
Expand All @@ -91,8 +89,7 @@ public function toFormInput(
$lng->txt('prg_deadline_date_label'),
$lng->txt('prg_deadline_date_desc')
)
->withFormat($format)
->withValue($this->getDeadlineDate() !== null ? $this->getDeadlineDate()->format('d.m.Y') : '')
->withValue($this->getDeadlineDate())
->withRequired(true)
],
$lng->txt('prg_deadline_date')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public function toFormInput(
Refinery $refinery,
Factory $data_factory
): \ILIAS\UI\Component\Input\Container\Form\FormInput {
$format = $data_factory->dateFormat()->germanShort();
$grp1 = $input->group([], $lng->txt('prg_no_validity_qualification'));
$grp2 = $input->group(
[
Expand All @@ -130,8 +129,7 @@ public function toFormInput(
$lng->txt('vq_date_label'),
$lng->txt('validity_qualification_date_desc')
)
->withFormat($format)
->withValue($this->getQualificationDate() !== null ? $this->getQualificationDate()->format('d.m.Y') : '')
->withValue($this->getQualificationDate())
->withRequired(true)
],
$lng->txt('validity_qualification_date')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ private function buildForm(string $form_command = self::CMD_SAVE_FORM): Standard
$user_format = $this->activeUser->getDateFormat();

$environment['participant_data_exists'] = $this->test_object->participantDataExist();
$environment['user_date_format'] = $data_factory->dateFormat()->withTime24($user_format);
$environment['user_time_zone'] = $this->activeUser->getTimeZone();

$main_inputs = [
Expand Down Expand Up @@ -464,12 +463,9 @@ private function getTimebasedAvailabilityInputs(): OptionalGroup
$value = $this->getValueForActivationLimitedOptionalGroup();

$data_factory = new DataFactory();
$user_format = $this->activeUser->getDateFormat();
$format = $data_factory->dateFormat()->withTime24($user_format);

$inputs['time_span'] = $field_factory->duration($this->lng->txt('rep_time_period'))
->withTimezone($this->activeUser->getTimeZone())
->withFormat($format)
->withUseTime(true)
->withRequired(true);
$inputs['activation_visibility'] = $field_factory->checkbox(
Expand Down
2 changes: 0 additions & 2 deletions Modules/Test/classes/MainSettings/ilObjTestSettingsAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ private function getSubInputsAccessWindow(
$lng->txt('tst_starting_time'),
$lng->txt('tst_starting_time_desc')
)->withTimezone($environment['user_time_zone'])
->withFormat($environment['user_date_format'])
->withUseTime(true);
if ($this->getStartTime() !== null) {
$sub_inputs_access_window['start_time'] = $sub_inputs_access_window['start_time']
Expand All @@ -127,7 +126,6 @@ private function getSubInputsAccessWindow(
$lng->txt('tst_ending_time'),
$lng->txt('tst_ending_time_desc')
)->withTimezone($environment['user_time_zone'])
->withFormat($environment['user_date_format'])
->withUseTime(true);
if ($this->getEndTime() !== null) {
$sub_inputs_access_window['end_time'] = $sub_inputs_access_window['end_time']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ function ($v) {
[
$f->dateTime($lng->txt('tst_reporting_date'), "")
->withTimezone($environment['user_time_zone'])
->withFormat($environment['user_date_format'])
->withValue(
$this->getReportingDate()?->setTimezone(
new DateTimeZone($environment['user_time_zone'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,6 @@ private function buildForm(): Form


$environment = [];
$environment['user_date_format'] = (new \ILIAS\Data\Factory())->dateFormat()->withTime24(
$this->active_user->getDateFormat()
);
$environment['user_time_zone'] = $this->active_user->getTimeZone();

$anonymity_flag = (bool) $this->test_object->getAnonymity();
Expand Down
5 changes: 1 addition & 4 deletions Modules/Test/test/ScoreSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,7 @@ public function testScoreSettingsSectionSummary(): void
$s = new ilObjTestSettingsResultSummary(666);
$actual = $this->getDefaultRenderer()->render(
$s->toForm(...array_merge($ui, [[
'user_time_zone' => 'Europe/Berlin',
'user_date_format' => $data_factory->dateFormat()->withTime24(
$data_factory->dateFormat()->standard()
)
'user_time_zone' => 'Europe/Berlin'
]]))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ public function getHTML(): string
public function initForm(): void
{
$field = $this->ui->input()->field();
$custom_trafo = fn (callable $c): Transformation => $this->refinery->custom()->transformation($c);
$custom_constraint = fn (callable $c, string $error): Transformation => $this->refinery->custom()->constraint(
$custom_trafo = fn(callable $c): Transformation => $this->refinery->custom()->transformation($c);
$custom_constraint = fn(callable $c, string $error): Transformation => $this->refinery->custom()->constraint(
$c,
$error
);
Expand Down Expand Up @@ -148,7 +148,6 @@ public function initForm(): void

$display_date_start = $field->dateTime($this->txt(self::F_DISPLAY_DATE_START))
->withUseTime(true)
->withFormat($format)
->withValue($this->notification->getDisplayStart()->format($str))
->withAdditionalTransformation(
$custom_trafo(function (?DateTimeImmutable $v): ?\DateTimeImmutable {
Expand All @@ -158,7 +157,6 @@ public function initForm(): void
);
$display_date_end = $field->dateTime($this->txt(self::F_DISPLAY_DATE_END))
->withUseTime(true)
->withFormat($format)
->withValue($this->notification->getDisplayEnd()->format($str))
->withAdditionalTransformation(
$custom_trafo(function (?DateTimeImmutable $v): ?\DateTimeImmutable {
Expand All @@ -168,7 +166,6 @@ public function initForm(): void
);
$event_date_start = $field->dateTime($this->txt(self::F_EVENT_DATE_START))
->withUseTime(true)
->withFormat($format)
->withValue($this->notification->getEventStart()->format($str))
->withAdditionalTransformation(
$custom_trafo(function (?DateTimeImmutable $v): ?\DateTimeImmutable {
Expand All @@ -178,7 +175,6 @@ public function initForm(): void
);
$event_date_end = $field->dateTime($this->txt(self::F_EVENT_DATE_END))
->withUseTime(true)
->withFormat($format)
->withValue($this->notification->getEventEnd()->format($str))
->withAdditionalTransformation(
$custom_trafo(function (?DateTimeImmutable $v): ?\DateTimeImmutable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ protected function rawInput(
$dh = $this->data_helper;
return $this->ui_factory
->dateTime('placeholder')
->withFormat($this->presenter->utilities()->getUserDateFormat())
->withAdditionalTransformation(
$this->refinery->custom()->transformation(
function ($v) use ($dh) {
Expand Down
21 changes: 1 addition & 20 deletions Services/Repository/Service/Form/class.FormAdapterGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,28 +260,9 @@ public function date(
): self {
$field = $this->ui->factory()->input()->field()->dateTime($title, $description);

$format = $this->user->getDateFormat();
$dt_format = (string) $format;
/*
switch ((int) $this->user->getDateFormat()) {
case \ilCalendarSettings::DATE_FORMAT_DMY:
$format = $this->data->dateFormat()->germanShort();
$dt_format = "d.m.Y";
break;
case \ilCalendarSettings::DATE_FORMAT_MDY:
$format = $this->data->dateFormat()->custom()->month()->slash()->day()->slash()->year();
$dt_format = "m/d/Y";
break;
default:
$format = $this->data->dateFormat()->standard();
$dt_format = "Y-m-d";
break;
}*/

$field = $field->withFormat($format);
if (!is_null($value)) {
$field = $field->withValue(
(new \DateTime($value->get(IL_CAL_DATE)))->format($dt_format)
(new \DateTime($value->get(IL_CAL_DATE)))->format("Y-m-d")
);
}
$this->addField($key, $field);
Expand Down
10 changes: 0 additions & 10 deletions src/UI/Component/Input/Field/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@
*/
interface DateTime extends FormInput
{
/**
* Get an input like this using the given format.
*/
public function withFormat(DateFormat $format): self;

/**
* Get the date-format of this input.
*/
public function getFormat(): DateFormat;

/**
* Get an input like this using the given timezone.
*/
Expand Down
10 changes: 0 additions & 10 deletions src/UI/Component/Input/Field/Duration.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@
*/
interface Duration extends Group
{
/**
* Get an input like this using the given format.
*/
public function withFormat(DateFormat $format): Duration;

/**
* Get the date-format of this input.
*/
public function getFormat(): DateFormat;

/**
* Limit accepted values to Duration past (and including) the given $Duration.
*/
Expand Down
14 changes: 0 additions & 14 deletions src/UI/Implementation/Component/Input/Field/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class DateTime extends FormInput implements C\Input\Field\DateTime

public const TIME_FORMAT = 'HH:mm';

protected DateFormat $format;
protected ?DateTimeImmutable $min_date = null;
protected ?DateTimeImmutable $max_date = null;
protected bool $with_time = false;
Expand Down Expand Up @@ -94,19 +93,6 @@ public function withValue($value): self
return parent::withValue($value);
}

public function withFormat(DateFormat $format): self
{
$clone = clone $this;
$clone->format = $format;
return $clone;
}

public function getFormat(): DateFormat
{
return $this->format;
}


public function withTimezone(string $tz): self
{
$timezone_trafo = $this->refinery->dateTime()->changeTimezone($tz);
Expand Down
Loading

0 comments on commit 8fb561e

Please sign in to comment.