pavlyuts / porta-datetime
PortaOne 计费 API 日期时间辅助类
0.1.2
2023-05-25 08:26 UTC
Requires
- php: ^7.2
Requires (Dev)
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2024-09-25 11:22:01 UTC
README
目的
本包旨在简化与 Portabilling API 一起工作时日期时间和数据字段的管理。
PortaDateTime 类扩展了标准的 DateTime 类以提供特定方法。API 中所有的日期时间字段都采用 MySQL 格式,并且始终使用 UTC 时区。此辅助类允许
- 从基于 UTC 的 Portaone 日期时间 API 字符串创建具有所需时区的 PortaDateTime 类。
- 为任何日期时间和任何时区创建 PortaDateTime 类,并获取计费格式的 UTC 日期时间字符串
- 还可以使用 DateTime 的任何方法
安装
在 Composer 存储中。只需添加适当的 require 部分
"require": {
"pavlyuts/porta-datetime": "^0.1"
}
依赖关系
- php: ^7.2
测试
在 php 7.2 上使用 PHPUnit 8.5 进行测试,达到 100% 的覆盖率,但这并不意味着一切都会按预期工作。
要测试,以开发模式安装并使用
composer test
命令从库根目录运行所有标准模块测试
文档
所有方法都有 PHPdoc 块,希望这足够了。
用法示例
// Typical PortaBilling API datetime string
$portaDateTime = = '2023-03-20 07:38:17';
// Create PortaDateTime from the string
$dateTime = \PortaDateTime::createFromPortaString(self::DATETIME, 'Asia/Seoul');
// Let's say we need to cancel addon product at the last second of today, local time
// First, create the object for 'now' at local timezone
$dateTime = new \PortaDateTime('now', 'Asia/Seoul');
// Get the string with 'last moment of the day' in UTC, ready to pass to the billing
$addonValidToString = $dateTime->getLastMomentString();
//Then, variable contains datetime string you may put to API call field, in UTC format.