Download the PHP package gtmassey/quarter without Composer
On this page you can find all versions of the php package gtmassey/quarter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gtmassey/quarter
More information about gtmassey/quarter
Files in gtmassey/quarter
Package quarter
Short Description Easily retrieve start and end dates for calendar quarters or fiscal quarters for any year. An extension of gtmassey/period
License MIT
Homepage https://github.com/gtmassey/quarter
Informations about the package quarter
Quarter
Retrieve start and end dates for calendar or fiscal quarters for any year with ease!
Installation
You can install the package via composer:
This package is an extension of the gtmassey/period package. You can find the documentation for that package here.
Usage
The package provides a Quarter
class which contains static methods for each quarter of a year, and additional methods that can be chained on that allow for mutations of the quarter to specific years, calendar types, and dates.
As an extension of the Period
class from gtmassey/period, the resulting Quarter object is structured the same way:
Specifying Years
If you want to specify the year of the quarter, you can chain the year()
method on the quarter. Note that you have to format the year as YYYY
. If you don't, it will take the year literally, i.e. the year 0020.
Changing the Resulting Object
By default, the Quarter
class returns a Quarter
object. You can default to the parent Period
object by calling the asPeriod()
method:
which will result in an instance of Period like so:
Changing Calendar Types
So far, the quarter methods have been assuming a calendar year for the quarter dates. If you want to use the fiscal year in which the first quarter starts on July 1, you can chain the toFiscal()
method:
You can chain the year()
and toFiscal()
methods together:
and if you want the resulting object to be an instance of the parent Period
class, you can chain the asPeriod()
method:
The toFiscal()
method creates a new Quarter
instance that is 6 months ahead of the current Quarter
.
If you wish to convert the current Quarter
instance into a fiscal representation, you can use the asFiscal()
method.
The difference between toFiscal()
and asFiscal()
is that the asFiscal()
keeps the start and end dates the same, it just changes the instance's name to be the correct representation in a fiscal calendar.
Using the asFiscal()
method preserves the start and end dates of the quarter, but changes the name
and isFiscal
properties on the object.
Start and End Dates Only
Sometimes you only need to access the start and end dates of a given quarter, without accessing the entire range. To do that, simply add the startDate()
or endDate()
method to the chain:
Past and Future Quarters:
If you have a given quarter object, and you want to get the next quarter, you can use the next()
method:
To get the previous quarters from a given Quarter object, use the previous()
method:
Finally, you can access the current quarter by calling the current()
method:
Laravel Note:
The parent Period
class is written specifically for Laravel because it is an extracted package from the gtmassey/laravel-analytics package. However, the Quarter class does not need Laravel to function. If you want to use the Quarter
class in Laravel, you can add the class to your config/app.php
aliases array:
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
To contribute, fork the repo, create a new branch, and submit a pull request. I will do my best to review them in a timely manner.
License
The MIT License (MIT). Please see License File for more information.