diff --git a/CHANGELOG.md b/CHANGELOG.md index 609bddb..f11a0b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Version 2.0.2] — 2024-08-23 + +* Use the `const` keyword instead of `define()` for slight performance gains, easier readability, and better IDE interoperability. Props @ChadSikorra and @ramsey for the recommendation! ([#23]) + ## [Version 2.0.1] — 2024-08-22 * Now that constants are namespaced, remove the `defined()` checks and unnecessary multiplication in order to a) help IDEs and b) remove an (albeit tiny) level of overhead ([#21]) @@ -103,6 +107,7 @@ Initial public release of the library, with the following constants: [Unreleased]: https://github.com/stevegrunwell/time-constants/compare/main...develop +[Version 2.0.2]: https://github.com/stevegrunwell/time-constants/releases/tag/v2.0.2 [Version 2.0.1]: https://github.com/stevegrunwell/time-constants/releases/tag/v2.0.1 [Version 2.0.0]: https://github.com/stevegrunwell/time-constants/releases/tag/v2.0.0 [Version 1.2.0]: https://github.com/stevegrunwell/time-constants/releases/tag/v1.2.0 @@ -122,3 +127,4 @@ Initial public release of the library, with the following constants: [#18]: https://github.com/stevegrunwell/time-constants/pull/18 [#19]: https://github.com/stevegrunwell/time-constants/pull/19 [#21]: https://github.com/stevegrunwell/time-constants/pull/21 +[#23]: https://github.com/stevegrunwell/time-constants/pull/23 diff --git a/src/Constants.php b/src/Constants.php index 11bc018..cd7f534 100644 --- a/src/Constants.php +++ b/src/Constants.php @@ -3,7 +3,7 @@ /** * Defines useful time-based constants. * - * @package SteveGrunwell\TimeConstants + * @package TimeConstants */ declare(strict_types=1); @@ -22,37 +22,37 @@ /** * One second. */ -define(__NAMESPACE__ . '\\ONE_SECOND', 1); +const ONE_SECOND = 1; /** * One minute is 60 seconds. */ -define(__NAMESPACE__ . '\\MINUTE_IN_SECONDS', 60); +const MINUTE_IN_SECONDS = 60; /** * One hour is 60 minutes. */ -define(__NAMESPACE__ . '\\HOUR_IN_SECONDS', 3600); +const HOUR_IN_SECONDS = 3600; /** * One day is 24 hours. */ -define(__NAMESPACE__ . '\\DAY_IN_SECONDS', 86400); +const DAY_IN_SECONDS = 86400; /** * One week is 7 days. */ -define(__NAMESPACE__ . '\\WEEK_IN_SECONDS', 604800); +const WEEK_IN_SECONDS = 604800; /** * For general purposes, assume that one month is 30 days. */ -define(__NAMESPACE__ . '\\MONTH_IN_SECONDS', 2592000); +const MONTH_IN_SECONDS = 2592000; /** * For general purposes, assume that one year is 365 days. */ -define(__NAMESPACE__ . '\\YEAR_IN_SECONDS', 31536000); +const YEAR_IN_SECONDS = 31536000; /** * Time based in minutes. @@ -64,32 +64,32 @@ /** * One minute. */ -define(__NAMESPACE__ . '\\ONE_MINUTE', 1); +const ONE_MINUTE = 1; /** * One hour is 60 minutes. */ -define(__NAMESPACE__ . '\\HOUR_IN_MINUTES', 60); +const HOUR_IN_MINUTES = 60; /** * One day is 24 hours. */ -define(__NAMESPACE__ . '\\DAY_IN_MINUTES', 1440); +const DAY_IN_MINUTES = 1440; /** * One week is 7 days. */ -define(__NAMESPACE__ . '\\WEEK_IN_MINUTES', 10080); +const WEEK_IN_MINUTES = 10080; /** * For general purposes, assume that one month is 30 days. */ -define(__NAMESPACE__ . '\\MONTH_IN_MINUTES', 43200); +const MONTH_IN_MINUTES = 43200; /** * For general purposes, assume that one year is 365 days. */ -define(__NAMESPACE__ . '\\YEAR_IN_MINUTES', 525600); +const YEAR_IN_MINUTES = 525600; /** * Common multipliers. @@ -100,19 +100,19 @@ /** * A millisecond is 1/1000 of a second. */ -define(__NAMESPACE__ . '\\MILLISECONDS_PER_SECOND', 1000); +const MILLISECONDS_PER_SECOND = 1000; /** * A microsecond is one millionth of a second. */ -define(__NAMESPACE__ . '\\MICROSECONDS_PER_SECOND', 1000000); +const MICROSECONDS_PER_SECOND = 1000000; /** * A nanosecond is one billionth of a second. */ -define(__NAMESPACE__ . '\\NANOSECONDS_PER_SECOND', 1000000000); +const NANOSECONDS_PER_SECOND = 1000000000; /** * A picosecond is one trillionth of a second. */ -define(__NAMESPACE__ . '\\PICOSECONDS_PER_SECOND', 1000000000000); +const PICOSECONDS_PER_SECOND = 1000000000000; diff --git a/src/GlobalAliases.php b/src/GlobalAliases.php index be0ce06..c4a1d2d 100644 --- a/src/GlobalAliases.php +++ b/src/GlobalAliases.php @@ -9,7 +9,7 @@ * either load this file via `autoload.files` in your `composer.json` file or by requiring the file * directly in your code. * - * @package SteveGrunwell\TimeConstants + * @package TimeConstants */ declare(strict_types=1); diff --git a/tests/ConstantsTest.php b/tests/ConstantsTest.php index 4c078bc..791edad 100644 --- a/tests/ConstantsTest.php +++ b/tests/ConstantsTest.php @@ -11,7 +11,7 @@ /** * Tests the definition of time constants. * - * @package SteveGrunwell\TimeConstants + * @package TimeConstants */ class ConstantsTest extends TestCase {