2017 © Pedro Peláez
 

library wpdatetime

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

image

rarst/wpdatetime

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

  • Friday, March 16, 2018
  • by Rarst
  • Repository
  • 5 Watchers
  • 38 Stars
  • 900 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 38 % Grown

The README.md

WpDateTime — DateTime extension for WordPress

WpDateTime is an extension of PHP’s DateTime and DateTimeZone classes for WordPress context., (*1)

It makes it easy to instance time objects from WordPress posts and produce localized output with correct format and time zone handling., (*2)

Retired

The project is retired in favor of native WordPress 5.3+ functions:, (*3)

Installation

Require as Composer package in your project:, (*4)

composer require rarst/wpdatetime

Usage

WpDateTime and WpDateTimeImmutable

Classes extend DateTime and DateTimeImmutable respectively and retain their full functionality., (*5)

You can use shared WpDateTimeInterface to hint for both., (*6)

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., (*7)

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)., (*8)

composer install
phpunit

License

MIT, (*9)

The Versions

16/03 2018

dev-master

9999999-dev

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

  Sources   Download

MIT

The Requires

  • php >=5.5.10

 

The Development Requires

wordpress date time timezone

16/03 2018

0.3

0.3.0.0

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

  Sources   Download

MIT

The Requires

  • php >=5.5.10

 

The Development Requires

wordpress date time timezone

01/02 2018

0.2.2

0.2.2.0

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

  Sources   Download

MIT

The Requires

  • php >=5.5.10

 

The Development Requires

wordpress date time timezone

28/12 2017

0.2.1

0.2.1.0

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

  Sources   Download

MIT

The Requires

  • php >=5.5.10

 

The Development Requires

wordpress date time timezone

06/11 2017

0.2

0.2.0.0

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

  Sources   Download

MIT

The Development Requires

wordpress date time timezone

15/11 2016

0.1

0.1.0.0

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

  Sources   Download

MIT

The Development Requires