date and time format object abstraction based on ISO 8601 standard
package | Default |
---|
__construct(string $dateTimeString = ''): \org\turbocommons\src\main\php\model\DateTimeObject
All the class methods are based and expect values that follow the ISO 8601 format, which is the international standard for the
representation of dates and times. Any other date/time format will be considered as invalid.
Following is an example of a valid ISO 8601 dateTime value:
yyyy-mm-ddTHH:MM:SS.UUU+TT:TT
where:
IMPORTANT: It is highly recommended to always physically store your datetime values as UTC (aka 00 timezone offset). The local timezone offset should be applied only when showing the datetime values to the user. All the other date and time usages of your application should be performed with UTC values.
example | Will create a DateTimeObject with the value '1996-01-01T00:00:00.000000+00:00' based on the UTC 00 timezone Will create a DateTimeObject with the value '1996-12-01T00:00:00.000000+00:00' based on the UTC 00 timezone is a fully valid ISO 8601 string value: '2017-10-14T17:55:25.163583+02:00' |
---|---|
see | https://es.wikipedia.org/wiki/ISO_8601 |
string
A string containing a valid ISO 8601 date/time value that will be used to initialize this instance. If string is empty, the current system date/time WITH UTC TIMEZONE will be used. If string is incomplete, all missing parts will be filled with the lowest possible value. If timezone offset is missing, UTC will be used.
\org\turbocommons\src\main\php\model\DateTimeObject
The created instance
add(string $value,string $type = 'minutes'): void
string
The numeric amount that will be added to this DateTimeObject instance
string
TODO - this paramenter description
compare(mixed $dateTime1,mixed $dateTime2): integer
Timezones from the specified dateTime values are taken into consideration for the comparison.
Throws |
|
---|
mixed
A valid ISO 8601 dateTime value or a DateTimeObject instance.
mixed
A valid ISO 8601 dateTime value or a DateTimeObject instance.
integer
0 If the two dateTime values represent the exact same time, 1 if dateTime1 > dateTime2 or 2 if dateTime2 > dateTime1
compareTo(mixed $dateTime): integer
Timezones from the both dateTime values are taken into consideration for the comparison.
see | \org\turbocommons\src\main\php\model\DateTimeObject::compare |
---|---|
Throws |
|
mixed
A valid ISO 8601 dateTime value or a DateTimeObject instance.
integer
0 If the two dateTime values represent the exact same time, 1 if this instance > dateTime or 2 if dateTime > this instance
getCurrentDay(): integer
integer
The day of month as a value between 1 and 31
getCurrentDayOfWeek(): integer
..
integer
A numeric value between 1 and 7 (where Sunday is 1, Monday is 2, ...)
getCurrentHour(): integer
integer
The hour as a value between 0 and 23
getCurrentMicroSecond(): integer
integer
The microseconds as a value up to 6 digits
getCurrentMiliSecond(): integer
integer
The miliseconds as a value up to 3 digits
getCurrentMinute(): integer
integer
The minute as a value between 0 and 59
getCurrentMonth(): integer
integer
A value between 1 and 12
getCurrentSecond(): integer
integer
The seconds as a value between 0 and 59
getCurrentTimeZoneOffset(): integer
integer
The timezone offset as a numeric value in seconds
getCurrentYear(): integer
integer
A numeric value representing the current year
getDay(): integer
integer
A value between 1 and 31
getDayName(integer $day): string
..
integer
A day number between 1 and 7
string
The day name in english and with capital letters, like for example: MONDAY, SATURDAY...
getDayOfWeek(): integer
..
integer
A numeric value between 1 and 7
getFirstDayOfMonth(): \org\turbocommons\src\main\php\model\DateTimeObject
\org\turbocommons\src\main\php\model\DateTimeObject
A dateTime object representing the first day of month based on the current instance
getHour(): integer
integer
A value between 0 and 23
getLastDayOfMonth(): \org\turbocommons\src\main\php\model\DateTimeObject
\org\turbocommons\src\main\php\model\DateTimeObject
A dateTime object representing the last day of month based on the current instance
getMicroSecond(): integer
integer
A value up to 6 digit
getMiliSecond(): integer
integer
A value up to 3 digit
getMinute(): integer
integer
A value between 0 and 59
getMonth(): integer
integer
A value between 1 and 12
getMonthName(integer $month): string
integer
A month number between 1 and 12
string
the month name in english and with capital letters, like: JANUARY, FEBRUARY, ...
getSecond(): integer
integer
A value between 0 and 59
getTimeZoneOffset(): integer
integer
The UTC timezone offset in seconds
getYear(): integer
integer
A 4 digits numeric value
isEqual(mixed $dateTime1,mixed $dateTime2): boolean
see | \org\turbocommons\src\main\php\model\DateTimeObject::__construct |
---|
mixed
A valid ISO 8601 dateTime string or a DateTimeObject instance.
mixed
A valid ISO 8601 dateTime string or a DateTimeObject instance.
boolean
True if the date and time values on both elements are the same
isEqualTo(mixed $dateTime): boolean
mixed
A valid ISO 8601 dateTime string or a DateTimeObject instance.
boolean
True if both dateTime values are equivalent to the exact same date and time
isUTC(): boolean
boolean
True if the instance timezone is UTC, false if not
isValidDateTime(mixed $dateTime): boolean
Therefore, this method considers a dateTime string value to be valid only if it is a string that follows that standard or a DateTimeObject instance.
see | \org\turbocommons\src\main\php\model\DateTimeObject::__construct |
---|
mixed
A string containing a valid ISO 8601 date/time value or a valid DateTimeObject instance.
boolean
true if the specified value is ISO 8601 or a DateTimeObject instance, false if value contains invalid information.
setLocalTimeZone(): \org\turbocommons\src\main\php\model\DateTimeObject
setTimeZoneOffset(string $offset): \org\turbocommons\src\main\php\model\DateTimeObject
string
One of the supported timezone names or an offset value (+0200, +05:00, -0300, -03:00, etc...)
\org\turbocommons\src\main\php\model\DateTimeObject
This object instance
setUTC(): \org\turbocommons\src\main\php\model\DateTimeObject
example | this instance contains a +02:00 timezone offset, after calling this method the offset will be +00:00 (date and time will be updated accordingly) |
---|---|
\org\turbocommons\src\main\php\model\DateTimeObject
This object instance
substract( $value, $type = 'minutes')
toString(string $formatString = 'Y-M-DTH:N:S.UOffset'): string
string
A string containing the output format like 'd/m/Y' or 'm-d-y'
where the following characters will be automatically replaced:
string
The dateTime with the specified format.