-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
81 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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() ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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() ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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() ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
*/ | ||
|
@@ -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() ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
*/ | ||
|