Download the PHP package prokki/ext-datetime without Composer
On this page you can find all versions of the php package prokki/ext-datetime. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package ext-datetime
Ext-DateTime
Extends the native datetime objects (\DateTime and \DateTimeImmutable) with a lot of additional helpful methods.
Most of the new methods are short cuts of already existing functionality. But these methods will help you to save time and code if you need to handle a many date- and time-operations.
All new methods support method chaining.
Table of Contents
- Requirements
- Integration
- Usage
- Static Initialization
- Cloning
- Manipulating
- Instant Setter Methods
Requirements
The usage of PHP v7.3 is obligatory.
Integration
Please install via composer.
Usage
The classes and instances of the classes ExtDateTime/DateTimeImmutable can be used exactly like native datetime objects/classes.
Example
Static Initialization
Similar to the native objects there are several others ways to create a datetime object.
All static methods can be used to implement method chaining.
create()
Use the static constructor create()
to use chaining immediately.
current()
The static constructor current()
returns a datetime object with the current date/time.
But in opposite to DateTime::create("now")
this method returns the object with additional microtime.
createFromObject()
Creates a new object from any datetime object implementing the DateTimeInterface.
Cloning
Two new methods add the availability to use chaining directly after cloning an object.
duplicate()
This method is just a wrapper function for clone
:
toImmutable() / toMutable()
Instead of using static constructors (DateTime::createFromImmutable or DateTimeImmutable::createFromMutable) you can also use these new non-static methods.
Manipulating
Most of the new methods are short cuts to avoid re-initialization of necessary parameter in your code.
addHours() / subHours()
Adds or subtracts hours of a datetime object.
addDays() / subHours()
Adds or subtracts days of a datetime object.
addMonth() / subMonth()
Adds or subtracts months of a datetime object.
Attention: This methods behaves differently than the suspected background function of adding days. If the current date is the last day of the month (31/30/29/28) and the target month has less days then the current month, the day will be set to the last day of the target month.
Example: The datetime object is
2017-01-30 17:00:00
and you want to add 1 month, the result will be
2017-02-28 17:00:00
Instant Setter Methods
toEndOfDay()
Sets the time to the end of the day (23:59:59).
toNoon()
Sets the time to noon (12:00:00).
toStartOfDay()
Sets the time to the start of the day (00:00:00).
toStartOfMonth()
Sets the date to the first day of the month and additionally the time to the start of the day (00:00:00).
toEndOfMonth()
Sets the date to the last day of the month and additionally the time to the end of the day (23:59:59).