shafayat/date-formatter
最新稳定版本:v1.0.0
Composer 安装命令:
composer require shafayat/date-formatter
包简介
A custom Laravel package for formatting dates.
README 文档
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.
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-06