From 40a4d692b38121b09877be0d7d6d4fd9c0d734d2 Mon Sep 17 00:00:00 2001 From: mehdi hosseini Date: Wed, 8 Nov 2017 17:30:49 +0330 Subject: [PATCH] Add DateInterval week support Added DateInterval week support to the src/Config.php Also related tests added. --- src/Config.php | 4 ++-- tests/DatiumTest.php | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Config.php b/src/Config.php index ce3beff..dfb0b18 100644 --- a/src/Config.php +++ b/src/Config.php @@ -20,9 +20,9 @@ 'default_calendar' => 'gregorian', - 'date_interval' => [ 'D', 'M', 'Y', 'HT', 'MT', 'ST' ], + 'date_interval' => [ 'D', 'W','M', 'Y', 'HT', 'MT', 'ST' ], - 'date_simple' => [ 'day', ' month', ' year', ' hour', ' minute', ' second' ], + 'date_simple' => [ 'day', ' week', ' month', ' year', ' hour', ' minute', ' second' ], ]; diff --git a/tests/DatiumTest.php b/tests/DatiumTest.php index 25cc531..f450a62 100644 --- a/tests/DatiumTest.php +++ b/tests/DatiumTest.php @@ -90,6 +90,16 @@ public function testAddDateTime() Datium::create(2016, 1, 1, 0, 0, 0)->add('10 day')->get() ); + $this->assertEquals( + '2016-01-08 00:00:00', + Datium::create(2016, 1, 1, 0, 0, 0)->add('1 week')->get() + ); + + $this->assertEquals( + '2016-01-29 00:00:00', + Datium::create(2016, 1, 1, 0, 0, 0)->add('4 week')->get() + ); + $this->assertEquals( '2016-02-01 00:00:00', Datium::create(2016, 1, 1, 0, 0, 0)->add('1 month')->get() @@ -160,6 +170,16 @@ public function testSubDateTime() Datium::create(2016, 1, 11, 0, 0, 0)->sub('10 day')->get() ); + $this->assertEquals( + '2016-01-01 00:00:00', + Datium::create(2016, 1, 8, 0, 0, 0)->sub('1 week')->get() + ); + + $this->assertEquals( + '2016-01-01 00:00:00', + Datium::create(2016, 1, 15, 0, 0, 0)->sub('2 week')->get() + ); + $this->assertEquals( '2016-01-01 00:00:00', Datium::create(2016, 2, 1, 0, 0, 0)->sub('1 month')->get() @@ -206,6 +226,13 @@ public function testDateDifference() $this->assertEquals(5000, $diff->days); + $diff = Datium::diff( + Datium::now()->object(), + Datium::now()->add('1 week')->object() + ); + + $this->assertEquals(7, $diff->days); + } public function testJalaliCalendar()