-
-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement time manipulation on date now * Add link to regex for checks * Use Carbon:parse function to convert datetime to carbon to prevent all missing usecases * Update code examples * Change tests to check for parse static call * Add today as method call and fix tests * Change the tests to parse method * Update function return types * Rewrite Carbon Call Factory to combine regex and fallback to parse * Add tests for tomorrow and yesterday * Test for fallback to parse * Fix correct strings utils * Create const for regex * Fallback if unit or operator not set * Add text for date manipulation * Remove month test this is combined * Change classname * Fix most of possible cases for carbon * Fix some static errors * When set time always add all args * Use correct var for identifier name * Add method call for set date * Add some extra tests * Fix tests * Correct test with time * do correct time checks * Make sure property exists * Change checks * Refactor use of reference * Rebuild the carboncall * Check correct instances * Check size of callstack * Check correct instance * Add count check * change check for rebuild * Skip checks * Check for empty callstack * Move rebuild to separate function * Fix time when set to 00:00 * Add full datetime method * Add test for full date * Add change to config * remove setDate & setTime functions * Add test for date where no string args * Configure rule config for test * Revert classname changes * Update config/set/datetime-to-carbon.php Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com> --------- Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
- Loading branch information
1 parent
97653a9
commit 71ae13a
Showing
8 changed files
with
255 additions
and
131 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
...ts/Carbon/Rector/New_/DateTimeInstanceToCarbonRector/Fixture/datetime_now_add_sub.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture; | ||
|
||
final class DateTimeNowAddSub | ||
{ | ||
public function run() | ||
{ | ||
$addSeconds = new \DateTime('+5 seconds'); | ||
$addMinutes = new \DateTime('+5 minutes'); | ||
$addHours = new \DateTime('+5 hours'); | ||
$addDays = new \DateTime('+5 days'); | ||
$addWeeks = new \DateTime('+5 weeks'); | ||
$addMonths = new \DateTime('+5 months'); | ||
$addYears = new \DateTime('+5 years'); | ||
|
||
$subSeconds = new \DateTime('-5 seconds'); | ||
$subMinuts = new \DateTime('-5 minutes'); | ||
$subHours = new \DateTime('-5 hours'); | ||
$subDays = new \DateTime('-5 days'); | ||
$subWeeks = new \DateTime('-5 weeks'); | ||
$subMonths = new \DateTime('-5 months'); | ||
$subYears = new \DateTime('-5 years'); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture; | ||
|
||
final class DateTimeNowAddSub | ||
{ | ||
public function run() | ||
{ | ||
$addSeconds = \Carbon\Carbon::now()->addSeconds(5); | ||
$addMinutes = \Carbon\Carbon::now()->addMinutes(5); | ||
$addHours = \Carbon\Carbon::now()->addHours(5); | ||
$addDays = \Carbon\Carbon::now()->addDays(5); | ||
$addWeeks = \Carbon\Carbon::now()->addWeeks(5); | ||
$addMonths = \Carbon\Carbon::now()->addMonths(5); | ||
$addYears = \Carbon\Carbon::now()->addYears(5); | ||
|
||
$subSeconds = \Carbon\Carbon::now()->subSeconds(5); | ||
$subMinuts = \Carbon\Carbon::now()->subMinutes(5); | ||
$subHours = \Carbon\Carbon::now()->subHours(5); | ||
$subDays = \Carbon\Carbon::now()->subDays(5); | ||
$subWeeks = \Carbon\Carbon::now()->subWeeks(5); | ||
$subMonths = \Carbon\Carbon::now()->subMonths(5); | ||
$subYears = \Carbon\Carbon::now()->subYears(5); | ||
} | ||
} | ||
|
||
?> |
31 changes: 31 additions & 0 deletions
31
rules-tests/Carbon/Rector/New_/DateTimeInstanceToCarbonRector/Fixture/datetime_parse.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture; | ||
|
||
final class DateTimeParse | ||
{ | ||
public function run() | ||
{ | ||
$date = new \DateTime('next week'); | ||
$exactDate = new \DateTime('2024-07-25'); | ||
$textualDate = new \DateTime('2 days ago'); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture; | ||
|
||
final class DateTimeParse | ||
{ | ||
public function run() | ||
{ | ||
$date = \Carbon\Carbon::parse('next week'); | ||
$exactDate = \Carbon\Carbon::parse('2024-07-25'); | ||
$textualDate = \Carbon\Carbon::parse('2 days ago'); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...Carbon/Rector/New_/DateTimeInstanceToCarbonRector/Fixture/datetime_with_date_time.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture; | ||
|
||
final class DateTimeWithDateTime | ||
{ | ||
public function run() | ||
{ | ||
$date = new \DateTime('2024-07-30'); | ||
$time = new \DateTime('11:12:13'); | ||
$datetime = new \DateTime('2024-07-30 11:12:13'); | ||
|
||
$tomorrowTime = new \DateTime('tomorrow 12:00'); | ||
$yesterdayTime = new \DateTime('yesterday 12:00'); | ||
|
||
$dateNoon = new \DateTime('2024-07-30 noon'); | ||
$restStringToParse = new \DateTime('tomorrow noon'); | ||
|
||
$fullDate = new \DateTime('2024-07-30T11:12:13.000Z'); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture; | ||
|
||
final class DateTimeWithDateTime | ||
{ | ||
public function run() | ||
{ | ||
$date = \Carbon\Carbon::parse('2024-07-30'); | ||
$time = \Carbon\Carbon::parse('11:12:13'); | ||
$datetime = \Carbon\Carbon::parse('2024-07-30 11:12:13'); | ||
|
||
$tomorrowTime = \Carbon\Carbon::parse('12:00 tomorrow'); | ||
$yesterdayTime = \Carbon\Carbon::parse('12:00 yesterday'); | ||
|
||
$dateNoon = \Carbon\Carbon::parse('2024-07-30 noon'); | ||
$restStringToParse = \Carbon\Carbon::parse('noon tomorrow'); | ||
|
||
$fullDate = \Carbon\Carbon::parse('2024-07-30T11:12:13.000Z'); | ||
} | ||
} | ||
|
||
?> |
39 changes: 0 additions & 39 deletions
39
...n/Rector/New_/DateTimeInstanceToCarbonRector/Fixture/datetime_with_today_sub_time.php.inc
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
...ests/Carbon/Rector/New_/DateTimeInstanceToCarbonRector/Fixture/datetime_yesterday.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture; | ||
|
||
final class DateTimeYesterday | ||
{ | ||
public function run() | ||
{ | ||
$date = new \DateTime('yesterday'); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture; | ||
|
||
final class DateTimeYesterday | ||
{ | ||
public function run() | ||
{ | ||
$date = \Carbon\Carbon::yesterday(); | ||
} | ||
} | ||
|
||
?> |
Oops, something went wrong.