summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Schneider2007-10-01 18:14:00 +0000
committerChristian Schneider2007-10-01 18:14:00 +0000
commitbbaf65234fc69effce584b6e6b89173693ad907a (patch)
tree6f6d0173fa5db1b3f9868e41afd6fcd074a3c34f
parente11cbb4456fcd49f4375982a962c72ff10b80934 (diff)
downloaditools-bbaf65234fc69effce584b6e6b89173693ad907a.tar.gz
itools-bbaf65234fc69effce584b6e6b89173693ad907a.tar.bz2
itools-bbaf65234fc69effce584b6e6b89173693ad907a.zip
Added it::date() (and made it_text silent when texts.php is missing)
-rw-r--r--it.class33
-rw-r--r--it_text.class4
2 files changed, 35 insertions, 2 deletions
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);
+}
+
}
?>
diff --git a/it_text.class b/it_text.class
index 76e8aed..de3fe52 100644
--- a/it_text.class
+++ b/it_text.class
@@ -34,10 +34,10 @@ function it_text($p = null)
# Read $this->statictext from php file if it's not defined yet
if (!$this->statictext)
- include($this->p['phpfile']);
+ @include($this->p['phpfile']);
# Get array of supported languages and their names
- $this->languages_available = $this->statictext['_'];
+ $this->languages_available = (array)$this->statictext['_'];
foreach($this->languages_available as $code => $languagename)
{
# Only use a language in browser/cookie detection below if it's not disabled by a leading '-'