承接 fahdi/php-date-format 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-31