All Projects → Rarst → Wpdatetime

Rarst / Wpdatetime

Licence: mit
Extension of PHP’s DateTime and DateTimeZone classes for WordPress context.

Projects that are alternatives of or similar to Wpdatetime

Argon Theme
📖 Argon - 一个轻盈、简洁的 WordPress 主题
Stars: ✭ 1,104 (+1572.73%)
Mutual labels:  wordpress
Wprig
A progressive theme development rig for WordPress.
Stars: ✭ 1,125 (+1604.55%)
Mutual labels:  wordpress
Wordpress Base Plugin
A starter template for WordPress plugins, with autoloading, namespaces and object caching (where available).
Stars: ✭ 65 (-1.52%)
Mutual labels:  wordpress
Advanced Forms
WordPress plugin to create forms using Advanced Custom Fields
Stars: ✭ 61 (-7.58%)
Mutual labels:  wordpress
Free Genesis Themes
A collection of free, do-whatever-you-want Genesis child themes.
Stars: ✭ 63 (-4.55%)
Mutual labels:  wordpress
Rnmaterial
Make Fun with RnMaterial on WordPress.
Stars: ✭ 64 (-3.03%)
Mutual labels:  wordpress
Theme My Login
Home of the Theme My Login plugin for WordPress.
Stars: ✭ 60 (-9.09%)
Mutual labels:  wordpress
Bathe
The simplest WordPress starter theme including full setup for Sass, PostCSS, Autoprefixer, stylelint, Webpack, Eslint, imagemin, Browsersync, etc.
Stars: ✭ 65 (-1.52%)
Mutual labels:  wordpress
Plugin Wordpress
Looking for contributors! OUTDATED. WordPress plugin for jsDelivr CDN
Stars: ✭ 63 (-4.55%)
Mutual labels:  wordpress
Zeo uc
A Powerful WordPress 👶User Center 👶 | Under development
Stars: ✭ 65 (-1.52%)
Mutual labels:  wordpress
Dones
Simple team task management and tracking
Stars: ✭ 62 (-6.06%)
Mutual labels:  wordpress
Generator Kittn
The Yeoman Kittn Generator
Stars: ✭ 63 (-4.55%)
Mutual labels:  wordpress
Wordpress Progressive Web Apps
WordPress Mobile Plugin including a Progressive Web App implemented with React
Stars: ✭ 64 (-3.03%)
Mutual labels:  wordpress
When
A natural language date/time parser with pluggable rules
Stars: ✭ 1,113 (+1586.36%)
Mutual labels:  datetime
Wp Cli Fixtures
Easily generate custom fake data for WordPress
Stars: ✭ 65 (-1.52%)
Mutual labels:  wordpress
Wordpress Docker Compose
Easy Wordpress development with Docker and Docker Compose
Stars: ✭ 1,107 (+1577.27%)
Mutual labels:  wordpress
Timefhuman
Convert natural language date-like strings--dates, date ranges, and lists of dates--to Python objects
Stars: ✭ 64 (-3.03%)
Mutual labels:  datetime
Snipcart Wordpress React
Strapping React.js on a WordPress Backend: WP REST API Example
Stars: ✭ 66 (+0%)
Mutual labels:  wordpress
Dctb Links
My Personal Links
Stars: ✭ 65 (-1.52%)
Mutual labels:  wordpress
Wordpress Indieweb
Helps you establish your IndieWeb identity by extending the user profile to provide rel-me and h-card fields. It also includes a bundled installer for a core set of IndieWeb-related plugins.
Stars: ✭ 64 (-3.03%)
Mutual labels:  wordpress

WpDateTime — DateTime extension for WordPress

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:

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 to timezone_string option and falls back to gmt_offset one.

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].