shafayat / date-formatter
A custom Laravel package for formatting dates.
v1.0.0
2024-12-06 18:36 UTC
Requires
- php: >=8.0
- illuminate/support: >=10.0.0
README
You can install the package via Composer:
composer require shafayat/date-formatter
Configuration
To customize the package's default settings, publish the configuration file:
php artisan vendor:publish --tag=config
This will create a config/dateformatter.php
file where you can define your date formats:
return [ 'default_format' => 'Y-m-d', 'styles' => [ 'short' => 'm/d/Y', 'long' => 'F d, Y', 'custom' => 'd-m-Y H:i:s', ], ];
Usage
Formatting a Date
You can format dates using the format
method:
use Shafayat\DateFormatter\DateFormatter; // Format a string date echo DateFormatter::format('2024-01-01', 'short'); // Output: 01/01/2024 // Format a DateTime instance $date = new \DateTime('2024-01-01'); echo DateFormatter::format($date, 'long'); // Output: January 01, 2024
Default Format
If no style is specified, the default_format
from the configuration will be used:
echo DateFormatter::format('2024-01-01'); // Output: 2024-01-01
Testing
This package comes with unit tests. To run them, navigate to the package directory and execute:
vendor/bin/phpunit
Roadmap
- Add support for localization.
- Introduce customizable input date parsing.
- Add timezone-aware date formatting.
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a feature branch:
git checkout -b feature-name
. - Commit your changes:
git commit -m 'Add feature name'
. - Push to the branch:
git push origin feature-name
. - Create a pull request.
License
This package is open-source software licensed under the MIT License.