From bbaf65234fc69effce584b6e6b89173693ad907a Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Mon, 1 Oct 2007 18:14:00 +0000 Subject: Added it::date() (and made it_text silent when texts.php is missing) --- it.class | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'it.class') diff --git a/it.class b/it.class index 3db36c1..952da9e 100644 --- a/it.class +++ b/it.class @@ -531,6 +531,39 @@ function gets() return $result; } +/** + * Output formatted and localized date + * @param format optional format (default is 2007-01-02 03:04:05). + * Other formats are "date", "datetime", "time". + * Formats can be qualified with language, e.g. "date:en" + * @param stamp optional unix timestamp (default is now). + * If it contains nondigits, it is fed to strtotime + */ +function date($format = "", $stamp = null) +{ + list($name, $language) = explode(":", $format); + + if ($format && !$language) + $language = T_lang(); + + $formats = array( + "" => "Y-m-d H:i:s", + "date" => "d.m.Y", + "datetime" => "d.m.Y H:i", + "time" => "H:i", + "date:en" => "m/d/Y", + "datetime:en" => "m/d/Y h:ia", + "time:en" => "h:ia", + ); + + if (!($formatstring = $formats["$name:$language"]) && !($formatstring = $formats[$name])) + $formatstring = $format; + + $stamp = !isset($stamp) ? time() : (it::match('^\d+$', $stamp) ? $stamp : strtotime($stamp)); + + return date($formatstring, $stamp); +} + } ?> -- cgit v1.2.3