承接 deviantintegral/null-date-time 相关项目开发

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

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

deviantintegral/null-date-time

最新稳定版本:v1.1.0

Composer 安装命令:

composer require deviantintegral/null-date-time

包简介

Interfaces and classes supporting empty or null DateTime objects

README 文档

README

CI Packagist Downloads

composer require deviantintegral/null-date-time

This package provides classes that decorate \DateTime so that it is always formattable as a string, even if the time is empty or null.

PHP's \DateTime object does not have any way to represent an "empty" date. While there is a \DateTimeInterface class, it's documentation explicitly says it is not for implementation but type hinting only.

We don't want calling code to have to check for null returns on every get call. DateTimeFormatInterface requires that format() return an empty string if the underlying date is not set.

When constructing a DateTime object, a common pattern would be:

<?php

function createTime(string $time = null): \Deviantintegral\NullDateTime\DateTimeFormatInterface
{
  if (null === $time || '' === $time) {
    return new \Deviantintegral\NullDateTime\NullDateTime();
  }

  return \Deviantintegral\NullDateTime\ConcreteDateTime::fromString($time);
}

$dateTime = createTime('now');
$dateTime->format('U'); // Will return the current Unix timestamp.
if ($dateTime instanceof \Deviantintegral\NullDateTime\ConcreteDateTimeInterface) {
  $dateTime->getDateTime()->getOffset(); // Call any of the usual \DateTime methods.
}

$dateTime = createTime('');
$dateTime->format('U'); // Will return an empty string.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 未知

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固