rarst/wpdatetime
最新稳定版本:0.4
Composer 安装命令:
composer require rarst/wpdatetime
包简介
Extension of PHP’s DateTime and DateTimeZone classes for WordPress context.
README 文档
README
WpDateTime is an extension of PHP’s DateTime and DateTimeZone classes for WordPress context.
It makes it easy to instance time objects from WordPress posts and produce localized output with correct format and time zone handling.
Retired
The project is retired in favor of native WordPress 5.3+ functions:
WpDateTime::createFromPost()—get_post_datetime()WpDateTime->formatI18n()—wp_date()WpDateTimeZone::getWpTimezone()—wp_timezone()
Installation
Require as Composer package in your project:
composer require rarst/wpdatetime
Usage
WpDateTime and WpDateTimeImmutable
Classes extend DateTime and DateTimeImmutable respectively and retain their full functionality.
You can use shared WpDateTimeInterface to hint for both.
Methods
WpDateTime::createFromPost()creates object instance from WP post. Time zone defaults to current WP setting.WpDateTime->formatI18n()outputs formatted and localized date in object’s time zone.WpDateTime->formatDate()outputs in current WP date format.WpDateTime->formatTime()outputs in current WP time format.
Example
use Rarst\WordPress\DateTime\WpDateTime; $date = WpDateTime::createFromPost( get_post() ); printf( 'Posted on: <time datetime="%s">%s</time>', $date->format( DATE_RFC3339 ), $date->formatDate() ); // Posted on: <time datetime="2014-11-07T15:36:31+02:00">Ноябрь 7, 2014</time>
WpDateTimeZone
Class extends DateTimeZone.
Methods
WpDateTimeZone::getWpTimezone()static method creates object instance from current WordPress settings. Defaults totimezone_stringoption and falls back togmt_offsetone.
Example
use Rarst\WordPress\DateTime\WpDateTimeZone; // Timezone string. var_dump( WpDateTimeZone::getWpTimezone()->getName() ); // string(11) "Europe/Kiev" // GMT offset. var_dump( WpDateTimeZone::getWpTimezone()->getName() ); // string(6) "+02:00"
Tests
Tests use Brain Monkey (included in dependencies) and PHPUnit 7 (not included).
composer install phpunit
License
MIT
统计信息
- 总下载量: 83.79k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 67
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-11-15