Format
Format
Format values based on locale and system settings.
- Full name: \Gibbon\Services\Format
Methods
- setup — Sets the internal formatting options from an array.
- setupFromSession — Sets the formatting options from session i18n and database settings.
- date — Formats a YYYY-MM-DD date with the language-specific format. Optionally provide a format string to use instead.
- dateConvert — Converts a date in the language-specific format to YYYY-MM-DD.
- dateTime — Formats a YYYY-MM-DD H:I:S MySQL timestamp as a readable string. Optionally provide a format string to use.
- dateReadable — Formats a YYYY-MM-DD date as a readable string with month names.
- dateRange — Formats two YYYY-MM-DD dates with the language-specific format. Optionally provide a format string to use instead.
- dateRangeReadable — Formats two YYYY-MM-DD dates as a readable string, collapsing same months and same years.
- dateFromTimestamp — Formats a Unix timestamp as the language-specific format. Optionally provide a format string to use instead.
- timestamp — Converts a YYYY-MM-DD date to a Unix timestamp.
- time — Formats a time from a given MySQL time or timestamp value.
- timeRange — Formats a range of times from two given MySQL time or timestamp values.
- number — Formats a number to an optional decimal points.
- currency — Formats a currency with a symbol and two decimals, optionally displaying the currency name in brackets.
- yesNo — Formats a Y/N value as Yes or No in the current language.
- link — Formats a link from a url. Automatically adds target _blank to external links.
- age — Formats a YYYY-MM-DD date as a relative age with years and months.
- phone — Formats phone numbers, optionally including countrt code and types.
- address — Formats an address including optional district and country.
- name — Formats a name based on the provided Role Category. Optionally reverses the name (surname first) or uses an informal format (no title).
- nameList — Formats a list of names from an array containing standard title, preferredName & surname fields.
- userPhoto — Returns an HTML based on the supplied photo path, using a placeholder image if none exists. Size may be either 75 or 240 at this time.
- userStatusInfo
- courseClassName — Returns the course and class name concatenated with a . (dot). The separator could become a setting at some point?
Inherited from FormatResolver
setup
Sets the internal formatting options from an array.
static Format::setup( array $settings )
- This method is static.
setupFromSession
Sets the formatting options from session i18n and database settings.
static Format::setupFromSession( \Gibbon\Session $session )
- This method is static.
date
Formats a YYYY-MM-DD date with the language-specific format. Optionally provide a format string to use instead.
static Format::date( string $dateString, string $format = false ): string
- This method is static.
Return Value:
string
dateConvert
Converts a date in the language-specific format to YYYY-MM-DD.
static Format::dateConvert( string $dateString ): string
- This method is static.
Return Value:
string
dateTime
Formats a YYYY-MM-DD H:I:S MySQL timestamp as a readable string. Optionally provide a format string to use.
static Format::dateTime( string $dateString, string $format = false ): string
- This method is static.
Return Value:
string
dateReadable
Formats a YYYY-MM-DD date as a readable string with month names.
static Format::dateReadable( string $dateString ): string
- This method is static.
Return Value:
string
dateRange
Formats two YYYY-MM-DD dates with the language-specific format. Optionally provide a format string to use instead.
static Format::dateRange( string $dateFrom, string $dateTo, $format = false ): string
- This method is static.
Return Value:
string
dateRangeReadable
Formats two YYYY-MM-DD dates as a readable string, collapsing same months and same years.
static Format::dateRangeReadable( string $dateFrom, string $dateTo ): string
- This method is static.
Return Value:
string
dateFromTimestamp
Formats a Unix timestamp as the language-specific format. Optionally provide a format string to use instead.
static Format::dateFromTimestamp( string|integer $timestamp, string $format = false ): string
- This method is static.
Return Value:
string
timestamp
Converts a YYYY-MM-DD date to a Unix timestamp.
static Format::timestamp( $dateString ): string
- This method is static.
Return Value:
string
time
Formats a time from a given MySQL time or timestamp value.
static Format::time( string $timeString, string|boolean $format = false ): string
- This method is static.
Return Value:
string
timeRange
Formats a range of times from two given MySQL time or timestamp values.
static Format::timeRange( string $timeFrom, string $timeTo, string|boolean $format = false ): string
- This method is static.
Return Value:
string
number
Formats a number to an optional decimal points.
static Format::number( integer|string $value, integer $decimals ): string
- This method is static.
Return Value:
string
currency
Formats a currency with a symbol and two decimals, optionally displaying the currency name in brackets.
static Format::currency( string|integer $value, boolean $includeName = false ): string
- This method is static.
Return Value:
string
yesNo
Formats a Y/N value as Yes or No in the current language.
static Format::yesNo( string $value, boolean $translate = true ): string
- This method is static.
Return Value:
string
link
Formats a link from a url. Automatically adds target _blank to external links.
static Format::link( string $url, string $text = '', string $title = '' ): string
- This method is static.
Return Value:
string
age
Formats a YYYY-MM-DD date as a relative age with years and months.
static Format::age( string $dateString, boolean $short = false ): string
- This method is static.
Return Value:
string
phone
Formats phone numbers, optionally including countrt code and types.
static Format::phone( string|integer $number, boolean $countryCode = false, boolean $type = false ): string
Adds spaces to 7-10 digit numbers based on the most common global formats.
- This method is static.
Return Value:
string
address
Formats an address including optional district and country.
static Format::address( string $address, string $addressDistrict, string $addressCountry ): string
- This method is static.
Return Value:
string
name
Formats a name based on the provided Role Category. Optionally reverses the name (surname first) or uses an informal format (no title).
static Format::name( string $title, string $preferredName, string $surname, string $roleCategory = 'Staff', boolean $reverse = false, boolean $informal = false ): string
- This method is static.
Return Value:
string
nameList
Formats a list of names from an array containing standard title, preferredName & surname fields.
static Format::nameList( array $list, string $roleCategory = 'Staff', boolean $reverse = false, boolean $informal = false ): string
- This method is static.
Return Value:
string
userPhoto
Returns an HTML based on the supplied photo path, using a placeholder image if none exists. Size may be either 75 or 240 at this time.
static Format::userPhoto( string $path, integer $size = 75 ): string
- This method is static.
Return Value:
string
userStatusInfo
static Format::userStatusInfo( $person = array() )
- This method is static.
courseClassName
Returns the course and class name concatenated with a . (dot). The separator could become a setting at some point?
static Format::courseClassName( string $courseName, string $className ): string
- This method is static.
Return Value:
string