time-constants

A series of constants designed to make it easier to express time in PHP applications

MIT License

Downloads
322.5K
Stars
27
Committers
2
time-constants - Version 2.0.1 Latest Release

Published by stevegrunwell 2 months ago

  • 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)
time-constants - Version 2.0.0

Published by stevegrunwell 2 months ago

⚠️ 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)
  • Move the constants from the global namespace into the TimeConstants namespace (#18)
  • 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:
    use const TimeConstants\HOUR_IN_SECONDS;
    
  2. Update references to use the constants new, fully-qualified names:
    - 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:
    "autoload": {
        "files": [
            "vendor/stevegrunwell/time-constants/src/GlobalAliases.php"
        ]
    }
    
  2. Explicitly requiring the file:
      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.

time-constants - Version 1.2.0

Published by stevegrunwell 10 months ago

  • Add the following multipliers to help with sub-second timings (#13):
    • MILLISECONDS_PER_SECOND (1,000ms/s)
    • MICROSECONDS_PER_SECOND (1,000,000µs/s)
    • NANOSECONDS_PER_SECOND (1,000,000,000ns/s)
    • PICOSECONDS_PER_SECOND (1,000,000,000,000ps/s)
  • Remove the composer.lock file, overhaul CI pipeline so tests can be run across all supported versions of PHP (#14, props @peter279k).
  • Define an archive.exclude section in composer.json (#15).
time-constants - Version 1.1.2

Published by stevegrunwell almost 3 years ago

  • Add PHP 8 support in composer.json (#9)
  • Move from Travis CI to GitHub Actions (#10)
  • Rename master to main
time-constants - Version 1.1.1

Published by stevegrunwell almost 5 years ago

  • Fixed a copy+paste error in the comment for ONE_MINUTE.
  • Add namespacing to the tests, minimum PHP version to composer.json (#5, props @peter279k).
  • Added PHP 7.4 to the Travis CI build matrix.
time-constants - Version 1.1.0

Published by stevegrunwell almost 6 years ago

  • Addition of both ONE_SECOND and ONE_MINUTE, which are both equal to 1 (#2).
  • Conform to the PSR-2 coding standards (#3).
  • Adjustments to the PHPUnit and Travis CI configuration files.
time-constants - Version 1.0.0

Published by stevegrunwell over 6 years ago

First release of the package, containing 11 constants:

Time based in seconds

  • MINUTE_IN_SECONDS (60 seconds)
  • HOUR_IN_SECONDS (3600 seconds)
  • DAY_IN_SECONDS (86,400 seconds)
  • WEEK_IN_SECONDS (604,800 seconds)
  • MONTH_IN_SECONDS (2,592,000 seconds)
  • YEAR_IN_SECONDS (31,536,000 seconds)

Time based in minutes

  • HOUR_IN_MINUTES (60 minutes)
  • DAY_IN_MINUTES (1,440 minutes)
  • WEEK_IN_MINUTES (10,080 minutes)
  • MONTH_IN_MINUTES (43,200 minutes)
  • YEAR_IN_MINUTES (525,600 minutes)