Download the PHP package icanboogie/datetime without Composer
On this page you can find all versions of the php package icanboogie/datetime. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download icanboogie/datetime
More information about icanboogie/datetime
Files in icanboogie/datetime
Package datetime
Short Description Extends the features of PHP DateTime and DateTimeZone
License BSD-3-Clause
Homepage https://icanboogie.org/
Informations about the package datetime
DateTime
This package extends the features of PHP DateTime and DateTimeZone classes to ease the handling of times, time zones and time zone locations. Getting the UTC or local representation of a time, formatting the time to a predefined format, accessing common properties such as day, month, year, quarter and more has been made especially easy. Also, all instances can be used as strings.
Installation
Usage
Let's say that now is "2013-02-03 21:03:45" in Paris:
Empty dates are also supported:
Acknowledgements
The implementation of the Time class.
Day of week
now()
and right_now()
DateTime::now()
returns a new instance with the current local time and the local time zone. Subsequent calls return equal times, event if they are minutes apart. now actually refers to the REQUEST_TIME
or, if it is not available, to the first time the method was invoked.
On the other hand, DateTime::right_now()
returns a new instance with the real current local time and the local time zone.
The following example demonstrates the difference:
Comparing DateTime instances
DateTime Instances are compared using standard comparison operations:
To determine if an instance is between two other instances you just need two comparisons:
To determine which instance is the most recent, or the most late, simply use PHP's min()
and max()
functions:
DateTime and JSON
Starting with v1.1.0, JsonSerializable interface and are serialized into ISO-8601 strings.
Changing multiple properties
The change()
method is used to change multiple properties at once.
Note: Values exceeding ranges are added to their parent values.
Using the $cascade
parameter, setting the hour resets the minute and second to 0, and setting the minute resets the second to 0.
Creating a new instance with changed properties
The with()
method is similar to the change()
method as it is used to define multiple properties at once, the difference is that the method creates a new instance, leaving the original instance intact.
Localized formatting
Localized formatting is outside of this package scope, still a localizer can be provided to the DateTime class to localize its instances, but of course the result depends on the implementation.
The following example demonstrates how to localize instances using ICanBoogie/CLDR which uses Unicode's Common Locale Data Repository to format DateTime instances.
Continuous Integration
The project is continuously tested by GitHub actions.
Contributing
Please see CONTRIBUTING for details.
License
ICanBoogie/DateTime is released under the BSD-3-Clause.