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.

v1.0 2024-01-29 23:25 UTC

This package is auto-updated.

Last update: 2024-04-29 23:58:03 UTC


README

Latest Version on Packagist Tests Total Downloads

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.