Dates
The Dates class provides helper methods for formatting dates and times.
Namespace: Medialight\Textstem\Helpers
format_date
Formats a date string according to the specified format.
public static function format_date($date, $format = 'd/m/y'): string
Parameters:
$date(string): The date string to format.$format(string): The format to use. Default is 'd/m/y'.
Returns:
- (string): The formatted date string or an empty string if the input is empty.
format_time
Formats a time string according to the specified format.
public static function format_time($date, $format = 'h:m a'): string
Parameters:
$date(string): The date/time string to format.$format(string): The format to use. Default is 'h:m a'.
Returns:
- (string): The formatted time string or an empty string if the input is empty.
format_datetime
Formats a date and time string according to the specified format.
public static function format_datetime($date, $format = 'd/m/y h:m a'): string
Parameters:
$date(string): The date/time string to format.$format(string): The format to use. Default is 'd/m/y h:m a'.
Returns:
- (string): The formatted date and time string or an empty string if the input is empty.
format_datetime_ml
Formats a date and time string on multiple lines.
public static function format_datetime_ml($date, $format = 'd/m/y', $format2 = 'h:m a'): string
Parameters:
$date(string): The date/time string to format.$format(string): The format to use for the date. Default is 'd/m/y'.$format2(string): The format to use for the time. Default is 'h:m a'.
Returns:
- (string): The formatted date and time string with a line break between them, or an empty string if the input is empty.
format_daterange_str
Display a daterange in a compact format.
public static function format_daterange_str($start_date = '', $end_date = ''): string
Parameters:
$start_date(string): The start date string.$end_date(string): The end date string.
Returns:
- (string): The formatted date range string.
formatTimeRange
Given two time objects, return a formatted time range that is formatted nicely and compactly.
public static function formatTimeRange($t1, $t2): string
Parameters:
$t1(mixed): The start time (string or timestamp).$t2(mixed): The end time (string or timestamp).
Returns:
- (string): The formatted time range string.