daun/datetime-carbon-format 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

daun/datetime-carbon-format

Composer 安装命令:

composer require daun/datetime-carbon-format

包简介

Format Datetime fields as Carbon instances

README 文档

README

GitHub tag (latest by date) GitHub License

Format Datetime fields as Carbon instances.

Installation

Install the module using Composer. This will install Carbon as a child dependency.

composer require daun/datetime-carbon-format

ℹ️ Installation via the module directory will only work if you already have nesbot/carbon required from the project root.

Usage

All Datetime fields will now be formatted as Carbon instances instead of strings. Some examples of how to make use of this:

// $page->date is a Datetime field
// Output format: j/n/Y

echo $page->date;                    // 20/10/2027
echo $page->date->add('7 days');     // 27/10/2027
echo $page->date->format('l, F j');  // Monday, October 20
echo $page->date->year;              // 2027
echo $page->date->diffForHumans();   // 28 minutes ago

Consult the Carbon docs for details.

Notes

Frontend only

The ProcessWire admin expects datetime fields to be strings. That's why this module will only return Carbon instances on normal frontend page views.

Date output format

When casting a Carbon instance to a string (usually when outputting the field in a template), the field's date output format will be respected.

Empty values

Empty date fields will be wrapped in a proxy object that silently "swallows" access to properties and methods without triggering an exception. That's because Carbon instances cannot be empty, i.e. created without a valid timestamp value.

Use either the timestamp property or the isset accessor to see if a date has a value.

// Date field with data
$page->date->timestamp;    // 1778870000
$page->date->isset;        // true
$page->date->year;         // 2027
$page->date->format('j');  // 20

// Empty date field
$page->date->timestamp;    // null
$page->date->isset;        // null
$page->date->year;         // null
$page->date->format('j');  // null

carbon API Variable

The module will create a pre-configured Carbon Factory and wire it into a new carbon API variable. This factory object can be used to create new Carbon instances, edit settings on it, etc.

// Create a new Carbon instance
$datetime = wire()->carbon->createFromTimestamp($timestamp);

Contributing

Pull requests are welcome. Please read the Contributing Guidelines.

License

MIT

daun/datetime-carbon-format 适用场景与选型建议

daun/datetime-carbon-format 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 487 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 10 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「module」 「datetime」 「carbon」 「processwire」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 daun/datetime-carbon-format 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 daun/datetime-carbon-format 我们能提供哪些服务?
定制开发 / 二次开发

基于 daun/datetime-carbon-format 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-10-20