X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fdatetime.php;h=3033b88afc816238ea7e0e4ada4b86fa92576c5b;hb=90870d4872dbc8ff408183a79fd005b905aa86c2;hp=f7be5bdb11666d789af3f3a908515671583b7af9;hpb=75a8b684fcb198f03a4dc2f208395179144f5fe7;p=friendica.git diff --git a/include/datetime.php b/include/datetime.php index f7be5bdb11..3033b88afc 100644 --- a/include/datetime.php +++ b/include/datetime.php @@ -65,9 +65,9 @@ if(! function_exists('datetime_convert')) { function datetime_convert($from = 'UTC', $to = 'UTC', $s = 'now', $fmt = "Y-m-d H:i:s") { // Slight hackish adjustment so that 'zero' datetime actually returns what is intended - // otherwise we end up with -0001-11-30 ... + // otherwise we end up with -0001-11-30 ... // add 32 days so that we at least get year 00, and then hack around the fact that - // months and days always start with 1. + // months and days always start with 1. if(substr($s,0,10) == '0000-00-00') { $d = new DateTime($s . ' + 32 days', new DateTimeZone('UTC')); @@ -84,12 +84,47 @@ function datetime_convert($from = 'UTC', $to = 'UTC', $s = 'now', $fmt = "Y-m-d function dob($dob) { list($year,$month,$day) = sscanf($dob,'%4d-%2d-%2d'); $y = datetime_convert('UTC',date_default_timezone_get(),'now','Y'); - $o = datesel('',1920,$y,true,$year,$month,$day); + $f = get_config('system','birthday_input_format'); + if(! $f) + $f = 'ymd'; + $o = datesel($f,'',1920,$y,true,$year,$month,$day); + return $o; +} + + +function datesel_format($f) { + + $o = ''; + + if(strlen($f)) { + for($x = 0; $x < strlen($f); $x ++) { + switch($f[$x]) { + case 'y': + if(strlen($o)) + $o .= '-'; + $o .= t('year'); + break; + case 'm': + if(strlen($o)) + $o .= '-'; + $o .= t('month'); + break; + case 'd': + if(strlen($o)) + $o .= '-'; + $o .= t('day'); + break; + default: + break; + } + } + } return $o; } // returns a date selector. +// $f = format string, e.g. 'ymd' or 'mdy' // $pre = prefix (if needed) for HTML name and class fields // $ymin = first year shown in selector dropdown // $ymax = last year shown in selector dropdown @@ -99,38 +134,84 @@ function dob($dob) { // $d = already selected day if(! function_exists('datesel')) { -function datesel($pre,$ymin,$ymax,$allow_blank,$y,$m,$d) { +function datesel($f,$pre,$ymin,$ymax,$allow_blank,$y,$m,$d) { $o = ''; - $o .= ""; + if($allow_blank) { + $sel = (($y == '0000') ? " selected=\"selected\" " : ""); + $o .= ""; + } + + if($ymax > $ymin) { + for($x = $ymax; $x >= $ymin; $x --) { + $sel = (($x == $y) ? " selected=\"selected\" " : ""); + $o .= ""; + } + } + else { + for($x = $ymax; $x <= $ymin; $x ++) { + $sel = (($x == $y) ? " selected=\"selected\" " : ""); + $o .= ""; + } + } + } + elseif($f[$z] == 'm') { + + $o .= " "; + return $o; +}} + +if(! function_exists('timesel')) { +function timesel($pre,$h,$m) { + + $o = ''; + $o .= " : "; return $o; }} + + + + + + + // implements "3 seconds ago" etc. // based on $posted_date, (UTC). // Results relative to current timezone @@ -142,6 +223,11 @@ function relative_date($posted_date) { $localtime = datetime_convert('UTC',date_default_timezone_get(),$posted_date); $abs = strtotime($localtime); + + if (is_null($posted_date) || $posted_date === '0000-00-00 00:00:00' || $abs === False) { + return t('never'); + } + $etime = time() - $abs; if ($etime < 1) { @@ -149,12 +235,12 @@ function relative_date($posted_date) { } $a = array( 12 * 30 * 24 * 60 * 60 => array( t('year'), t('years')), - 30 * 24 * 60 * 60 => array( t('month'), t('months')), - 7 * 24 * 60 * 60 => array( t('week'), t('weeks')), - 24 * 60 * 60 => array( t('day'), t('days')), - 60 * 60 => array( t('hour'), t('hours')), - 60 => array( t('minute'), t('minutes')), - 1 => array( t('second'), t('seconds')) + 30 * 24 * 60 * 60 => array( t('month'), t('months')), + 7 * 24 * 60 * 60 => array( t('week'), t('weeks')), + 24 * 60 * 60 => array( t('day'), t('days')), + 60 * 60 => array( t('hour'), t('hours')), + 60 => array( t('minute'), t('minutes')), + 1 => array( t('second'), t('seconds')) ); foreach ($a as $secs => $str) { @@ -242,7 +328,7 @@ function get_first_dim($y,$m) { if(! function_exists('cal')) { -function cal($y = 0,$m = 0, $links = false) { +function cal($y = 0,$m = 0, $links = false, $class='') { // month table - start at 1 to match human usage. @@ -272,7 +358,7 @@ function cal($y = 0,$m = 0, $links = false) { $tddate = intval(datetime_convert('UTC',date_default_timezone_get(),'now','j')); $str_month = day_translate($mtab[$m]); - $o = ''; + $o = '
'; $o .= ""; for($a = 0; $a < 7; $a ++) $o .= '';
$str_month $y
' . mb_substr(day_translate($dn[$a]),0,3,'UTF-8') . '