Skip to content

Commit

Permalink
Merge branch 'release/2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed Jan 10, 2022
2 parents 9c8cd95 + 417723d commit bb3d2a0
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 65 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ This projects adheres to [Semantic Versioning](http://semver.org/) and [Keep a C
## [Unreleased][unreleased]
-

## [2.0.0] - 2022-01-10
### Added
- Added `DateTimeTrait::create_from_interface`.

### Removed
- Removed `DateTime::create_from_mutable`.
- Removed `DateTimeImmutable::create_from_mutable`.

## [1.2.2] - 2021-08-26
- Added the character `p` to the date format characters list which was added in PHP 8.

Expand Down Expand Up @@ -41,7 +49,8 @@ This projects adheres to [Semantic Versioning](http://semver.org/) and [Keep a C
## 1.0.0
- First release.

[unreleased]: https://github.com/pronamic/wp-datetime/compare/1.2.2...HEAD
[unreleased]: https://github.com/pronamic/wp-datetime/compare/2.0.0...HEAD
[2.0.0]: https://github.com/pronamic/wp-datetime/compare/1.2.2...2.0.0
[1.2.2]: https://github.com/pronamic/wp-datetime/compare/1.2.1...1.2.2
[1.2.1]: https://github.com/pronamic/wp-datetime/compare/1.2.0...1.2.1
[1.2.0]: https://github.com/pronamic/wp-datetime/compare/1.1.1...1.2.0
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ Source: https://developer.wordpress.org/reference/functions/date_i18n/#comment-2

* https://github.com/woocommerce/woocommerce/blob/3.3.5/includes/class-wc-datetime.php
* https://github.com/Rarst/wpdatetime

[![Pronamic - Work with us](https://github.com/pronamic/brand-resources/blob/main/banners/pronamic-work-with-us-leaderboard-728x90%404x.png)](https://www.pronamic.eu/contact/)
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
"phpmd/phpmd": "^2.9",
"phpunit/phpunit": "^5.7 || ^6.0",
"pronamic/wp-coding-standards": "^1.0",
"roots/wordpress": "^5.6",
"roots/wordpress": "^5.8",
"squizlabs/php_codesniffer": "^3.5",
"vlucas/phpdotenv": "^2.0",
"wp-phpunit/wp-phpunit": "^5.6"
"wp-phpunit/wp-phpunit": "^5.8",
"yoast/phpunit-polyfills": "^1.0"
},
"scripts": {
"coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-clover build/logs/clover.xml --coverage-text",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wp-datetime",
"version": "1.2.2",
"version": "2.0.0",
"description": "WordPress DateTime library.",
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions pronamic-datetime.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin URI: https://www.pronamic.eu/plugins/pronamic-datetime/
* Description: WordPress DateTime library.
*
* Version: 1.2.0
* Version: 2.0.0
* Requires at least: 4.7
*
* Author: Pronamic
Expand All @@ -18,7 +18,7 @@
* GitHub URI: https://github.com/pronamic/wp-datetime
*
* @author Pronamic <[email protected]>
* @copyright 2005-2021 Pronamic
* @copyright 2005-2022 Pronamic
* @license GPL-3.0-or-later
* @package Pronamic\WordPress\Pay
*/
Expand Down
27 changes: 1 addition & 26 deletions src/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Date time
*
* @author Pronamic <[email protected]>
* @copyright 2005-2021 Pronamic
* @copyright 2005-2022 Pronamic
* @license GPL-3.0-or-later
* @package Pronamic\WordPress\DateTime
* @see https://github.com/woocommerce/woocommerce/blob/3.3.4/includes/class-wc-datetime.php
Expand All @@ -21,29 +21,4 @@
*/
class DateTime extends \DateTime implements DateTimeInterface {
use DateTimeTrait;

/**
* Overrides upstream method to correct returned instance type to the inheriting one.
*
* {@inheritdoc}
*
* @param \DateTimeImmutable $object Object.
* @return self
*/
public static function createFromImmutable( $object ) {
return self::create_from_immutable( $object );
}

/**
* Create from immutable.
*
* @link https://www.php.net/manual/en/datetimeimmutable.createfrommutable.php
* @param \DateTimeImmutable $object The immutable DateTimeImmutable object that needs to be converted to a mutable version.
* @return self
*/
public static function create_from_immutable( \DateTimeImmutable $object ) {
$instance = new self( '@' . $object->getTimestamp() );

return $instance->setTimezone( $object->getTimezone() );
}
}
27 changes: 1 addition & 26 deletions src/DateTimeImmutable.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Date time immutable
*
* @author Pronamic <[email protected]>
* @copyright 2005-2021 Pronamic
* @copyright 2005-2022 Pronamic
* @license GPL-3.0-or-later
* @package Pronamic\WordPress\DateTime
* @see https://github.com/woocommerce/woocommerce/blob/3.3.4/includes/class-wc-datetime.php
Expand All @@ -21,29 +21,4 @@
*/
class DateTimeImmutable extends \DateTimeImmutable implements DateTimeInterface {
use DateTimeTrait;

/**
* Overrides upstream method to correct returned instance type to the inheriting one.
*
* {@inheritdoc}
*
* @param \DateTime $object Object.
* @return self
*/
public static function createFromMutable( $object ) {
return self::create_from_mutable( $object );
}

/**
* Create from mutable.
*
* @link https://www.php.net/manual/en/datetimeimmutable.createfrommutable.php
* @param \DateTime $object The mutable DateTime object that you want to convert to an immutable version.
* @return self
*/
public static function create_from_mutable( \DateTime $object ) {
$instance = new self( '@' . $object->getTimestamp() );

return $instance->setTimezone( $object->getTimezone() );
}
}
2 changes: 1 addition & 1 deletion src/DateTimeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Date time interface
*
* @author Pronamic <[email protected]>
* @copyright 2005-2021 Pronamic
* @copyright 2005-2022 Pronamic
* @license GPL-3.0-or-later
* @package Pronamic\WordPress\DateTime
* @see https://github.com/woocommerce/woocommerce/blob/3.3.4/includes/class-wc-datetime.php
Expand Down
14 changes: 13 additions & 1 deletion src/DateTimeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Date time trait
*
* @author Pronamic <[email protected]>
* @copyright 2005-2021 Pronamic
* @copyright 2005-2022 Pronamic
* @license GPL-3.0-or-later
* @package Pronamic\WordPress\DateTime
* @see https://github.com/woocommerce/woocommerce/blob/3.3.4/includes/class-wc-datetime.php
Expand Down Expand Up @@ -293,4 +293,16 @@ public static function create_from_format( $format, $time, \DateTimeZone $timezo

return $wp_date_time;
}

/**
* Create from interface.
*
* @link https://www.php.net/manual/en/datetime.createfrominterface.php
* @link https://php.watch/versions/8.0/datetime-immutable-createfrominterface
* @param \DateTimeInterface $object The mutable DateTime object that you want to convert to an immutable version.
* @return self
*/
public static function create_from_interface( \DateTimeInterface $object ) {
return new self( $object->format('Y-m-d H:i:s.u'), $object->getTimezone() );
}
}
2 changes: 1 addition & 1 deletion src/DateTimeZone.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Date time zone
*
* @author Pronamic <[email protected]>
* @copyright 2005-2021 Pronamic
* @copyright 2005-2022 Pronamic
* @license GPL-3.0-or-later
* @package Pronamic\WordPress\DateTime
* @see https://github.com/woocommerce/woocommerce/blob/3.3.4/includes/class-wc-datetime.php
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Bootstrap tests
*
* @author Pronamic <[email protected]>
* @copyright 2005-2021 Pronamic
* @copyright 2005-2022 Pronamic
* @license GPL-3.0-or-later
* @package Pronamic\WordPress\DateTime
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/phpstan/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Definitions for PHPStan.
*
* @author Pronamic <[email protected]>
* @copyright 2005-2021 Pronamic
* @copyright 2005-2022 Pronamic
* @license GPL-3.0-or-later
* @package Pronamic\WordPress\Pay
*/
Expand Down
44 changes: 43 additions & 1 deletion tests/src/DateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* DateTime
*
* @author Pronamic <[email protected]>
* @copyright 2005-2021 Pronamic
* @copyright 2005-2022 Pronamic
* @license GPL-3.0-or-later
* @package Pronamic\WordPress\DateTime
*/
Expand Down Expand Up @@ -274,4 +274,46 @@ public function test_backslash_at_end_in_translation() {

$this->assertEquals( $expected, \date_i18n( '123 - F - Y', \strtotime( $string ) ) );
}

/**
* Test create mutable from interface.
*/
public function test_create_mutable_from_interface() {
$date = new \DateTime( '2005-05-05 10:15:00', new \DateTimeZone( 'Europe/Amsterdam' ) );

$test = DateTime::create_from_interface( $date );

$this->assertInstanceOf( DateTime::class, $test );
$this->assertEquals( '2005-05-05 10:15:00', $test->format( 'Y-m-d H:i:s' ) );
$this->assertEquals( 'Europe/Amsterdam', $test->getTimezone()->getName() );

$date = new DateTime('15-07-2014 18:30:00.123456', new \DateTimeZone( 'UTC' ) );

$test = DateTime::create_from_interface( $date );

$this->assertInstanceOf( DateTime::class, $test );
$this->assertEquals( '2014-07-15 18:30:00.123456', $test->format( 'Y-m-d H:i:s.u' ) );
$this->assertEquals( 'UTC', $test->getTimezone()->getName() );
}

/**
* Test create mutable from interface.
*/
public function test_create_immutable_from_interface() {
$date = new \DateTime( '2005-05-05 10:15:00', new \DateTimeZone( 'Europe/Amsterdam' ) );

$test = DateTimeImmutable::create_from_interface( $date );

$this->assertInstanceOf( DateTimeImmutable::class, $test );
$this->assertEquals( '2005-05-05 10:15:00', $test->format( 'Y-m-d H:i:s' ) );
$this->assertEquals( 'Europe/Amsterdam', $test->getTimezone()->getName() );

$date = new DateTime('15-07-2014 18:30:00.123456', new \DateTimeZone( 'UTC' ) );

$test = DateTimeImmutable::create_from_interface( $date );

$this->assertInstanceOf( DateTimeImmutable::class, $test );
$this->assertEquals( '2014-07-15 18:30:00.123456', $test->format( 'Y-m-d H:i:s.u' ) );
$this->assertEquals( 'UTC', $test->getTimezone()->getName() );
}
}
2 changes: 1 addition & 1 deletion tests/src/DateTimeZoneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* DateTime
*
* @author Pronamic <[email protected]>
* @copyright 2005-2021 Pronamic
* @copyright 2005-2022 Pronamic
* @license GPL-3.0-or-later
* @package Pronamic\WordPress\DateTime
*/
Expand Down

0 comments on commit bb3d2a0

Please sign in to comment.