├── CHANGELOG.md ├── LICENSE ├── README.md ├── composer.json ├── pint.json └── src └── Seconds.php /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | ## [Unreleased] 6 | 7 | ## [4.0.1] - 2023-05-25 8 | 9 | ### Changed 10 | 11 | - Refactor internals. 12 | 13 | ## [4.0.0] - 2022-10-03 14 | 15 | ### Removed 16 | 17 | - Drop support for PHP 7. 18 | 19 | ## [3.0.0] - 2021-10-25 20 | 21 | ### Removed 22 | 23 | - Drop support for PHP <= 7.3. 24 | - Drop support for PHPUnit 8. 25 | 26 | ## [2.1.0] - 2021-04-16 27 | 28 | ### Added 29 | 30 | - Support for PHP 8.0. 31 | 32 | ### Changed 33 | 34 | - Exception messages use correct variable names. 35 | 36 | ## [2.0.0] - 2020-04-17 37 | 38 | :boom: Breaking changes! New namespace. Run `composer dump-autoload` after update. 39 | 40 | ### Changed 41 | 42 | - Change namespace to top level `Adevade`. Use `Adevade\Seconds::class` instead of `Adevade\Seconds\Seconds::class` in ^2.0. 43 | 44 | ## [1.1.0] - 2020-04-17 45 | 46 | ### Added 47 | 48 | - Added support for PHPUnit `^8|^9`. 49 | 50 | ## [1.0.2] - 2020-02-28 51 | 52 | ### Changed 53 | 54 | - Better variable names for DocBlock helpers. 55 | 56 | ## [1.0.1] - 2020-02-08 57 | 58 | ### Added 59 | 60 | - DocBlock helpers for IDEs. 61 | 62 | ### Fixed 63 | 64 | - Throw exceptions if method does not exist or if parameter is invalid. 65 | 66 | ## [1.0.0] - 2020-02-06 67 | 68 | - Initial release 69 | 70 | [unreleased]: https://github.com/adevade/seconds/compare/4.0.1...HEAD 71 | [4.0.1]: https://github.com/adevade/seconds/compare/4.0.0...4.0.1 72 | [4.0.0]: https://github.com/adevade/seconds/compare/3.0.0...4.0.0 73 | [3.0.0]: https://github.com/adevade/seconds/compare/2.1.0...3.0.0 74 | [2.1.0]: https://github.com/adevade/seconds/compare/2.0.0...2.1.0 75 | [2.0.0]: https://github.com/adevade/seconds/compare/1.1.0...2.0.0 76 | [1.1.0]: https://github.com/adevade/seconds/compare/1.0.2...1.1.0 77 | [1.0.2]: https://github.com/adevade/seconds/compare/1.0.1...1.0.2 78 | [1.0.1]: https://github.com/adevade/seconds/compare/1.0.0...1.0.1 79 | [1.0.0]: https://github.com/adevade/seconds/releases/tag/1.0.0 80 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Andréas Lundgren 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Seconds 2 | 3 | [![Tests](https://github.com/adevade/seconds/workflows/Tests/badge.svg)](https://github.com/adevade/seconds) 4 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/adevade/seconds.svg)](https://packagist.org/packages/adevade/seconds) 5 | [![Total Downloads](https://img.shields.io/packagist/dt/adevade/seconds.svg)](https://packagist.org/packages/adevade/seconds) 6 | 7 | Helpers for converting time to seconds. 8 | 9 | ## Installation 10 | 11 | You can install the package via composer: 12 | 13 | ```bash 14 | composer require adevade/seconds 15 | ``` 16 | 17 | ### Supported PHP versions 18 | 19 | | Package | PHP | 20 | | ------- | ---------- | 21 | | ^1.0 | ^7.2 | 22 | | ^2.1 | ^7.2\|^8.0 | 23 | | ^3.0 | ^7.4\|^8.0 | 24 | | ^4.0 | ^8.0 | 25 | 26 | ## Usage 27 | 28 | ```php 29 | use Adevade\Seconds; 30 | 31 | Seconds::fromMinutes(2); // returns => (int) 120 32 | ``` 33 | 34 | ### Available methods 35 | 36 | ```php 37 | Seconds::fromMinutes($minutes = 5); 38 | Seconds::fromHours($hours = 12); 39 | Seconds::fromDays($days = 4); 40 | Seconds::fromWeeks($weeks = 2); 41 | Seconds::fromMonths($months = 6); 42 | Seconds::fromYears($years = 2); 43 | 44 | Seconds::fromMinute(); 45 | Seconds::fromHour(); 46 | Seconds::fromDay(); 47 | Seconds::fromWeek(); 48 | Seconds::fromMonth(); 49 | Seconds::fromYear(); 50 | ``` 51 | 52 | ### Available constants 53 | 54 | ```php 55 | Seconds::MINUTE; 56 | Seconds::HOUR; 57 | Seconds::DAY; 58 | Seconds::WEEK; 59 | Seconds::MONTH; 60 | Seconds::YEAR; 61 | ``` 62 | 63 | > Months have an average length of 30.42 days.\ 64 | > Years have an average length of 365.24 days. 65 | 66 | ## Credits 67 | 68 | - [Andréas Lundgren](https://github.com/adevade) 69 | 70 | Idea came from a tweet by [@LasseRafn](https://twitter.com/LasseRafn). Thanks! 71 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "adevade/seconds", 3 | "description": "Helpers for converting time to seconds.", 4 | "keywords": [ 5 | "php", 6 | "helpers", 7 | "convert", 8 | "time", 9 | "seconds" 10 | ], 11 | "homepage": "https://github.com/adevade/seconds", 12 | "license": "MIT", 13 | "type": "library", 14 | "authors": [ 15 | { 16 | "name": "Andréas Lundgren", 17 | "email": "andreas@035media.se" 18 | } 19 | ], 20 | "require": { 21 | "php": "^8.0" 22 | }, 23 | "require-dev": { 24 | "laravel/pint": "^1.2", 25 | "phpunit/phpunit": "^9.0" 26 | }, 27 | "autoload": { 28 | "psr-4": { 29 | "Adevade\\": "src" 30 | } 31 | }, 32 | "autoload-dev": { 33 | "psr-4": { 34 | "Adevade\\Seconds\\Tests\\": "tests" 35 | } 36 | }, 37 | "scripts": { 38 | "format": "vendor/bin/pint", 39 | "test": "vendor/bin/phpunit" 40 | }, 41 | "config": { 42 | "sort-packages": true 43 | }, 44 | "minimum-stability": "dev", 45 | "prefer-stable": true 46 | } 47 | -------------------------------------------------------------------------------- /pint.json: -------------------------------------------------------------------------------- 1 | { 2 | "exclude": [ 3 | "tests/" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /src/Seconds.php: -------------------------------------------------------------------------------- 1 |