From cbe5b85dd8283dbfa4aa8d92b3ba8d3b757efb4b Mon Sep 17 00:00:00 2001 From: ShahrokhNiakan Date: Fri, 1 Sep 2017 23:04:31 +0430 Subject: [PATCH] Fix jalali day of the week return problem Fixed problem of return day of the week when used sub method to sub from date and convert it to jalali, fixed it by get current day of the week on sub method. --- src/Datium.php | 5 +++-- tests/DatiumTest.php | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Datium.php b/src/Datium.php index 6090713..84a9f22 100644 --- a/src/Datium.php +++ b/src/Datium.php @@ -160,7 +160,6 @@ public function __construct() $this->gregorian_DayofWeek = $this->date_time->format('w'); $this->convert_calendar = new Convert(); - } /** @@ -477,6 +476,8 @@ public function sub($value) new DateInterval($this->date_interval_expression) ); + $this->gregorian_DayofWeek = $this->date_time->format('w'); + return $this; } @@ -590,7 +591,7 @@ public function timestamp() public function get($format = 'Y-m-d H:i:s') { - if( $format === 'timestamp' ) { + if ($format === 'timestamp') { return $this->timestamp(); diff --git a/tests/DatiumTest.php b/tests/DatiumTest.php index 69e2aa6..4a492b4 100644 --- a/tests/DatiumTest.php +++ b/tests/DatiumTest.php @@ -252,4 +252,12 @@ public function testGregorianCalendar() $this->assertEquals('Saturday 25th June 2016 12:00:00 PM', $gregorian); } + + public function testJalaliSubDateTime() + { + $jalali = Datium::create(2017, 9, 1, 12, 0, 0)->sub('1 day')->to('jalali') + ->get('l jS F Y h:i:s'); + + $this->assertEquals("Panjshanbe 9th Shahrivar 1396 12:00:00", $jalali); + } }