tp TouchPointWP Utilities DateFormats - TenthPres/TouchPoint-WP GitHub Wiki
tp\TouchPointWP\Utilities\DateFormats
Formatting Dates
- Full name:
\tp\TouchPointWP\Utilities\DateFormats - This class is an Abstract class
Methods
DateAndTimeStringFormatted
Get a single string for a single given DateTime containing both the date and the time.
public static DateAndTimeStringFormatted(\DateTimeInterface $dt): string
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$dt |
\DateTimeInterface |
TimeStringFormatted
Get a string for a single given DateTime.
public static TimeStringFormatted(\DateTimeInterface $dt): string
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$dt |
\DateTimeInterface |
timestampWithoutOffset
public static timestampWithoutOffset(?\DateTimeInterface $dt): int
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$dt |
?\DateTimeInterface |
timestampAndOffset
public static timestampAndOffset(?\DateTimeInterface $dt): int
- This method is static.* Warning: this method is deprecated. This means that this method will likely be removed in a future version. Parameters:
| Parameter | Type | Description |
|---|---|---|
$dt |
?\DateTimeInterface |
TimeRangeStringFormatted
Get a time string for a given pair of DateTimesInterfaces. This should generally only be used when all of these are true:
- The DateTimes are on the same day.
public static TimeRangeStringFormatted(\DateTimeInterface $startDt, \DateTimeInterface $endDt): string
- The event represented is not all-day.
- Neither are null
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$startDt |
\DateTimeInterface | |
$endDt |
\DateTimeInterface |
DateStringFormatted
Get a string for a single given datetime string.
public static DateStringFormatted(\DateTimeInterface $dt): string
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$dt |
\DateTimeInterface |
DateStringFormattedShort
Get a (shorter) string for a single given datetime string.
public static DateStringFormattedShort(\DateTimeInterface $dt): string
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$dt |
\DateTimeInterface |
DurationToString
Get a string for the period between $start and $end.
public static DurationToString(?\tp\TouchPointWP\Utilities\DateTimeExtended $start, ?\tp\TouchPointWP\Utilities\DateTimeExtended $end, bool|null $multiDay = null): ?string
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$start |
?\tp\TouchPointWP\Utilities\DateTimeExtended | |
$end |
?\tp\TouchPointWP\Utilities\DateTimeExtended | |
$multiDay |
bool|null |
DurationToStringArray
Takes a start and end and returns one or two strings that are intended for use in a Meeting's Notable Attributes, but can be used for other similar cases.
public static DurationToStringArray(?\DateTimeInterface $start, ?\DateTimeInterface $end, ?bool $multiDay = null, ?bool $allDay = null): \tp\TouchPointWP\Utilities\StringableArray
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$start |
?\DateTimeInterface | |
$end |
?\DateTimeInterface | |
$multiDay |
?bool | |
$allDay |
?bool |
OccurrencesToStringArray
Describe a set of separate occurrences, such as the meetings of a Cluster, rather than one continuous span.
public static OccurrencesToStringArray(array $occurrences, int $limit = \tp\TouchPointWP\Utilities\PHP_INT_MAX, bool $shortDates = false): \tp\TouchPointWP\Utilities\StringableArray
- If they're all at the same time of day, the result is a list of dates and one time, such as "Wed, Dec 23 & Thu, Dec 24" and "7:30 pm – 9:00 pm".
- If they're all on the same date, it's one date and a list of times, such as "Sun, Dec 24" and "9:00 am & 11:00 am".
- Otherwise, or if any occurrence spans more than one day, it's a list of dates with times.
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$occurrences |
array | Each an array of [DateTimeInterface $start, ?DateTimeInterface $end, bool $allDay]. |
$limit |
int | The maximum number of dates, times, or dates with times to list before "& others". |
$shortDates |
bool | Whether to use the short date format (e.g. "Wed, Dec 23"). |
Return Value:
With 'date' and 'time', or with 'datetime'. Empty if there are no occurrences.