New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

gtmassey/period

Create date ranges and periods of time with ease.
75,716
Install
composer require gtmassey/period
Latest Version:v1.3.1
PHP:^8.1|^8.2|^8.3
Laravel:10 · 11
Older releases:9
License:MIT
Last Updated:May 28, 2025
Links: GitHub  ·  Packagist
Maintainer: gtmassey

Period

Latest Version on Packagist Total Downloads Tests

Create date ranges and periods of time with ease.

Installation

You can install the package via composer:

composer require gtmassey/period

Usage

All instances of Period take in Carbon instances for the startDate and endDate.

You can define a period by passing a start and end date to the static create method:


$customPeriod = Period::create(Carbon::now()->subDays(3), Carbon::now());

You can also use one of the many methods provided for you to generate pre-defined periods of time:


//days
Period::today();
Period::yesterday();
Period::lastDays(int $days); //$days = 2
Period::lastDaysExcludingToday(int $days); //$days = 2

//weeks
Period::thisWeek();
Period::thisWeekExcludingToday();
Period::lastWeek();
Period::lastWeeks(int $weeks);

//months
Period::thisMonth();
Period::thisMonthExcludingToday();
Period::lastMonth();
Period::lastMonths(int $months);

//quarters (3 months)
Period::thisQuarter();
Period::thisQuarterExcludingToday();
Period::lastQuarter();
Period::lastQuarters(int $quarters);

//years
Period::thisYear();
Period::thisYearExcludingToday();
Period::lastYear();
Period::lastYears(int $years);

Testing

composer test

Changelog

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

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

This package was extracted from gtmassey/laravel-analytics. A special thanks goes to Plytas for their help in creating the original package this code is extracted from.

Thank you to the team at Spatie for their awesome packages and inspiration. Their laravel-analytics package was the inspiration for this project and the analytics project.

License

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

Related Packages

spatie/period

Complex period comparisons

5,351,755 1,703
doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

648,266,899 9,701
laravel/framework

The Laravel Framework.

604,216,237 34,982
laravel/tinker

Powerful REPL for the Laravel framework.

512,508,631 7,443
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

429,221,767 607

Version History

Version Released PHP Laravel License
v1.3.1 ^8.1|^8.2|^8.3 ^10.0|^11.0 MIT
v1.3.0 ^8.2|^8.3 ^10.0|^11.0 MIT
v1.2.0 ^8.1 ^9.0|^10.0|^11.0 MIT
v1.1.0 ^8.1 ^9.0|^10.0 MIT
v1.0.0 ^8.1 ^9.0 MIT