apie/dateformat-to-regex

apie库的Composer包:日期格式转换为正则表达式

dev-main 2022-09-07 14:01 UTC

This package is auto-updated.

Last update: 2024-09-16 14:57:54 UTC


README

dateformat-to-regex

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require Code coverage

PHP Composer

此包是Apie库的一部分。代码在单仓库中维护,因此PR需要发送到单仓库

文档

此包可以将PHP日期格式字符串转换为正则表达式。目前它将创建“简单”的正则表达式,因此它将验证2月30日为一个有效日期。

用法

<?php

use Apie\DateformatToRegex\DateFormatToRegex;

$dateFormat = DateTime::ATOM;
$regularExpression = DateFormatToRegex::formatToRegex($dateFormat);
$dateString = '2020-01-28T16:22:37-07:00';

// echos 1 as the regular expression matches the date string.
var_dump(preg_match($regularExpression, $dateString));