Skip to content

Commit

Permalink
Merge pull request #2653 from Axum25/master
Browse files Browse the repository at this point in the history
Added: 'Day, Month Day, Year' as a predefined date format
  • Loading branch information
kylekatarnls authored Aug 16, 2022
2 parents bdf4f4f + 020d5d8 commit 1dd341d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Carbon/Traits/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,21 @@ 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

0 comments on commit 1dd341d

Please sign in to comment.