gtmassey / days
An extracted class that I wrote to help with managing days of the week as string objects. It does one thing and one thing only: convert a day of the week name to an abbreviation and back.
Requires
- php: ^8.1
Requires (Dev)
- laravel/pint: ^1.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.3.2
- spatie/ray: ^1.28
README
Simple helper class for accessing the days of the week as strings in PHP.
Note from the developer:
This package is literally only one class. I will likely never update this package again. I just wanted to make a simple helper class for switching between days as names and as abbreviations in a separate project. If you have any suggestions for features or ideas, feel free to fork!
Thanks,
Garrett
Installation
You can install the package via composer:
composer require gtmassey/days
Usage
To use, you can either create a new days object with the new
keyword, or you can use the make
static method, or you can call the day of week directly as a static method:
use Gtmassey\Days\Days; $monday = new Days('Monday'); $tuesday = Days::make('Tuesday'); $wednesday = Days::Wednesday();
Once you have a Days
object, you can call the various methods to return the day of the week as a specific English formatted string:
$monday->asCharacterCode(); //'M' $monday->asShortName(); //'Mon' $sunday->asCharacterCode(); //'U' $thursday->asFullName(); //'Thursday'
The character codes use R
for Thursday to avoid confusion with Tuesday and U
for Sunday to avoid confusion with Saturday.
Testing
To run the testsuite, run the following command:
composer test
License
The MIT License (MIT). Please see License File for more information.