Skip to content

Commit

Permalink
Add DateInterval week support
Browse files Browse the repository at this point in the history
Added DateInterval week support to the src/Config.php Also related tests added.
  • Loading branch information
mehdi hosseini committed Nov 8, 2017
1 parent 8278dcc commit 40a4d69
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ],

];
27 changes: 27 additions & 0 deletions tests/DatiumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 40a4d69

Please sign in to comment.