fahdi/php-date-format
Composer 安装命令:
composer require fahdi/php-date-format
包简介
A PHP library to convert dates to words
README 文档
README
This library provides a simple and flexible way to convert dates into word representations in PHP. It handles various date formats and offers customizable output for days, months, and years.
Features
- Convert dates to word representations
- Support for multiple input date formats
- Handles special cases for days (1st, 2nd, 3rd, 21st, 22nd, etc.)
- Consistent word representation for years from 1 to 9999
- Extensive test suite to ensure accuracy
Requirements
- PHP 7.4 or higher
- ext-intl extension
Installation
You can install this package via Composer:
composer require fahdi/php-date-format
Usage
Here's a basic example of how to use the DateToWords converter:
<?php require_once 'vendor/autoload.php'; use Fahdi\PhpDateFormat\DateToWords; echo DateToWords::convert('1890-05-15'); // Output: Fifteenth of May, Eighteen ninety echo DateToWords::convert('1990-05-15'); // Output: Fifteenth of May, Nineteen ninety echo DateToWords::convert('2023-12-31'); // Output: Thirty-first of December, Twenty twenty-three echo DateToWords::convert('1800-01-01'); // Output: First of January, Eighteen hundred echo DateToWords::convert('1900-01-01'); // Output: First of January, Nineteen hundred echo DateToWords::convert('2000-02-29'); // Output: Twenty-ninth of February, Two thousand echo DateToWords::convert('2100-12-31'); // Output: Thirty-first of December, Twenty-one hundred
The convert method accepts dates in various formats:
- 'Y-m-d' (e.g., '1990-05-15')
- 'd-m-Y' (e.g., '15-05-1990')
- 'm/d/Y' (e.g., '05/15/1990')
- 'd/m/Y' (e.g., '15/05/1990')
- 'Y/m/d' (e.g., '1990/05/15')
- 'F j, Y' (e.g., 'May 15, 1990')
- 'Y.m.d' (e.g., '1990.05.15')
If an invalid date format is provided, the method will return "Invalid date format".
Running Tests
To run the tests, use the following command in your project root:
./vendor/bin/phpunit tests
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is open-sourced software licensed under the MIT license.
fahdi/php-date-format 适用场景与选型建议
fahdi/php-date-format 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 08 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 fahdi/php-date-format 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fahdi/php-date-format 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-31