Methods
-
date
Returns date as string according to the specified format.
-
format
Returns time as string according to the specified format.
-
getDefaultTimeZone
Returns the default time zone using PHP function
date_default_timezone_get
. -
getFormat
Returns format strings for PHP function
date
corresponding to formats used by Webasyst framework. -
getFormatJS
Returns format strings for date/time formatting by means of JavaScript code corresponding to formats used by Webasyst framework.
-
getTimeZones
Returns the list of available time zones with localized descriptions.
-
parse
Returns time value, formatted using one of the formats supported by Webasyst framework, as a string acceptable by standard PHP functions.
-
getWeekdayNames
Returns the names of days of the week.
-
getMonthNames
Returns month names.
public static function date ($format, $time = null, $timezone = null, $locale = null)
Returns date as string according to the specified format.
Parameters
-
$format
Date format. Format symbols acceptable for PHP function
date
are supported. To display month name in lowercase, character f should be used. -
$time
Unix timestamp. If not specified, current timestamp is used.
-
$timezone
Time zone identifier. If not specified, the time zone is determined automatically.
-
$locale
Locale identifier. If not specified, the current user locale is determined automatically.
Example
waDateTime::date('F j, Y', '06-11-2013')
Result
November 6, 2013
public static function format ($format, $time = null, $timezone = null, $locale = null)
Returns time as string according to the specified format.
Parameters
-
$format
Date/time format. The following format strings are acceptable:
humandatetime
: adds words "yesterday", "today", "tomorrow" instead of appropriate dates relative to the current user datehumandate
: returns the date in formatd f Y
supported by methoddate
(format strings listed below are also supported by that method)date
: returns date/time in formatY-m-d
time
: returns date/time in formatH:i
fulltime
: returns date/time in formatH:i:s
datetime
: returns date/time in formatY-m-d H:i
fulldatetime
: returns date/time in formatY-m-d H:i:s
timestamp
: returns date/time in formatU
-
$time
Unix timestamp. If not specified, current timestamp is used.
-
$timezone
Time zone identifier. If not specified, the time zone is determined automatically.
-
$locale
Locale identifier. If not specifed, the current user locale is determined automatically.
Example
waDateTime::format('humandatetime')
Result
Today 17:11
PHP functions
function wa_date ($format, $time = null, $timezone = null, $locale = null)
Wrapper for method format.
Example
wa_date('humandatetime')
Result
Today 17:11
Smarty modifiers
{$timestamp |wa_date [:format='date' :$timezone=null :$locale=null]}
Formats a timestamp using method format. By default, format string date
is used.
Example
{'1384761717'|wa_date}
Result
11/18/2013
{$timestamp |wa_datetime [:format='datetime' :$timezone=null :$locale=null]}
Formats a timestamp using method format. By default, format string datetime
is used..
Example
{'1384761717'|wa_datetime}
Result
11/18/2013 12:01
public static function getDefaultTimeZone()
Returns the default time zone using PHP function date_default_timezone_get
.
Example
waDateTime::getDefaultTimeZone()
Result
America/New_York
public static function getFormat ($format, $locale = null)
Returns format strings for PHP function date
corresponding to formats used by Webasyst framework.
Parameters
-
$format
Time format strings used in Webasyst framework including the following options: sub-array
date_formats
keys specified in config file located inwa-system/locale/data/
, PHP classDateTime
constants, format strings acceptable for PHP functiondate
, or one of the identifiers corresponding to pre-defined time formatting strings supported by method format. -
$locale
Locale identifier. If not specifed, the current user locale is determined automatically.
Example
waDateTime::getFormat ('humandate', 'en_US')
Result
F j, Y
public static function getFormatJS ($format, $locale = null)
Returns format strings for date/time formatting by means of JavaScript code corresponding to formats used by Webasyst framework.
Parameters
-
$format
Format string accepted by parameter
$format
of method getFormat. -
$locale
Locale identifier. If not specifed, the current user locale is determined automatically.
Example
waDateTime::getFormatJS ('humandate', 'en_US')
Result
MM d, yy
public static function getTimeZones()
Returns the list of available time zones with localized descriptions.
Example
waDateTime::getTimeZones()
Result
[ [Pacific/Apia] => −11 Apia, Midway, Niue, Pago Pago [Pacific/Fakaofo] => −10 Fakaofo, Honolulu, Johnston, Rarotonga, Tahiti [America/Adak] => −09 Adak [Pacific/Gambier] => −09 Gambier, Marquesas [America/Anchorage] => −08 Anchorage, Juneau, Nome, Sitka, Yakutat [Pacific/Pitcairn] => −08 Pitcairn [America/Dawson] => −07 Dawson, Dawson Creek, Hermosillo, Los Angeles, Metlakatla ... [Pacific/Efate] => +11 Efate, Guadalcanal, Kosrae, Norfolk, Noumea [Pacific/Pohnpei] => +11 Pohnpei [Antarctica/McMurdo] => +12 McMurdo, South Pole [Asia/Anadyr] => +12 Anadyr, Kamchatka, Magadan [Pacific/Auckland] => +12 Auckland, Chatham, Fiji, Funafuti, Kwajalein [Pacific/Majuro] => +12 Majuro, Nauru, Tarawa, Wake, Wallis [Pacific/Enderbury] => +13 Enderbury, Tongatapu [Pacific/Kiritimati] => +14 Kiritimati ]
public static function parse ($format, $string, $timezone = null, $locale = null)
Returns time value, formatted using one of the formats supported by Webasyst framework, as a string acceptable by standard PHP functions.
Parameters
-
$format
Format string accepted by format except for
humandatetime
. -
$string
Date/time value string formatted to match the format identifier specified in
$format
parameter. -
$timezone
Time zone identifier. If not specified, the time zone is determined automatically.
-
$locale
Locale identifier. If not specifed, the current user locale is determined automatically.
Example
waDateTime::parse ('humandate', 'November 8, 2013', null, 'en_US')
Result
2013-11-08
PHP functions
function wa_parse_date ($format, $string, $timezone = null, $locale = null)
Wrapper for calling method parse.
Example
wa_parse_date ('humandate', 'November 8, 2013', null, 'en_US')
Result
2013-11-08
public static function getWeekdayNames ($case = 'ucfirst', $length = 'full')
Returns the names of days of the week.
Parameters
-
$case
Case of letters in the names of days:
- 'ucfirst': first letter in the upper case, other letters in the lower case;
- 'lower': all letters in the lower case.
-
$length
Length of the names of days:
- 'full': full names;
- any other value: brief names.
Example
waDateTime::getWeekdayNames()
Result
[ 1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday', 7 => 'Sunday', ]
Example
waDateTime::getWeekdayNames('lower', false)
Result
[ 1 => 'mon', 2 => 'tue', 3 => 'wed', 4 => 'thu', 5 => 'fri', 6 => 'sat', 7 => 'sun', ]
public static function getMonthNames ($n = 1, $case = 'ucfirst')
Returns month names.
Parameters
-
$n
Number denoting the month name form:
- 1: default form; e.g., “January”.
- 2: additional form for locales using f for a month name in the
date_formats[humandate]
parameter in their configuration.
-
$case
Case of letters in month names:
- 'ucfirst': first letter in the upper case, other letters in the lower case;
- 'lower': all letters in the lower case.
Example
waDateTime::getMonthNames()
Result
[ 1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April', 5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August', 9 => 'September', 10 => 'October', 11 => 'November', 12 => 'December', ]