summaryrefslogtreecommitdiff
path: root/app/Elements
diff options
context:
space:
mode:
Diffstat (limited to 'app/Elements')
-rw-r--r--app/Elements/ChangeDate.php19
-rw-r--r--app/Elements/DateValue.php15
-rw-r--r--app/Elements/DateValueExact.php38
-rw-r--r--app/Elements/DateValueToday.php50
-rw-r--r--app/Elements/TimeValue.php2
-rw-r--r--app/Elements/TimeValueNow.php42
-rw-r--r--app/Elements/TransmissionDate.php5
7 files changed, 150 insertions, 21 deletions
diff --git a/app/Elements/ChangeDate.php b/app/Elements/ChangeDate.php
index eab1bf790f..2aff62d875 100644
--- a/app/Elements/ChangeDate.php
+++ b/app/Elements/ChangeDate.php
@@ -27,26 +27,9 @@ use Fisharebest\Webtrees\Tree;
* <DATE_EXACT>
* The date that this data was changed.
*/
-class ChangeDate extends AbstractElement
+class ChangeDate extends DateValueToday
{
protected const SUBTAGS = [
'TIME' => '1:1',
];
-
- /**
- * Display the value of this type of element.
- *
- * @param string $value
- * @param Tree $tree
- *
- * @return string
- */
- public function value(string $value, Tree $tree): string
- {
- $canonical = $this->canonical($value);
-
- $date = new Date($canonical);
-
- return $date->display();
- }
}
diff --git a/app/Elements/DateValue.php b/app/Elements/DateValue.php
index 4bd15abae7..f0c103b4f0 100644
--- a/app/Elements/DateValue.php
+++ b/app/Elements/DateValue.php
@@ -20,6 +20,7 @@ declare(strict_types=1);
namespace Fisharebest\Webtrees\Elements;
use Fisharebest\Webtrees\Date;
+use Fisharebest\Webtrees\Html;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Services\LocalizationService;
use Fisharebest\Webtrees\Tree;
@@ -62,9 +63,21 @@ class DateValue extends AbstractElement
$dmy = $localization_service->dateFormatToOrder(I18N::dateFormat());
+ $attributes = [
+ 'class' => 'form-control',
+ 'dir' => 'ltr',
+ 'type' => 'text',
+ 'id' => $id,
+ 'name' => $name,
+ 'value' => $value,
+ 'onchange' => 'webtrees.reformatDate(this, \'' . e($dmy) . '\')',
+ 'maxlength' => static::MAXIMUM_LENGTH,
+ 'pattern' => static::PATTERN,
+ ];
+
return
'<div class="input-group">' .
- '<input class="form-control" type="text" id="' . $id . '" name="' . $name . '" value="' . e($value) . '" onchange="webtrees.reformatDate(this, \'' . e($dmy) . '\')" dir="ltr" />' .
+ '<input ' . Html::attributes($attributes) . ' />' .
view('edit/input-addon-calendar', ['id' => $id]) .
view('edit/input-addon-help', ['topic' => 'DATE']) .
'</div>' .
diff --git a/app/Elements/DateValueExact.php b/app/Elements/DateValueExact.php
new file mode 100644
index 0000000000..8d1b466d85
--- /dev/null
+++ b/app/Elements/DateValueExact.php
@@ -0,0 +1,38 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2022 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Elements;
+
+use Fisharebest\Webtrees\Date;
+use Fisharebest\Webtrees\I18N;
+use Fisharebest\Webtrees\Services\LocalizationService;
+use Fisharebest\Webtrees\Tree;
+
+use function app;
+use function e;
+use function preg_replace_callback;
+use function view;
+
+/**
+ * DATE_VALUE := {Size=1:35}
+ */
+class DateValueExact extends DateValue
+{
+ protected const PATTERN = '(0[1-9]|[12][0-9]|3[0-1]) (JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC) [0-9][0-9][0-9][0-9]';
+}
diff --git a/app/Elements/DateValueToday.php b/app/Elements/DateValueToday.php
new file mode 100644
index 0000000000..26743d32ae
--- /dev/null
+++ b/app/Elements/DateValueToday.php
@@ -0,0 +1,50 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2022 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Elements;
+
+use Fisharebest\Webtrees\Date;
+use Fisharebest\Webtrees\I18N;
+use Fisharebest\Webtrees\Services\LocalizationService;
+use Fisharebest\Webtrees\Tree;
+
+use function app;
+use function date;
+use function e;
+use function preg_replace_callback;
+use function strtoupper;
+use function view;
+
+/**
+ * DATE_VALUE := {Size=1:35}
+ */
+class DateValueToday extends DateValueExact
+{
+ /**
+ * Create a default value for this element.
+ *
+ * @param Tree $tree
+ *
+ * @return string
+ */
+ public function default(Tree $tree): string
+ {
+ return strtoupper(date('d M Y'));
+ }
+}
diff --git a/app/Elements/TimeValue.php b/app/Elements/TimeValue.php
index 9bfe262f64..befac9677c 100644
--- a/app/Elements/TimeValue.php
+++ b/app/Elements/TimeValue.php
@@ -30,5 +30,5 @@ namespace Fisharebest\Webtrees\Elements;
*/
class TimeValue extends AbstractElement
{
- protected const PATTERN = '([01][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?';
+ protected const PATTERN = '([01][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9]([.][0-9]+)?)?';
}
diff --git a/app/Elements/TimeValueNow.php b/app/Elements/TimeValueNow.php
new file mode 100644
index 0000000000..45ef3b8ab2
--- /dev/null
+++ b/app/Elements/TimeValueNow.php
@@ -0,0 +1,42 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2022 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Elements;
+
+use Fisharebest\Webtrees\Tree;
+
+use function date;
+
+/**
+ * TIME_VALUE := {Size=1:12}
+ */
+class TimeValueNow extends TimeValue
+{
+ /**
+ * Create a default value for this element.
+ *
+ * @param Tree $tree
+ *
+ * @return string
+ */
+ public function default(Tree $tree): string
+ {
+ return date('H:i:s');
+ }
+}
diff --git a/app/Elements/TransmissionDate.php b/app/Elements/TransmissionDate.php
index cc96157ae8..b5eae24e6a 100644
--- a/app/Elements/TransmissionDate.php
+++ b/app/Elements/TransmissionDate.php
@@ -24,6 +24,9 @@ namespace Fisharebest\Webtrees\Elements;
* <DATE_EXACT>
* The date that this transmission was created.
*/
-class TransmissionDate extends AbstractElement
+class TransmissionDate extends DateValueToday
{
+ protected const SUBTAGS = [
+ 'TIME' => '1:1',
+ ];
}