Skip to content

Commit

Permalink
Set next year when date is in past and year number is not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
onovy committed Nov 24, 2023
1 parent 36b69bb commit 8af8fb7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Gui.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,19 @@ protected function parseDate($date) {
$date = trim($date);
$dt = false;
foreach (Config::$config['gui']['date_format_in'] as $format) {
$dt = DateTime::createFromFormat($format, $date);
$dt = DateTime::createFromFormat('!' . $format, $date);
if ($dt !== false) {
$dt->modify('00.00.00');
if ($dt->format('Y') == 1970) {
$dt = DateTime::createFromFormat($format, $date);
$dt->modify('00.00.00');
$now = new DateTime('today');
$now->modify('00.00.00');
$i = $dt->diff($now);
if ($i->days > 0 && $i->invert == 0) {
$dt->modify('+1 year');
}
}

break;
}
}
Expand Down
15 changes: 15 additions & 0 deletions tests/GuiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ public function testParseDate() {
$dt->modify('+2 year');
$ret = invokeMethod($gui, 'parseDate', array('+2y'))->format('Y-m-d');
$this->assertEquals($ret, $dt->format('Y-m-d'));

$dt = new DateTime('today');
$ret = invokeMethod($gui, 'parseDate', array($dt->format('d. m.')))->format('Y-m-d');
$this->assertEquals($ret, $dt->format('Y-m-d'));

$dt = new DateTime('today');
$dt->modify('+1 day');
$ret = invokeMethod($gui, 'parseDate', array($dt->format('d. m.')))->format('Y-m-d');
$this->assertEquals($ret, $dt->format('Y-m-d'));

$dt = new DateTime('today');
$dt->modify('-1 day');
$ret = invokeMethod($gui, 'parseDate', array($dt->format('d. m.')))->format('Y-m-d');
$dt->modify('+1 year');
$this->assertEquals($ret, $dt->format('Y-m-d'));
}

public function testParseSortString() {
Expand Down

0 comments on commit 8af8fb7

Please sign in to comment.