定制 openpsa/ranger 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

openpsa/ranger

最新稳定版本:v0.6.0

Composer 安装命令:

composer require openpsa/ranger

包简介

Formatter for date and time ranges with i18n support

README 文档

README

Ranger is a formatter for date and time ranges, based (somewhat loosely) on Adam Shaw's formatRange algorithm in fullCalendar.

Some Examples

<?php
use OpenPsa\Ranger\Ranger;

$ranger = new Ranger('en');
echo $ranger->format('2013-10-05', '2013-10-20');
// Oct 5–20, 2013
echo $ranger->format('2013-10-05', '2013-11-20');
// Oct 5 – Nov 20, 2013

$ranger = new Ranger('en_GB');
echo $ranger->format('2013-10-05', '2013-10-20');
// 5–20 Oct 2013
echo $ranger->format('2013-10-05', '2013-11-20');
// 5 Oct – 20 Nov 2013

$ranger = new Ranger('de');
echo $ranger->format('2013-10-05', '2013-10-20');
// 05.–20.10.2013
echo $ranger->format('2013-10-05', '2013-11-20');
// 05.10.–20.11.2013

Usage

To use Ranger, you will need to have the php-intl extension installed. If the you only need it to work in the "en" locale, you can alternatively require symfony/intl in your composer.json.

Instantiate ranger with the name of your locale as the parameter. You can also pass null to use the ini.default_locale setting. Afterwards, you can call format() with two date parameters. Accepted types are

  • DateTime objects
  • strings (any format that DateTime can read)
  • Unix timestamps
  • null (which means current date).

Output Customization

<?php
use OpenPsa\Ranger\Ranger;
use IntlDateFormatter;

$ranger = new Ranger('en');
$ranger
    ->setRangeSeparator(' and ')
    ->setDateTimeSeparator(', between ')
    ->setDateType(IntlDateFormatter::LONG)
    ->setTimeType(IntlDateFormatter::SHORT);

echo $ranger->format('2013-10-05 10:00:01', '2013-10-05 13:30:00');
// October 5, 2013, between 10:00 AM and 1:30 PM

统计信息

  • 总下载量: 168.2k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 76
  • 点击次数: 2
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 76
  • Watchers: 2
  • Forks: 16
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-03-09