aboutsummaryrefslogtreecommitdiffstats
path: root/include/functions.inc.php
diff options
context:
space:
mode:
authormistic100 <mistic@piwigo.org>2014-07-07 09:54:15 +0000
committermistic100 <mistic@piwigo.org>2014-07-07 09:54:15 +0000
commit8a1ea2ad0aa4d513ebea0f2bc46b96bd4ddc504f (patch)
tree1c0bcbe3b1d7c8a1c464804de0fbb2a4826ef8f4 /include/functions.inc.php
parentfb4237b7861b818cc3d46d7cc0740d648e80ccd8 (diff)
feature 2807: nicer display of "from to" dates (required changes in "format_date" function)
git-svn-id: http://piwigo.org/svn/trunk@28981 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include/functions.inc.php')
-rw-r--r--include/functions.inc.php73
1 files changed, 62 insertions, 11 deletions
diff --git a/include/functions.inc.php b/include/functions.inc.php
index 65c248cf6..cc6dae20c 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -549,6 +549,11 @@ function str2DateTime($original, $format=null)
{
return false;
}
+
+ if ($original instanceof DateTime)
+ {
+ return $original;
+ }
if (!empty($format) && version_compare(PHP_VERSION, '5.3.0') >= 0)// from known date format
{
@@ -588,12 +593,12 @@ function str2DateTime($original, $format=null)
* returns a formatted and localized date for display
*
* @param int|string timestamp or datetime string
- * @param bool $show_time
- * @param bool $show_day_name
+ * @param array $show list of components displayed, default is ['day_name', 'day', 'month', 'year']
+ * THIS PARAMETER IS PLANNED TO CHANGE
* @param string $format input format respecting date() syntax
* @return string
*/
-function format_date($original, $show_time=false, $show_day_name=true, $format=null)
+function format_date($original, $show=null, $format=null)
{
global $lang;
@@ -604,22 +609,32 @@ function format_date($original, $show_time=false, $show_day_name=true, $format=n
return l10n('N/A');
}
- $print = '';
- if ($show_day_name)
+ if ($show === null)
{
- $print.= $lang['day'][ $date->format('w') ].' ';
+ $show = array('day_name', 'day', 'month', 'year');
}
- $print.= $date->format('j');
- $print.= ' '.$lang['month'][ $date->format('n') ];
- $print.= ' '.$date->format('Y');
+ // TODO use IntlDateFormatter for proper i18n
+
+ $print = '';
+ if (in_array('day_name', $show))
+ $print.= $lang['day'][ $date->format('w') ].' ';
+
+ if (in_array('day', $show))
+ $print.= $date->format('j').' ';
+
+ if (in_array('month', $show))
+ $print.= $lang['month'][ $date->format('n') ].' ';
- if ($show_time)
+ if (in_array('year', $show))
+ $print.= $date->format('Y').' ';
+
+ if (in_array('time', $show))
{
$temp = $date->format('H:i');
if ($temp != '00:00')
{
- $print.= ' '.$temp;
+ $print.= $temp.' ';
}
}
@@ -627,6 +642,42 @@ function format_date($original, $show_time=false, $show_day_name=true, $format=n
}
/**
+ * Format a "From ... to ..." string from two dates
+ * @param string $from
+ * @param string $to
+ * @param boolean $full
+ * @return string
+ */
+function format_fromto($from, $to, $full=false)
+{
+ $from = str2DateTime($from);
+ $to = str2DateTime($to);
+
+ if ($from->format('Y-m-d') == $to->format('Y-m-d'))
+ {
+ return format_date($from);
+ }
+ else
+ {
+ if ($full || $from->format('Y') != $to->format('Y'))
+ {
+ $from_str = format_date($from);
+ }
+ else if ($from->format('m') != $to->format('m'))
+ {
+ $from_str = format_date($from, array('day_name', 'day', 'month'));
+ }
+ else
+ {
+ $from_str = format_date($from, array('day_name', 'day'));
+ }
+ $to_str = format_date($to);
+
+ return l10n('from %s to %s', $from_str, $to_str);
+ }
+}
+
+/**
* Works out the time since the given date
*
* @param int|string timestamp or datetime string