Skip to content

Commit

Permalink
Add changelog, release notes for v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
stevegrunwell committed Aug 20, 2024
1 parent 5f1c96e commit 9121a43
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
51 changes: 51 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,53 @@ 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.0] — 2024-08-20

**⚠️ Please note:** this is a **major** release, as it contains a breaking change to how the constants are defined. An extra file has been included to help bridge the gap between versions if you wish to run version 2.x of this library without updating all references across your app(s).

* Introduce a Makefile for running dev commands ([#17])
* Switch from PHP-CS-Fixer to PHP_CodeSniffer with the PHPCompatibility ruleset ([#19])
* With this change, we can run **one** version of PHPUnit in CI, using PHP_CodeSniffer to detect any backwards compatibility breaks with this (admittedly simply) library
* With only one version of PHPUnit necessary, tests have been upgraded for PHPUnit 11.x

### Breaking changes

This release moves the constants defined by this package from the global namespace into the `TimeConstants` namespace.

Your implementations of these constants can be updated in either of the following ways:

1. Explicitly import the constant(s) being used:
```php
use const TimeConstants\HOUR_IN_SECONDS;
```
2. Update references to use the constants new, fully-qualified names:
```diff
- cache($key, $value, HOUR_IN_SECONDS);
+ cache($key, $value, \TimeConstants\HOUR_IN_SECONDS);
```

#### Temporary aliases to help with migration

Alternatively, you may include the new `GlobalAliases.php` file as a short-term fix. This file will take the newly-namespaced constants and **also** define them in the global namespace.

Either of the following approaches will ensure the aliased versions are loaded:

1. (**Preferred**) Add the file to your `composer.json` file in the `autoload.files` array:
```json
"autoload": {
"files": [
"vendor/stevegrunwell/time-constants/src/GlobalAliases.php"
]
}
```
2. Explicitly requiring the file:
```diff
require_once __DIR__ . '/vendor/autoload.php';
+ require_once __DIR__ . '/vendor/stevegrunwell/time-constants/src/GlobalAliases.php';
```

Please note that this `GlobalAliases.php` file will be removed in the next **major** release (e.g. `v3.x`) of this library.

## [Version 1.2.0] — 2023-12-18

* Add the following multipliers to help with sub-second timings ([#13]):
Expand Down Expand Up @@ -51,6 +98,7 @@ Initial public release of the library, with the following constants:


[Unreleased]: https://github.com/stevegrunwell/time-constants/compare/main...develop
[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
[Version 1.1.2]: https://github.com/stevegrunwell/time-constants/releases/tag/v1.1.2
[Version 1.1.1]: https://github.com/stevegrunwell/time-constants/releases/tag/v1.1.1
Expand All @@ -64,3 +112,6 @@ Initial public release of the library, with the following constants:
[#13]: https://github.com/stevegrunwell/time-constants/pull/13
[#14]: https://github.com/stevegrunwell/time-constants/pull/14
[#15]: https://github.com/stevegrunwell/time-constants/pull/15
[#17]: https://github.com/stevegrunwell/time-constants/pull/17
[#18]: https://github.com/stevegrunwell/time-constants/pull/18
[#19]: https://github.com/stevegrunwell/time-constants/pull/19
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ cache($cacheKey, $value, 24 * 60 * 60);
Instead of spending the time figuring out what `24 * 60 * 60` means (or the fact that `86400` is meant to be one day in seconds), **Time Constants** allows you to represent the time using an easy-to-understand PHP constant:

```php
cache($cacheKey, $value, DAY_IN_SECONDS);
cache($cacheKey, $value, \TimeConstants\DAY_IN_SECONDS);
```

If the requirements changed and we needed to cache the value for multiple days, we can rewrite it as:

```php
cache($cacheKey, $value, 5 * DAY_IN_SECONDS);
cache($cacheKey, $value, 5 * \TimeConstants\DAY_IN_SECONDS);
```

These constants may seem familiar to WordPress developers, as they're absolutely [inspired by WordPress' use of time constants](https://codex.wordpress.org/Easier_Expression_of_Time_Constants). This package goes a bit further, however, adding `*_IN_MINUTES` constants, for easier use with libraries like [Laravel's `Cache` facade](https://laravel.com/docs/master/cache#cache-usage).
Expand All @@ -46,6 +46,8 @@ The package has been configured to automatically expose the `constants.php` file

This is a list of all constants defined by this package, along with their values. Each constant is wrapped in a `if (! defined(...))` conditional, ensuring these constants can easily be redefined if necessary and won't conflict with existing constants.

As of version 2.0.0 of this library, all of these constants are defined in the `TimeConstants` namespace. If you are upgrading from version 1.x, [please see the 2.0.0 release notes for notes about migration](https://github.com/stevegrunwell/time-constants/releases/tag/v2.0.0).

> Please note that these constants are defined for convenience, and not necessarily for accuracy; all months are treated as 30 days, and years as 365 days. If you need support for leap years or more advanced measures of time, you might consider [PHP's `DateTime` class](http://php.net/manual/en/book.datetime.php) or [Nesbot's Carbon package](https://carbon.nesbot.com/docs/).
### Time based in seconds
Expand Down

0 comments on commit 9121a43

Please sign in to comment.