Download the PHP package thomas-institut/timestring without Composer
On this page you can find all versions of the php package thomas-institut/timestring. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download thomas-institut/timestring
More information about thomas-institut/timestring
Files in thomas-institut/timestring
Package timestring
Short Description A class to deal with MySQL datetime strings with microseconds
License GPL-3.0-or-later
Informations about the package timestring
thomas-institut/timestring
A TimeString is an immutable object that holds a string with the format YYYY-MM-DD HH:mm:ss.xxxxxx, that is, a
date and time with microseconds, without any timezone indication. For example '1999-12-31 23:59:50.123456'
It is the same format as MySQL's datetime(6) and PostreSQL's timestamp(6) without time zone (for CE dates)
Code has been tested with PHP 8.3, 8.4 and 8.5 at 100% coverage.
Installation
`
Usage
Constructor
TimeString objects can be constructed from strings, float or integer timestamps, or DateTime objects.
Strings given to the constructor can be partial or complete MySQL datetime values or any format accepted by PHP's DateTime class. Empty strings are not allowed.
Floats and integers are understood as Unix timestamps. An additional parameter can be given to specify the timezone:
DateTime objects are also accepted:
Casting and Formatting
A TimeString object can be cast into a string or formatted using PHP's DateTime interface formats (see https://www.php.net/manual/en/datetime.format.php)
TimeString objects can be transformed into other types:
It is also possible to create a new TimeString object in a different timezone:
TimeString objects can be also created from and converted to compact strings with only numbers:
Factory Methods
The following factory methods are also provided:
Comparison
The class provides comparison functions: