Interface I18nDateTimeInterface
Interface for date formatting methods shared by both Time & Date.
Constants summary
-
int
DAYS_PER_WEEK7
-
string
DEFAULT_TO_STRING_FORMAT'Y-m-d H:i:s'
-
int
FRIDAY5
-
int
HOURS_PER_DAY24
-
int
MINUTES_PER_HOUR60
-
int
MONDAY1
-
int
MONTHS_PER_QUARTER3
-
int
MONTHS_PER_YEAR12
-
int
SATURDAY6
-
int
SECONDS_PER_MINUTE60
-
int
SUNDAY7
-
int
THURSDAY4
-
int
TUESDAY2
-
int
WEDNESDAY3
-
int
WEEKS_PER_YEAR52
-
int
YEARS_PER_CENTURY100
-
int
YEARS_PER_DECADE10
Method Summary
- addDays() public
Add days to the instance. Positive $value travels forward while negative $value travels into the past.
- addHours() public
Add hours to the instance. Positive $value travels forward while negative $value travels into the past.
- addMinutes() public
Add minutes to the instance. Positive $value travels forward while negative $value travels into the past.
- addMonths() public
Add months to the instance. Positive $value travels forward while negative $value travels into the past.
- addMonthsWithOverflow() public
Add months with overflowing to the instance. Positive $value travels forward while negative $value travels into the past.
- addSeconds() public
Add seconds to the instance. Positive $value travels forward while negative $value travels into the past.
- addWeekdays() public
Add weekdays to the instance. Positive $value travels forward while negative $value travels into the past.
- addWeeks() public
Add weeks to the instance. Positive $value travels forward while negative $value travels into the past.
- addYears() public
Add years to the instance. Positive $value travel forward while negative $value travel into the past.
- addYearsWithOverflow() public
Add years with overflowing to the instance. Positive $value travels forward while negative $value travels into the past.
- average() public
Modify the current instance to the average of a given instance (default now) and the current instance.
- firstOfMonth() public
Modify to the first occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the first day of the current month. Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
- firstOfQuarter() public
Modify to the first occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the first day of the current quarter. Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
- firstOfYear() public
Modify to the first occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the first day of the current year. Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
- i18nFormat() public
Returns a formatted string for this time object using the preferred format and language for the specified locale.
- lastOfMonth() public
Modify to the last occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the last day of the current month. Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
- lastOfQuarter() public
Modify to the last occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the last day of the current quarter. Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
- lastOfYear() public
Modify to the last occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the last day of the current year. Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
- max() public
Get the maximum instance between a given instance (default now) and the current instance.
- min() public
Get the minimum instance between a given instance (default now) and the current instance.
- modify() public
- nthOfMonth() public
Modify to the given occurrence of a given day of the week in the current month. If the calculated occurrence is outside the scope of the current month, then return false and no modifications are made.
- nthOfQuarter() public
Modify to the given occurrence of a given day of the week in the current quarter. If the calculated occurrence is outside the scope of the current quarter, then return false and no modifications are made.
- nthOfYear() public
Modify to the given occurrence of a given day of the week in the current year. If the calculated occurrence is outside the scope of the current year, then return false and no modifications are made.
- parseDate() public static
Returns a new Time object after parsing the provided $date string based on the passed or configured date time format. This method is locale dependent, Any string that is passed to this function will be interpreted as a locale dependent string.
- parseDateTime() public static
Returns a new Time object after parsing the provided time string based on the passed or configured date time format. This method is locale dependent, Any string that is passed to this function will be interpreted as a locale dependent string.
- parseTime() public static
Returns a new Time object after parsing the provided $time string based on the passed or configured date time format. This method is locale dependent, Any string that is passed to this function will be interpreted as a locale dependent string.
- resetToStringFormat() public static
Resets the format used to the default when converting an instance of this type to a string
- setJsonEncodeFormat() public static
Sets the default format used when converting this object to JSON
- setToStringFormat() public static
Sets the default format used when type converting instances of this type to string
- startOfWeek() public
Resets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00
Method Detail
addDay() public
addDay(int $value)
Add a day to the instance
Parameters
-
int
$value optional The number of days to add.
Returns
static
addDays() public
addDays(int $value)
Add days to the instance. Positive $value travels forward while negative $value travels into the past.
Parameters
-
int
$value The number of days to add.
Returns
static
addHour() public
addHour(int $value)
Add an hour to the instance
Parameters
-
int
$value optional The number of hours to add.
Returns
static
addHours() public
addHours(int $value)
Add hours to the instance. Positive $value travels forward while negative $value travels into the past.
Parameters
-
int
$value The number of hours to add.
Returns
static
addMinute() public
addMinute(int $value)
Add a minute to the instance
Parameters
-
int
$value optional The number of minutes to add.
Returns
static
addMinutes() public
addMinutes(int $value)
Add minutes to the instance. Positive $value travels forward while negative $value travels into the past.
Parameters
-
int
$value The number of minutes to add.
Returns
static
addMonth() public
addMonth(int $value)
Add a month to the instance.
Has the same behavior as addMonths()
.
Parameters
-
int
$value optional The number of months to add.
Returns
static
addMonthWithOverflow() public
addMonthWithOverflow(int $value)
Add a month with overflow to the instance.
Has the same behavior as addMonthsWithOverflow()
.
Parameters
-
int
$value optional The number of months to add.
Returns
static
addMonths() public
addMonths(int $value)
Add months to the instance. Positive $value travels forward while negative $value travels into the past.
If the new date does not exist, the last day of the month is used instead instead of overflowing into the next month.
Example:
(new Chronos('2015-01-03'))->addMonths(1); // Results in 2015-02-03 (new Chronos('2015-01-31'))->addMonths(1); // Results in 2015-02-28
Parameters
-
int
$value The number of months to add.
Returns
static
addMonthsWithOverflow() public
addMonthsWithOverflow(int $value)
Add months with overflowing to the instance. Positive $value travels forward while negative $value travels into the past.
If the new date does not exist, the days overflow into the next month.
Example:
(new Chronos('2012-01-30'))->addMonthsWithOverflow(1); // Results in 2013-03-01
Parameters
-
int
$value The number of months to add.
Returns
static
addSecond() public
addSecond(int $value)
Add a second to the instance
Parameters
-
int
$value optional The number of seconds to add.
Returns
static
addSeconds() public
addSeconds(int $value)
Add seconds to the instance. Positive $value travels forward while negative $value travels into the past.
Parameters
-
int
$value The number of seconds to add.
Returns
static
addWeek() public
addWeek(int $value)
Add a week to the instance
Parameters
-
int
$value optional The number of weeks to add.
Returns
static
addWeekday() public
addWeekday(int $value)
Add a weekday to the instance
Parameters
-
int
$value optional The number of weekdays to add.
Returns
static
addWeekdays() public
addWeekdays(int $value)
Add weekdays to the instance. Positive $value travels forward while negative $value travels into the past.
Parameters
-
int
$value The number of weekdays to add.
Returns
static
addWeeks() public
addWeeks(int $value)
Add weeks to the instance. Positive $value travels forward while negative $value travels into the past.
Parameters
-
int
$value The number of weeks to add.
Returns
static
addYear() public
addYear(int $value)
Add a year to the instance
Has the same behavior as addYears()
.
Parameters
-
int
$value optional The number of years to add.
Returns
static
addYearWithOverflow() public
addYearWithOverflow(int $value)
Add a year with overflow to the instance
Has the same behavior as addYearsWithOverflow()
.
Parameters
-
int
$value optional The number of years to add.
Returns
static
addYears() public
addYears(int $value)
Add years to the instance. Positive $value travel forward while negative $value travel into the past.
If the new date does not exist, the last day of the month is used instead instead of overflowing into the next month.
Example:
(new Chronos('2015-01-03'))->addYears(1); // Results in 2016-01-03 (new Chronos('2012-02-29'))->addYears(1); // Results in 2013-02-28
Parameters
-
int
$value The number of years to add.
Returns
static
addYearsWithOverflow() public
addYearsWithOverflow(int $value)
Add years with overflowing to the instance. Positive $value travels forward while negative $value travels into the past.
If the new date does not exist, the days overflow into the next month.
Example:
(new Chronos('2012-02-29'))->addYearsWithOverflow(1); // Results in 2013-03-01
Parameters
-
int
$value The number of years to add.
Returns
static
average() public
average(?\Cake\Chronos\ChronosInterface $dt)
Modify the current instance to the average of a given instance (default now) and the current instance.
Parameters
-
\Cake\Chronos\ChronosInterface
$dt optional The instance to compare with.
Returns
static
between() public
between(\Cake\Chronos\ChronosInterface $dt1, \Cake\Chronos\ChronosInterface $dt2, bool $equal)
Determines if the instance is between two others
Parameters
-
\Cake\Chronos\ChronosInterface
$dt1 The instance to compare with.
-
\Cake\Chronos\ChronosInterface
$dt2 The instance to compare with.
-
bool
$equal optional Indicates if a > and < comparison should be used or <= or >=
Returns
bool
closest() public
closest(\Cake\Chronos\ChronosInterface $dt1, \Cake\Chronos\ChronosInterface $dt2)
Get the closest date from the instance.
Parameters
-
\Cake\Chronos\ChronosInterface
$dt1 The instance to compare with.
-
\Cake\Chronos\ChronosInterface
$dt2 The instance to compare with.
Returns
static
copy() public
copy()
Get a copy of the instance
Returns
static
day() public
day(int $value)
Set the instance's day
Parameters
-
int
$value The day value.
Returns
static
diffFiltered() public
diffFiltered(\Cake\Chronos\ChronosInterval $ci, callable $callback, ?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference by the given interval using a filter callable
Parameters
-
\Cake\Chronos\ChronosInterval
$ci An interval to traverse by
-
callable
$callback The callback to use for filtering.
-
\Cake\Chronos\ChronosInterface|null
$dt optional The instance to difference from.
-
bool
$abs optional Get the absolute of the difference
Returns
int
diffForHumans() public
diffForHumans(?\Cake\Chronos\ChronosInterface $other, bool $absolute)
Get the difference in a human readable format in the current locale.
When comparing a value in the past to default now: 1 hour ago 5 months ago
When comparing a value in the future to default now: 1 hour from now 5 months from now
When comparing a value in the past to another value: 1 hour before 5 months before
When comparing a value in the future to another value: 1 hour after 5 months after
Parameters
-
\Cake\Chronos\ChronosInterface|null
$other optional The datetime to compare with.
-
bool
$absolute optional Removes time difference modifiers ago, after, etc
Returns
string
diffInDays() public
diffInDays(?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference in days
Parameters
-
\Cake\Chronos\ChronosInterface|null
$dt optional The instance to difference from.
-
bool
$abs optional Get the absolute of the difference
Returns
int
diffInDaysFiltered() public
diffInDaysFiltered(callable $callback, ?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference in days using a filter callable
Parameters
-
callable
$callback The callback to use for filtering.
-
\Cake\Chronos\ChronosInterface|null
$dt optional The instance to difference from.
-
bool
$abs optional Get the absolute of the difference
Returns
int
diffInHours() public
diffInHours(?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference in hours
Parameters
-
\Cake\Chronos\ChronosInterface|null
$dt optional The instance to difference from.
-
bool
$abs optional Get the absolute of the difference
Returns
int
diffInHoursFiltered() public
diffInHoursFiltered(callable $callback, ?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference in hours using a filter callable
Parameters
-
callable
$callback The callback to use for filtering.
-
\Cake\Chronos\ChronosInterface|null
$dt optional The instance to difference from.
-
bool
$abs optional Get the absolute of the difference
Returns
int
diffInMinutes() public
diffInMinutes(?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference in minutes
Parameters
-
\Cake\Chronos\ChronosInterface|null
$dt optional The instance to difference from.
-
bool
$abs optional Get the absolute of the difference
Returns
int
diffInMonths() public
diffInMonths(?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference in months
Parameters
-
\Cake\Chronos\ChronosInterface|null
$dt optional The instance to difference from.
-
bool
$abs optional Get the absolute of the difference
Returns
int
diffInSeconds() public
diffInSeconds(?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference in seconds
Parameters
-
\Cake\Chronos\ChronosInterface|null
$dt optional The instance to difference from.
-
bool
$abs optional Get the absolute of the difference
Returns
int
diffInWeekdays() public
diffInWeekdays(?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference in weekdays
Parameters
-
\Cake\Chronos\ChronosInterface|null
$dt optional The instance to difference from.
-
bool
$abs optional Get the absolute of the difference
Returns
int
diffInWeekendDays() public
diffInWeekendDays(?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference in weekend days using a filter
Parameters
-
\Cake\Chronos\ChronosInterface|null
$dt optional The instance to difference from.
-
bool
$abs optional Get the absolute of the difference
Returns
int
diffInWeeks() public
diffInWeeks(?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference in weeks
Parameters
-
\Cake\Chronos\ChronosInterface|null
$dt optional The instance to difference from.
-
bool
$abs optional Get the absolute of the difference
Returns
int
diffInYears() public
diffInYears(?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference in years
Parameters
-
\Cake\Chronos\ChronosInterface|null
$dt optional The instance to difference from.
-
bool
$abs optional Get the absolute of the difference
Returns
int
endOfCentury() public
endOfCentury()
Resets the date to end of the century and time to 23:59:59
Returns
static
endOfDay() public
endOfDay()
Resets the time to 23:59:59
Returns
static
endOfDecade() public
endOfDecade()
Resets the date to end of the decade and time to 23:59:59
Returns
static
endOfMonth() public
endOfMonth()
Resets the date to end of the month and time to 23:59:59
Returns
static
endOfWeek() public
endOfWeek()
Resets the date to end of week (defined in $weekEndsAt) and time to 23:59:59
Returns
static
endOfYear() public
endOfYear()
Resets the date to end of the year and time to 23:59:59
Returns
static
eq() public
eq(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is equal to another
Parameters
-
\Cake\Chronos\ChronosInterface
$dt The instance to compare with.
Returns
bool
See Also
equals() public
equals(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is equal to another
Parameters
-
\Cake\Chronos\ChronosInterface
$dt The instance to compare with.
Returns
bool
farthest() public
farthest(\Cake\Chronos\ChronosInterface $dt1, \Cake\Chronos\ChronosInterface $dt2)
Get the farthest date from the instance.
Parameters
-
\Cake\Chronos\ChronosInterface
$dt1 The instance to compare with.
-
\Cake\Chronos\ChronosInterface
$dt2 The instance to compare with.
Returns
static
firstOfMonth() public
firstOfMonth(?int $dayOfWeek)
Modify to the first occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the first day of the current month. Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
Parameters
-
int|null
$dayOfWeek optional The day of the week to move to.
Returns
mixed
firstOfQuarter() public
firstOfQuarter(?int $dayOfWeek)
Modify to the first occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the first day of the current quarter. Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
Parameters
-
int|null
$dayOfWeek optional The day of the week to move to.
Returns
mixed
firstOfYear() public
firstOfYear(?int $dayOfWeek)
Modify to the first occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the first day of the current year. Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
Parameters
-
int|null
$dayOfWeek optional The day of the week to move to.
Returns
mixed
getDefaultLocale() public static
getDefaultLocale()
Gets the default locale.
Returns
string|null
The default locale string to be used or null.
getDiffFormatter() public static
getDiffFormatter()
Get the difference formatter instance.
Returns
\Cake\Chronos\DifferenceFormatterInterface
The formatter instance.
greaterThan() public
greaterThan(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is greater (after) than another
Parameters
-
\Cake\Chronos\ChronosInterface
$dt The instance to compare with.
Returns
bool
greaterThanOrEquals() public
greaterThanOrEquals(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is greater (after) than or equal to another
Parameters
-
\Cake\Chronos\ChronosInterface
$dt The instance to compare with.
Returns
bool
gt() public
gt(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is greater (after) than another
Parameters
-
\Cake\Chronos\ChronosInterface
$dt The instance to compare with.
Returns
bool
See Also
gte() public
gte(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is greater (after) than or equal to another
Parameters
-
\Cake\Chronos\ChronosInterface
$dt The instance to compare with.
Returns
bool
See Also
hour() public
hour(int $value)
Set the instance's hour
Parameters
-
int
$value The hour value.
Returns
static
i18nFormat() public
i18nFormat(mixed $format, mixed $timezone, mixed $locale)
Returns a formatted string for this time object using the preferred format and language for the specified locale.
It is possible to specify the desired format for the string to be displayed. You can either pass IntlDateFormatter
constants as the first argument of this function, or pass a full ICU date formatting string as specified in the following resource: http://www.icu-project.org/apiref/icu4c/classSimpleDateFormat.html#details.
Additional to IntlDateFormatter
constants and date formatting string you can use Time::UNIX_TIMESTAMP_FORMAT to get a unix timestamp
Examples
$time = new Time('2014-04-20 22:10'); $time->i18nFormat(); // outputs '4/20/14, 10:10 PM' for the en-US locale $time->i18nFormat(\IntlDateFormatter::FULL); // Use the full date and time format $time->i18nFormat([\IntlDateFormatter::FULL, \IntlDateFormatter::SHORT]); // Use full date but short time format $time->i18nFormat('yyyy-MM-dd HH:mm:ss'); // outputs '2014-04-20 22:10' $time->i18nFormat(Time::UNIX_TIMESTAMP_FORMAT); // outputs '1398031800'
If you wish to control the default format to be used for this method, you can alter the value of the static Time::$defaultLocale
variable and set it to one of the possible formats accepted by this function.
You can read about the available IntlDateFormatter constants at https://secure.php.net/manual/en/class.intldateformatter.php
If you need to display the date in a different timezone than the one being used for this Time object without altering its internal state, you can pass a timezone string or object as the second parameter.
Finally, should you need to use a different locale for displaying this time object, pass a locale string as the third parameter to this function.
Examples
$time = new Time('2014-04-20 22:10'); $time->i18nFormat(null, null, 'de-DE'); $time->i18nFormat(\IntlDateFormatter::FULL, 'Europe/Berlin', 'de-DE');
You can control the default locale to be used by setting the static variable Time::$defaultLocale
to a valid locale string. If empty, the default will be taken from the intl.default_locale
ini config.
Parameters
-
string|int|null
$format optional Format string.
-
string|\DateTimeZone|null
$timezone optional Timezone string or DateTimeZone object in which the date will be displayed. The timezone stored for this object will not be changed.
-
string|null
$locale optional The locale name in which the date should be displayed (e.g. pt-BR)
Returns
string|int
Formatted and translated date string
isBirthday() public
isBirthday(\Cake\Chronos\ChronosInterface $dt)
Check if its the birthday. Compares the date/month values of the two dates.
Parameters
-
\Cake\Chronos\ChronosInterface
$dt The instance to compare with.
Returns
bool
isFriday() public
isFriday()
Checks if this day is a Friday.
Returns
bool
isFuture() public
isFuture()
Determines if the instance is in the future, ie. greater (after) than now
Returns
bool
isLeapYear() public
isLeapYear()
Determines if the instance is a leap year
Returns
bool
isMonday() public
isMonday()
Checks if this day is a Monday.
Returns
bool
isMutable() public
isMutable()
Check if instance of ChronosInterface is mutable.
Returns
bool
isPast() public
isPast()
Determines if the instance is in the past, ie. less (before) than now
Returns
bool
isSameDay() public
isSameDay(\Cake\Chronos\ChronosInterface $dt)
Checks if the passed in date is the same day as the instance current day.
Parameters
-
\Cake\Chronos\ChronosInterface
$dt The instance to check against.
Returns
bool
isSaturday() public
isSaturday()
Checks if this day is a Saturday.
Returns
bool
isSunday() public
isSunday()
Checks if this day is a Sunday.
Returns
bool
isThisMonth() public
isThisMonth()
Returns true if this object represents a date within the current month
Returns
bool
isThisWeek() public
isThisWeek()
Returns true if this object represents a date within the current week
Returns
bool
isThisYear() public
isThisYear()
Returns true if this object represents a date within the current year
Returns
bool
isThursday() public
isThursday()
Checks if this day is a Thursday.
Returns
bool
isToday() public
isToday()
Determines if the instance is today
Returns
bool
isTomorrow() public
isTomorrow()
Determines if the instance is tomorrow
Returns
bool
isTuesday() public
isTuesday()
Checks if this day is a Tuesday.
Returns
bool
isWednesday() public
isWednesday()
Checks if this day is a Wednesday.
Returns
bool
isWeekday() public
isWeekday()
Determines if the instance is a weekday
Returns
bool
isWeekend() public
isWeekend()
Determines if the instance is a weekend day
Returns
bool
isWithinNext() public
isWithinNext(mixed $timeInterval)
Returns true this instance will happen within the specified interval
Parameters
-
string|int
$timeInterval the numeric value with space then time type. Example of valid types: 6 hours, 2 days, 1 minute.
Returns
bool
isYesterday() public
isYesterday()
Determines if the instance is yesterday
Returns
bool
lastOfMonth() public
lastOfMonth(?int $dayOfWeek)
Modify to the last occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the last day of the current month. Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
Parameters
-
int|null
$dayOfWeek optional The day of the week to move to.
Returns
mixed
lastOfQuarter() public
lastOfQuarter(?int $dayOfWeek)
Modify to the last occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the last day of the current quarter. Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
Parameters
-
int|null
$dayOfWeek optional The day of the week to move to.
Returns
mixed
lastOfYear() public
lastOfYear(?int $dayOfWeek)
Modify to the last occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the last day of the current year. Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
Parameters
-
int|null
$dayOfWeek optional The day of the week to move to.
Returns
mixed
lessThan() public
lessThan(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is less (before) than another
Parameters
-
\Cake\Chronos\ChronosInterface
$dt The instance to compare with.
Returns
bool
lessThanOrEquals() public
lessThanOrEquals(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is less (before) or equal to another
Parameters
-
\Cake\Chronos\ChronosInterface
$dt The instance to compare with.
Returns
bool
lt() public
lt(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is less (before) than another
Parameters
-
\Cake\Chronos\ChronosInterface
$dt The instance to compare with.
Returns
bool
See Also
lte() public
lte(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is less (before) or equal to another
Parameters
-
\Cake\Chronos\ChronosInterface
$dt The instance to compare with.
Returns
bool
See Also
max() public
max(?\Cake\Chronos\ChronosInterface $dt)
Get the maximum instance between a given instance (default now) and the current instance.
Parameters
-
\Cake\Chronos\ChronosInterface|null
$dt optional The instance to compare with.
Returns
static
min() public
min(?\Cake\Chronos\ChronosInterface $dt)
Get the minimum instance between a given instance (default now) and the current instance.
Parameters
-
\Cake\Chronos\ChronosInterface|null
$dt optional The instance to compare with.
Returns
static
minute() public
minute(int $value)
Set the instance's minute
Parameters
-
int
$value The minute value.
Returns
static
modify() public
modify(string $relative)
Parameters
-
string
$relative
month() public
month(int $value)
Set the instance's month
Parameters
-
int
$value The month value.
Returns
static
ne() public
ne(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is not equal to another
Parameters
-
\Cake\Chronos\ChronosInterface
$dt The instance to compare with.
Returns
bool
See Also
next() public
next(?int $dayOfWeek)
Modify to the next occurrence of a given day of the week.
If no dayOfWeek is provided, modify to the next occurrence of the current day of the week. Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
Parameters
-
int|null
$dayOfWeek optional The day of the week to move to.
Returns
mixed
nice() public
nice(mixed $timezone, mixed $locale)
Returns a nicely formatted date string for this object.
The format to be used is stored in the static property Time::niceFormat
.
Parameters
-
string|\DateTimeZone|null
$timezone optional Timezone string or DateTimeZone object in which the date will be displayed. The timezone stored for this object will not be changed.
-
string|null
$locale optional The locale name in which the date should be displayed (e.g. pt-BR)
Returns
string
Formatted date string
notEquals() public
notEquals(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is not equal to another
Parameters
-
\Cake\Chronos\ChronosInterface
$dt The instance to compare with.
Returns
bool
now() public static
now(mixed $tz)
Get a ChronosInterface instance for the current date and time
Parameters
-
\DateTimeZone|string|null
$tz The DateTimeZone object or timezone name.
Returns
static
nthOfMonth() public
nthOfMonth(int $nth, int $dayOfWeek)
Modify to the given occurrence of a given day of the week in the current month. If the calculated occurrence is outside the scope of the current month, then return false and no modifications are made.
Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
Parameters
-
int
$nth The offset to use.
-
int
$dayOfWeek The day of the week to move to.
Returns
mixed
nthOfQuarter() public
nthOfQuarter(int $nth, int $dayOfWeek)
Modify to the given occurrence of a given day of the week in the current quarter. If the calculated occurrence is outside the scope of the current quarter, then return false and no modifications are made.
Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
Parameters
-
int
$nth The offset to use.
-
int
$dayOfWeek The day of the week to move to.
Returns
mixed
nthOfYear() public
nthOfYear(int $nth, int $dayOfWeek)
Modify to the given occurrence of a given day of the week in the current year. If the calculated occurrence is outside the scope of the current year, then return false and no modifications are made.
Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
Parameters
-
int
$nth The offset to use.
-
int
$dayOfWeek The day of the week to move to.
Returns
mixed
parseDate() public static
parseDate(string $date, mixed $format)
Returns a new Time object after parsing the provided $date string based on the passed or configured date time format. This method is locale dependent, Any string that is passed to this function will be interpreted as a locale dependent string.
When no $format is provided, the wordFormat
format will be used.
If it was impossible to parse the provided time, null will be returned.
Example:
$time = Time::parseDate('10/13/2013'); $time = Time::parseDate('13 Oct, 2013', 'dd MMM, y'); $time = Time::parseDate('13 Oct, 2013', IntlDateFormatter::SHORT);
Parameters
-
string
$date The date string to parse.
-
string|int|array|null
$format optional Any format accepted by IntlDateFormatter.
Returns
static|null
parseDateTime() public static
parseDateTime(string $time, mixed $format, mixed $tz)
Returns a new Time object after parsing the provided time string based on the passed or configured date time format. This method is locale dependent, Any string that is passed to this function will be interpreted as a locale dependent string.
When no $format is provided, the toString
format will be used.
If it was impossible to parse the provided time, null will be returned.
Example:
$time = Time::parseDateTime('10/13/2013 12:54am'); $time = Time::parseDateTime('13 Oct, 2013 13:54', 'dd MMM, y H:mm'); $time = Time::parseDateTime('10/10/2015', [IntlDateFormatter::SHORT, -1]);
Parameters
-
string
$time The time string to parse.
-
string|int[]|null
$format optional Any format accepted by IntlDateFormatter.
-
\DateTimeZone|string|null
$tz optional The timezone for the instance
Returns
static|null
Throws
InvalidArgumentException
If $format is a single int instead of array of constants
parseTime() public static
parseTime(string $time, mixed $format)
Returns a new Time object after parsing the provided $time string based on the passed or configured date time format. This method is locale dependent, Any string that is passed to this function will be interpreted as a locale dependent string.
When no $format is provided, the IntlDateFormatter::SHORT format will be used.
If it was impossible to parse the provided time, null will be returned.
Example:
$time = Time::parseTime('11:23pm');
Parameters
-
string
$time The time string to parse.
-
string|int|null
$format optional Any format accepted by IntlDateFormatter.
Returns
static|null
previous() public
previous(?int $dayOfWeek)
Modify to the previous occurrence of a given day of the week.
If no dayOfWeek is provided, modify to the previous occurrence of the current day of the week. Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
Parameters
-
int|null
$dayOfWeek optional The day of the week to move to.
Returns
mixed
resetToStringFormat() public static
resetToStringFormat()
Resets the format used to the default when converting an instance of this type to a string
second() public
second(int $value)
Set the instance's second
Parameters
-
int
$value The seconds value.
Returns
static
secondsSinceMidnight() public
secondsSinceMidnight()
The number of seconds since midnight.
Returns
int
secondsUntilEndOfDay() public
secondsUntilEndOfDay()
The number of seconds until 23:59:59.
Returns
int
setDateTime() public
setDateTime(int $year, int $month, int $day, int $hour, int $minute, int $second)
Set the date and time all together
Parameters
-
int
$year The year to set.
-
int
$month The month to set.
-
int
$day The day to set.
-
int
$hour The hour to set.
-
int
$minute The minute to set.
-
int
$second optional The second to set.
Returns
static
setDefaultLocale() public static
setDefaultLocale(?string $locale)
Sets the default locale.
Parameters
-
string|null
$locale optional The default locale string to be used or null.
setDiffFormatter() public static
setDiffFormatter(\Cake\Chronos\DifferenceFormatterInterface $formatter)
Set the difference formatter instance.
Parameters
-
\Cake\Chronos\DifferenceFormatterInterface
$formatter The formatter instance when setting.
setJsonEncodeFormat() public static
setJsonEncodeFormat(mixed $format)
Sets the default format used when converting this object to JSON
The format should be either the formatting constants from IntlDateFormatter as described in (https://secure.php.net/manual/en/class.intldateformatter.php) or a pattern as specified in (http://www.icu-project.org/apiref/icu4c/classSimpleDateFormat.html#details)
It is possible to provide an array of 2 constants. In this case, the first position will be used for formatting the date part of the object and the second position will be used to format the time part.
Alternatively, the format can provide a callback. In this case, the callback can receive this datetime object and return a formatted string.
Parameters
-
string|array|int|\Closure
$format Format.
See Also
setTimeFromTimeString() public
setTimeFromTimeString(string $time)
Set the time by time string
Parameters
-
string
$time Time as string.
Returns
static
setTimezone() public
setTimezone(mixed $value)
Set the instance's timezone from a string or object
Parameters
-
\DateTimeZone|string
$value The DateTimeZone object or timezone name to use.
Returns
static
setToStringFormat() public static
setToStringFormat(mixed $format)
Sets the default format used when type converting instances of this type to string
Parameters
-
string|int|int[]
$format Format.
startOfCentury() public
startOfCentury()
Resets the date to the first day of the century and the time to 00:00:00
Returns
static
startOfDay() public
startOfDay()
Resets the time to 00:00:00
Returns
static
startOfDecade() public
startOfDecade()
Resets the date to the first day of the decade and the time to 00:00:00
Returns
static
startOfMonth() public
startOfMonth()
Resets the date to the first day of the month and the time to 00:00:00
Returns
static
startOfWeek() public
startOfWeek()
Resets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00
Returns
static
startOfYear() public
startOfYear()
Resets the date to the first day of the year and the time to 00:00:00
Returns
static
subDay() public
subDay(int $value)
Remove a day from the instance
Parameters
-
int
$value optional The number of days to remove.
Returns
static
subDays() public
subDays(int $value)
Remove days from the instance
Parameters
-
int
$value The number of days to remove.
Returns
static
subHour() public
subHour(int $value)
Remove an hour from the instance
Parameters
-
int
$value optional The number of hours to remove.
Returns
static
subHours() public
subHours(int $value)
Remove hours from the instance
Parameters
-
int
$value The number of hours to remove.
Returns
static
subMinute() public
subMinute(int $value)
Remove a minute from the instance
Parameters
-
int
$value optional The number of minutes to remove.
Returns
static
subMinutes() public
subMinutes(int $value)
Remove minutes from the instance
Parameters
-
int
$value The number of minutes to remove.
Returns
static
subMonth() public
subMonth(int $value)
Remove a month from the instance
Has the same behavior as addMonths()
.
Parameters
-
int
$value optional The number of months to remove.
Returns
static
subMonthWithOverflow() public
subMonthWithOverflow(int $value)
Remove a month with overflow from the instance.
Has the same behavior as addMonthsWithOverflow()
.
Parameters
-
int
$value optional The number of months to remove.
Returns
static
subMonths() public
subMonths(int $value)
Remove months from the instance.
Has the same behavior as addMonths()
.
Parameters
-
int
$value The number of months to remove.
Returns
static
subMonthsWithOverflow() public
subMonthsWithOverflow(int $value)
Remove months with overflow from the instance.
Has the same behavior as addMonthsWithOverflow()
.
Parameters
-
int
$value The number of months to remove.
Returns
static
subSecond() public
subSecond(int $value)
Remove a second from the instance
Parameters
-
int
$value optional The number of seconds to remove.
Returns
static
subSeconds() public
subSeconds(int $value)
Remove seconds from the instance
Parameters
-
int
$value The number of seconds to remove.
Returns
static
subWeek() public
subWeek(int $value)
Remove a week from the instance
Parameters
-
int
$value optional The number of weeks to remove.
Returns
static
subWeekday() public
subWeekday(int $value)
Remove a weekday from the instance
Parameters
-
int
$value optional The number of weekdays to remove.
Returns
static
subWeekdays() public
subWeekdays(int $value)
Remove weekdays from the instance
Parameters
-
int
$value The number of weekdays to remove.
Returns
static
subWeeks() public
subWeeks(int $value)
Remove weeks to the instance
Parameters
-
int
$value The number of weeks to remove.
Returns
static
subYear() public
subYear(int $value)
Remove a year from the instance.
Has the same behavior as addYears()
.
Parameters
-
int
$value optional The number of years to remove.
Returns
static
subYearWithOverflow() public
subYearWithOverflow(int $value)
Remove a year with overflow from the instance
Has the same behavior as addYearsWithOverflow()
.
Parameters
-
int
$value optional The number of years to remove.
Returns
static
subYears() public
subYears(int $value)
Remove years from the instance.
Has the same behavior as addYears()
.
Parameters
-
int
$value The number of years to remove.
Returns
static
subYearsWithOverflow() public
subYearsWithOverflow(int $value)
Remove years with overflow from the instance
Has the same behavior as addYearsWithOverflow()
.
Parameters
-
int
$value The number of years to remove.
Returns
static
timestamp() public
timestamp(int $value)
Set the instance's timestamp
Parameters
-
int
$value The timestamp value to set.
Returns
static
timezone() public
timezone(mixed $value)
Alias for setTimezone()
Parameters
-
\DateTimeZone|string
$value The DateTimeZone object or timezone name to use.
Returns
static
toAtomString() public
toAtomString()
Format the instance as ATOM
Returns
string
toCookieString() public
toCookieString()
Format the instance as COOKIE
Returns
string
toDateString() public
toDateString()
Format the instance as date
Returns
string
toDateTimeString() public
toDateTimeString()
Format the instance as date and time
Returns
string
toDayDateTimeString() public
toDayDateTimeString()
Format the instance with day, date and time
Returns
string
toFormattedDateString() public
toFormattedDateString()
Format the instance as a readable date
Returns
string
toIso8601String() public
toIso8601String()
Format the instance as ISO8601
Returns
string
toRfc1036String() public
toRfc1036String()
Format the instance as RFC1036
Returns
string
toRfc1123String() public
toRfc1123String()
Format the instance as RFC1123
Returns
string
toRfc2822String() public
toRfc2822String()
Format the instance as RFC2822
Returns
string
toRfc3339String() public
toRfc3339String()
Format the instance as RFC3339
Returns
string
toRfc822String() public
toRfc822String()
Format the instance as RFC822
Returns
string
toRfc850String() public
toRfc850String()
Format the instance as RFC850
Returns
string
toRssString() public
toRssString()
Format the instance as RSS
Returns
string
toTimeString() public
toTimeString()
Format the instance as time
Returns
string
toW3cString() public
toW3cString()
Format the instance as W3C
Returns
string
tz() public
tz(mixed $value)
Alias for setTimezone()
Parameters
-
\DateTimeZone|string
$value The DateTimeZone object or timezone name to use.
Returns
static
wasWithinLast() public
wasWithinLast(mixed $timeInterval)
Returns true this instance happened within the specified interval
Parameters
-
string|int
$timeInterval the numeric value with space then time type. Example of valid types: 6 hours, 2 days, 1 minute.
Returns
bool
year() public
year(int $value)
Set the instance's year
Parameters
-
int
$value The year value.
Returns
static
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.1/interface-Cake.I18n.I18nDateTimeInterface.html