org_heigl/daterange
Composer 安装命令:
composer require org_heigl/daterange
包简介
Provides a way to display dateranges
关键字:
README 文档
README
This small library tries to ease printing of date-ranges.
Installation
Installation is easy via composer. Simply type this in your terminal to add the
DateRange-Library to your composer.conf-file:
composer require org_heigl/daterange
Usage
You can then use the DateRange library by creating a DateRange-instance,
setting a format and a separator and then simply calling getDateRange()
with the start-date and the end date as parameters.
Simple example:
<?php use Org_Heigl\DateRange\DateRangeFormatter $dateRange = new DateRangeFormatter(); $dateRange->setFormat('d.m.Y'); $dateRange->setSeparator(' - '); echo $dateRange->getDateRange(new \DateTime('12.3.2015'), new \DateTime('13.4.2015')); // Will print: 12.03. - 13.04.2014 echo $dateRange->getDateRange(new \DateTime('12.3.2015'), new \DateTime('13.3.2015')); // Will print: 12. - 13.03.2014
More complex example:
<?php use Org_Heigl\DateRange\DateRangeFormatter $dateRange = new DateRangeFormatter(); $dateRange->setFormat('m/d/Y'); $dateRange->setSeparator(' - '); echo $dateRange->getDateRange(new \DateTime('12.3.2015'), new \DateTime('13.3.2015')); // Will print: 3/12/ - 3/13/2014
You want to change parts of the date-formatting string? Try the Filters.
If you want to display something like 12 - 13.03.2013 (node the missing dot after the 12)
you can use the formatting-string d.m.Y and add a RemoveEverythingAfterLastDateStringFilter
lik this:
<?php use Org_Heigl\DateRange\DateRangeFormatter; use Org_Heigl\DateRange\Filter\RemoveEverythingAfterLastDateStringFilter; $dateRange = new DateRangeFormatter(); $dateRange->setFormat('d.m.Y'); $dateRange->setSeparator(' - '); $dateRange->addFilter(new RemoveEverythingAfterLastDateStringFilter(), DateRangeFormatter::FILTER_FIRST_DIFF); echo $dateRange->getDateRange(new \DateTime('12.3.2015'), new \DateTime('13.3.2015')); // Will print: 12 - 13.03.2014
Currently the following Filters are available:
- RemoveEverythingAfterLastDateStringFilter - This filter will remove everything
after the last dateformatting-character in the given date-part. So when the
dateformatting-string reads
d.m.it will remove everything behind themwhich is the last dateformatting-character. - TrimFilter - This filter will remove excess whitespace. It just passes the dateformatting-string through the ```trim``-function.
You can implement your own filter by simply implementing the Org_Heigl\DateRange\DateRangeFilterInterface
That way evertything is possible!
You can add a filter to four different filterchains that filter different parts of the formatting string.
- DateRangeFormatter::FILTER_COMPLETE will be applied to a formatting string
when first and second day are the same. So the input will be the formatting-string
you provided via the
DateRangeFormatter::setFormat(). - DateRangeFormatter::FILTER_FIRST_DIFF will be applied to the first part of
the splitted formatting string that is used for the start-date. So when your
formatting string is
d.m.Yand the dates differ in the month the filter will be applied tod.m.for the starting date - DateRangeFormatter::FILTER_SECOND_DIFF will be applied to the first part of
the splitted formatting string that is used for the end-date. So when your
formatting-string is
d.m.Yand the dates differ in the month the filter will be applied tod.m.for the end-date - DateRangeFormatter::FILTER_SAME will be applied to the second part of the
splitted formatting string that is used for the part that is equal on start-
and end-date. So when your formatting-string is
d.m.Yand the dates differ in the day the filter will be applied tom.Y.
org_heigl/daterange 适用场景与选型建议
org_heigl/daterange 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.06k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2015 年 03 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「date」 「daterange」 「datetime」 「range」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 org_heigl/daterange 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 org_heigl/daterange 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 org_heigl/daterange 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Tools to convert between .NET and PHP date formats
Time provider, providing consistent current date, time, datetime and timezone across the request.
Php date range implementation, usualy used in PgSQL database
Adds the EDTF data type to Wikibase
Datetime helpers for timezone handling
A custom Doctine DBAL type to use PHP DateTime objects set to the system's default timezone.
统计信息
- 总下载量: 1.06k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-03-03