Giter Site home page Giter Site logo

test-time's Introduction

A helper to control the flow of time

Latest Version on Packagist run-tests Total Downloads

Carbon is an excellent library to work with time in PHP projects. The Spatie\TestTime\TestTime class contains a few functions that under the hood manipulate the time that's considered the current time by Carbon.

// the flow of time is frozen
TestTime::freeze();

// we're now one year in the future
TestTime::addYear();

// will report the real current year + 1
$year = (new Carbon())->format('Y');

Are you a visual learner?

In this video, you'll learn how we use this package to test time sensitive functionality in Mailcoach.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require spatie/test-time

Usage

You can freeze the time with:

TestTime::freeze();

Alternatively you can pass in a carbon instance that will be used as the current time.

TestTime::freeze($carbonInstance);

You can also pass a format and time.

TestTime::freeze('Y-m-d', '2019-06-12');

Progressing time

You can progress the time with any of the carbon functions starting with add or sub.

TestTime::addMinute();

TestTime::subHours(5);

// you can also chain calls
TestTime::addMonth(3)->addYear();

Unfreezing time

To let time flow naturally again, call unfreeze.

TestTime::unfreeze();

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you've found a bug regarding security please mail [email protected] instead of using the issue tracker.

Postcardware

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

We publish all received postcards on our company website.

Credits

License

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

test-time's People

Contributors

adrianmrn avatar aryehraber avatar brendt avatar freekmurze avatar matanyadaev avatar pascalbaljet avatar patinthehat avatar svenluijten avatar veneliniliev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

test-time's Issues

More methods support

First, I want to say thank you guys! So simple and helpful package!

I am using this package, and I think it's good to have these methods also:

TestTime::setHour(8); // year, month, day, hour, second, millisecond...
TestTime::hour(8); // Alias of this ^
TestTime::startOfDay(); // startOfYear, startOfMonth...

Any other suggestions?

BTW, nice implementation, you guys rock it.

make compatible to nesbot/carbon 3.x

Cloud you please make the package compatible to nesbot/carbon 3.x.
I wanted to update my symfony project to 7.0. While nesbot/carbon 3.x is now compatible to symfony 7 it would be great that spatie/test-time is compatible to nesbot/carbon 3.x so that I could update my symfony to version 7.

many thx in advance

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.