Giter Site home page Giter Site logo

time-helpers's Introduction

Time Helpers

Packagist PHP support Latest Version on Packagist Build Status Scrutinizer Code Quality StyleCI Total Downloads

PHP time utilities for converting time values & creating time periods

Installation

You can install the package via composer:

composer require sfneal/time-helpers

Usage

Carbonate

Carbonate can be used to retrieve Carbon objects transformed from today's datetime. This is useful for getting a Carbon object that represents a datetime in the past or future.

use Sfneal\Helpers\Time\Carbonate;

// Retrieve a Carbon\Carbon object representing '3' days ago
$threeDaysAgo = Carbonate::daysAgo(3);
$threeDaysAgo = Carbonate::days(-3);

// Retrieve a Carbon\Carbon object representing '5' years ago
$fiveYearsAgo = Carbonate::yearsAgo(3);
$fiveYearsAgo = Carbonate::years(-3);

// Retrieve a Carbon\Carbon object representing '6' months ago
$sixMonthsAgo = Carbonate::monthsAgo(3);
$sixMonthsAgo = Carbonate::months(-3);

TimeConverter

TimeConverter is used to convert between different units of time (hours, minutes & seconds).

use Sfneal\Helpers\Time\TimeConverter;

// Convert Hours to Minutes
$hours = 5.5;
$minutes = (new TimeConverter())->setHours($hours)->minutes();
>>> 19800


// Convert Seconds to Hours
$seconds = 37800;
$hours = (new TimeConverter())->setSeconds($hours)->hours();
>>> 10.5

TimePeriod

TimePeriod is used to retrieve a start & end datetime for a period of time (like today, last month, etc). This can be useful when creating time scoped queries, like collecting all the orders from last month.

use Sfneal\Helpers\Time\TimePeriod;

// Retrieve a TimePeriod representing today (02/16/2021)
[$start, $end] = TimePeriods::today();
// $start >>> 2021-02-16 00:00:00
// $end >>> 2021-02-16 23:59:59

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

PHP Package Boilerplate

This package was generated using the PHP Package Boilerplate.

time-helpers's People

Contributors

sfneal avatar

Watchers

 avatar

time-helpers's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.