Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added: 'Day, Month Day, Year' as a predefined date format #2653

Merged
merged 4 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Carbon/Traits/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ public function toFormattedDateString()
{
return $this->rawFormat('M j, Y');
}
/**
* Format the instance with the day, and a readable date
*
* @example
* ```
* echo Carbon::now()->toFormattedDayDateString();
* ```
*
* @return string
*/
public function toFormattedDayDateString(): string
{
return $this->rawFormat('D, M j, Y');
}

/**
* Format the instance as time
Expand Down
6 changes: 6 additions & 0 deletions tests/Carbon/StringsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ public function testToDayDateTimeString()
$this->assertSame('Thu, Dec 25, 1975 2:15 PM', $d->toDayDateTimeString());
}

public function testToDayDateString()
{
$d = Carbon::create(1975, 12, 25, 14, 15, 16);
$this->assertSame('Thu, Dec 25, 1975', $d->toFormattedDayDateString());
}

public function testToAtomString()
{
$d = Carbon::create(1975, 12, 25, 14, 15, 16);
Expand Down