Date
Date
- Full name:
\Hazaar\Date
- Parent class:
DateTime
- This class implements:
\JsonSerializable
,\DateTimeInterface
Properties
usec
public int $usec
dateFormat
Global format for date part.
public static string $dateFormat
- This property is static.
timeFormat
Global format for time part.
public static string $timeFormat
- This property is static.
defaultFormat
public static string $defaultFormat
- This property is static.
instanceFormat
private string $instanceFormat
Methods
__construct
public __construct(mixed $datetime = null, \DateTimeZone|string $timezone = null): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$datetime | mixed | The datetime value you want to work with. This can be either an integer representing the datetime Epoch value (seconds since 1970-01-01) or a string datetime description supported by the PHP strtotime() function. This means that textual datetime descriptions such as 'now' and 'next monday' will work. See the PHP documentation on [[http://au1.php.net/manual/en/function.strtotime.php|strtotime()]] for more information on valid formats. If the datetime value is not set, the current date and time will be used. |
$timezone | \DateTimeZone|string | The timezone for this datetime value. If no timezone is specified then the default timezone is used. |
__toString
Magic method to output the datetime value as a string.
public __toString(): string
Uses the Date::timestamp() method.
Return Value:
string representation of the datetime value
__export
public __export(): int
setFormat
public setFormat(string $format): void
Parameters:
Parameter | Type | Description |
---|---|---|
$format | string |
setTimezone
Set the timezone for the date object.
public setTimezone(\DateTimeZone|string $timezone = null): \Hazaar\Date
Setting this will cause the date and time to be output using the specified timezone. If a timezone is not given then the default system timezone will be used. This is a good way to convert a date of another timezone into the current default system timezone.
Parameters:
Parameter | Type | Description |
---|---|---|
$timezone | \DateTimeZone|string | The timezone to set. This can be either a [[DateTimeZone]] object, a string representation of a timezone, an offset in the format hh:mm, or a numeric value of the timezone returned by timezone_identifiers_list(). If it is left null, then the default system timezone is used. |
formatTZ
Return the date time value using a format string for a specified timezone.
public formatTZ(string $format, string $timezone = 'UTC'): string
Parameters:
Parameter | Type | Description |
---|---|---|
$format | string | A standard date format string |
$timezone | string | The timezone to use to convert the date time value |
Return Value:
the date time string in the target timezone and format
getSQLDate
Get the current datetime value as an SQL compliant formatted string.
public getSQLDate(): string
Return Value:
the SQL compliant datetime string
sec
Returns the current datetime value as epoch (seconds passed since 1970-01-01).
public sec(): int
Return Value:
epoch value of datetime
usec
Return the microsecond part of the datetime value.
public usec(): int
This will more than likely always be 0 (zero) unless specified in the constructor.
Return Value:
microsecond part of datetime value
date
Return the date part formatted by the global date format.
public date(): string
Return Value:
The date part of the datetime value
time
Return the time part formatted by the global time format.
public time(): string
Return Value:
The time part of the datetime value
datetime
Return the date and time.
public datetime(): string
This will use the global date and time formats and concatenate them together, separated by a space.
Return Value:
The date and time of the datetime value
timestamp
Get the timestamp formatted as a string.
public timestamp(): string
This will use the global date and time formats and concatenate them together, separated by a space.
Return Value:
The timestamp as string
age
Returns the age in years of the date with optional precision.
public age(int $precision): int
Parameters:
Parameter | Type | Description |
---|---|---|
$precision | int | The number of digits to round an age to. Default: 0 |
Return Value:
the number of years passed since the date value
diffSeconds
Returns the difference between the current date/time value and the value supplied as the first argument.
public diffSeconds(\Hazaar\Date $timestamp): int
Normally this method will return a \DateInterval object which is the default for the \DateTime class. However this functionality has been extended with the $returnSeconds parameter which will instead return an integer value indicating the difference in whole seconds.
Parameters:
Parameter | Type | Description |
---|---|---|
$timestamp | \Hazaar\Date | The timestamp to compare the current date/time to |
year
Returns the objects current year.
public year(): int
month
Returns the objects current month.
public month(): int
day
Returns the objects current day.
public day(): int
hour
Returns the objects current hour(.
public hour(): int
minute
Returns the objects current minute.
public minute(): int
second
Returns the objects current second.
public second(): int
add
Add a date/time interval to the current date/time.
public add(\DateInterval|string $interval, bool $returnNew = false): static
See the PHP documentation on how to use the DateInterval object.
Parameters:
Parameter | Type | Description |
---|---|---|
$interval | \DateInterval|string | Can be either a \DateInterval object or a string representing an interval, such as P1H to specify 1 hour |
$returnNew | bool | Doesn't update the current \Hazaar\Date object and instead returns a new object with the interval applied |
sub
Subtract a date/time interval from the current date/time.
public sub(\DateInterval|string $interval, bool $returnNew = false): static
See the PHP documentation on how to use the DateInterval object.
Parameters:
Parameter | Type | Description |
---|---|---|
$interval | \DateInterval|string | can be either a \DateInterval object or a string representing an interval, such as P1H to specify 1 hour |
$returnNew | bool | doesn't update the current \Hazaar\Date object and instead returns a new object with the interval applied |
compare
Compare the current date with the argument.
public compare(mixed $date, bool $includeTime = false): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$date | mixed | |
$includeTime | bool |
start
Returns the start time of the current date as a Date object.
public start(): \Hazaar\Date
end
Returns the end time of the current date as a Date object.
public end(): \Hazaar\Date
firstOfWeek
Returns the first day of the current week as a Date object.
public firstOfWeek(): \Hazaar\Date
lastOfWeek
Returns the last day of the current week as a Date object.
public lastOfWeek(): \Hazaar\Date
firstOfMonth
Returns the first day of the current month as a Date object.
public firstOfMonth(): \Hazaar\Date
firstOfYear
Returns the first day of the current year as a Date object.
public firstOfYear(): \Hazaar\Date
lastOfYear
Returns the last day of the current year as a Date object.
public lastOfYear(): \Hazaar\Date
getFuzzyDiff
Return a fuzzy diff between the current time and the Date value.
public getFuzzyDiff(bool $precise = false, int $dateThresholdDays = 30): string
Parameters:
Parameter | Type | Description |
---|---|---|
$precise | bool | Boolean indicating if precise mode should be used. This generally adds the time to day-based results. |
$dateThresholdDays | int | A threshold in days after which the full date will be returned. Avoids situations like "3213 days ago" which is silly. |
Return Value:
returns a nice fuzzy interval like "yesterday at xx:xx" or "4 days ago"
getLocaleData
Get locale data for a specified locale.
public static getLocaleData(null|string[]|string $locale): string[]|bool
Data included is what is returned by PHP's localeconv() function.
- This method is static.
Parameters:
Parameter | Type | Description |
---|---|---|
$locale | null|string[]|string | the locale to get data for |
Return Value:
If the locale is invalid then FALSE is returned. Otherwise the result of localeconv() for the specified locale.
getLocaleDateFormat
Retrieve a date format for a specific locale.
public static getLocaleDateFormat(null|string[]|string $locale): bool|string
This will return something like DMY to indicate that the locale format is date, month followed by year.
These formats are not meant to be used directly in date functions as different date functions use different format specifiers and we won't even attempt to support all of them here.
- This method is static.
Parameters:
Parameter | Type | Description |
---|---|---|
$locale | null|string[]|string |
jsonSerialize
Outputs the UTC timestamp (EPOCH) When an object is included in a json_encode call.
public jsonSerialize(): mixed
Automatically generated on 2024-11-14