Download the PHP package alameda-red/datetime without Composer
On this page you can find all versions of the php package alameda-red/datetime. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alameda-red/datetime
More information about alameda-red/datetime
Files in alameda-red/datetime
Package datetime
Short Description Alameda DateTime component
License MIT
Homepage https://github.com/alameda-red/DateTime
Informations about the package datetime
Alameda DateTime component
This component provides a tool-kit to work with PHPs' Date and Time related objects.
Installation
You can either modify your composer.json with
or run:
Usage
Let's start with a warning right away: working with \DateIntervals is not trivial! There is obviously a certain extend boundary in which you can pretty much do anything. As soon as you leave the box you are on your own and there is actually no tool to help you from that point on. This component won't be able to help you either.
When you base your code on working with the values for seconds, minutes, hours and days you are on the safe-side in most cases when working in a narrow timeframe. If you use DateInterval::shorten($interval, true) be sure you understand what this value will represent. An hourly representation (2nd parameter = true) of a leap-year will yield 366 24 = 8784 hours while the year representation (2nd parameter = false default) will yield 365 24 = 8760 hours.
Divide a \DateInterval
Ever thought about splitting your \DateInterval('P1D') into two parts so you'd have \DateInterval('PT12H')? You can do that:
Create a shorter, more readable representation of \DateInterval
No idea what \DateTime('PT86400S) means? Make it more readable:
String representation of a \DateInterval
If you don't want to store your \DateInterval object in a human readable form it is probably more catchy reading 'PT24H' or 'P1D' in your database over the approach of other developers to store the value in seconds (86400):
Shorten the string by using larger time units
So \DateInterval('PT1440M') is a day, make it look like one:
Sum up \DateIntervals
Doing calculations with intervals? Struggle no more!