summaryrefslogtreecommitdiff
path: root/program/include
diff options
context:
space:
mode:
authorthomascube <thomas@roundcube.net>2012-03-14 21:33:05 +0000
committerthomascube <thomas@roundcube.net>2012-03-14 21:33:05 +0000
commita621a9d7ecf334c4894ef8f5168eb6208e5ae0e4 (patch)
tree63c1d62c4c5b5e7578fb2b418df92964e70b478e /program/include
parent6699a68da187285bc2ea1571d4ffa970f2075bd6 (diff)
Accept DateTime object as input to format_date()
Diffstat (limited to 'program/include')
-rw-r--r--program/include/main.inc30
1 files changed, 19 insertions, 11 deletions
diff --git a/program/include/main.inc b/program/include/main.inc
index 798a1fe0e..ecb46ab25 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -725,7 +725,7 @@ function rcube_strtotime($date)
* Convert the given date to a human readable form
* This uses the date formatting properties from config
*
- * @param mixed Date representation (string or timestamp)
+ * @param mixed Date representation (string, timestamp or DateTime object)
* @param string Date format to use
* @param bool Enables date convertion according to user timezone
*
@@ -735,23 +735,31 @@ function format_date($date, $format=NULL, $convert=true)
{
global $RCMAIL, $CONFIG;
- if (!empty($date))
- $ts = rcube_strtotime($date);
+ if (is_a($date, 'DateTime')) {
+ $ts = $date->format('U');
+ $tzs = $date->getTimezone();
+ }
+ else {
+ $tzs = 'GMT';
- if (empty($ts))
- return '';
+ if (!empty($date))
+ $ts = rcube_strtotime($date);
- try {
- $date = new DateTime("@".$ts);
- }
- catch (Exception $e) {
- return '';
+ if (empty($ts))
+ return '';
+
+ try {
+ $date = new DateTime("@".$ts);
+ }
+ catch (Exception $e) {
+ return '';
+ }
}
try {
// convert to the right timezone
$stz = date_default_timezone_get();
- $tz = new DateTimeZone($convert ? $RCMAIL->config->get('timezone') : 'GMT');
+ $tz = new DateTimeZone($convert ? $RCMAIL->config->get('timezone') : $tzs);
$date->setTimezone($tz);
date_default_timezone_set($tz->getName());