Download the PHP package choval/datetime without Composer
On this page you can find all versions of the php package choval/datetime. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download choval/datetime
More information about choval/datetime
Files in choval/datetime
Package datetime
Short Description A drop-in replacement for PHP's DateTime with more flexibility
License MIT
Informations about the package datetime
Choval\DateTime
This is a drop-in replacement for PHP's DateTime.
Some parsers have been added to ease the use, see Usage and Differences.
Installation
Simple drop-in
Before
With it replaced
The following examples will use the full class name to avoid confussion.
Usage
Differences
If replacing PHP's DateTime, this class behaves almost exactly alike. With the exception of the constructor handling int
as a timestamp even for low numbers.
Constructor
The __constructor
method allows a third parameter for passing the format of the first.
This allows passing custom format date time strings.
Format
The format
method allows a second paratemer for passing the timezone of the output, otherwise the timezone of the object is used.
The passed timezone will not change the one of the object itself. See the following example:
Extras
The following methods were added to move around dates and printing/returning them as strings.
Time modifiers
- startOfDay(void) : self
- midDay(void) : self
- endOfDay(void) : self
Date modifiers for the year
- firstDayOfYear([int $year]) : self
- lastDayOfYear([int $year]) : self
Date modifiers for the month
- firstDayOfMonth([int $month]) : self
- lastDayOfMonth([int $month]) : self
- firstSundayOfMonth([int $month]) : self
- lastSundayOfMonth([int $month]) : self
- firstMondayOfMonth([int $month]) : self
- lastMondayOfMonth([int $month]) : self
- firstFridayOfMonth([int $month]) : self
- lastFridayOfMonth([int $month]) : self
- nextMonth([int $day]) : self
- prevMonth([int $day]) : self
Workday
A non-weekend day and non-holiday (see Holidays).
- isWorkDay(void) : bool
- firstWorkDayOfMonth([int $month]) : self
- lastWorkDayOfMonth([int $month]) : self
- firstWorkDayOfYear([int $year]) : self
- lastWorkDayOfYear([int $year]) : self
Holidays
- setHolidays(array $holidays) : DateTime
- getHolidays(void) : array
- addHoliday(string $date)
- isHoliday(void) : bool
Formats
- atom(void) : string
- iso(void) : string
- cookie(void) : string
- iso8601(void) : string
- rfc822(void) : string
- rfc850(void) : string
- rfc1036(void) : string
- rfc1123(void) : string
- rfc2822(void) : string
- rfc3339(void) : string
- rfc3339Extended(void) : string
- rss(void) : string
- w3c(void) : string
Note that the ISO8601 constant returns the timezone without colon format. If needed, use the atom
format or the iso
method, both return Y-m-d\TH:i:sP
.