X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fdatetime.php;h=6461298ba2f155cc24db192554d6120c5e1dd2f9;hb=abe31d7e60b2c6640abf799f807b8258bed10ab8;hp=6d395fe3f25d06611d2c4f047c63bcc94f00e085;hpb=aaf5a81365b4cbcb3d1b9537b5544aeb5de66f4b;p=friendica.git diff --git a/include/datetime.php b/include/datetime.php index 6d395fe3f2..6461298ba2 100644 --- a/include/datetime.php +++ b/include/datetime.php @@ -19,7 +19,7 @@ if(! function_exists('select_timezone')) { function select_timezone($current = 'America/Los_Angeles') { $timezone_identifiers = DateTimeZone::listIdentifiers(); - + $o =''; +// if ($dob && $dob != '0000-00-00') +// $o = datesel($f,mktime(0,0,0,0,0,1900),mktime(),mktime(0,0,0,$month,$day,$year),'dob'); +// else +// $o = datesel($f,mktime(0,0,0,0,0,1900),mktime(),false,'dob'); 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 -// $allow_blank = allow an empty response on any field -// $y = already selected year -// $m = already selected month -// $d = already selected day - +/** + * returns a date selector + * @param $format + * format string, e.g. 'ymd' or 'mdy'. Not currently supported + * @param $min + * unix timestamp of minimum date + * @param $max + * unix timestap of maximum date + * @param $default + * unix timestamp of default date + * @param $id + * id and name of datetimepicker (defaults to "datetimepicker") + */ if(! function_exists('datesel')) { -function datesel($f,$pre,$ymin,$ymax,$allow_blank,$y,$m,$d) { - - $o = ''; - - if(strlen($f)) { - for($z = 0; $z < strlen($f); $z ++) { - if($f[$z] === 'y') { - - $o .= " "; - return $o; +function datesel($format, $min, $max, $default, $id = 'datepicker') { + return datetimesel($format,$min,$max,$default,$id,true,false, '',''); }} +/** + * returns a time selector + * @param $format + * format string, e.g. 'ymd' or 'mdy'. Not currently supported + * @param $h + * already selected hour + * @param $m + * already selected minute + * @param $id + * id and name of datetimepicker (defaults to "timepicker") + */ if(! function_exists('timesel')) { -function timesel($pre,$h,$m) { +function timesel($format, $h, $m, $id='timepicker') { + return datetimesel($format,new DateTime(),new DateTime(),new DateTime("$h:$m"),$id,false,true); +}} - $o = ''; - $o .= " : "; + $o = ''; + $dateformat = ''; + if($pickdate) $dateformat .= 'Y-m-d'; + if($pickdate && $picktime) $dateformat .= ' '; + if($picktime) $dateformat .= 'H:i'; + $minjs = $min ? ",minDate: new Date({$min->getTimestamp()}*1000), yearStart: " . $min->format('Y') : ''; + $maxjs = $max ? ",maxDate: new Date({$max->getTimestamp()}*1000), yearEnd: " . $max->format('Y') : ''; + + $input_text = $default ? 'value="' . date($dateformat, $default->getTimestamp()) . '"' : ''; + $defaultdatejs = $default ? ",defaultDate: new Date({$default->getTimestamp()}*1000)" : ''; + $pickers = ''; + if(!$pickdate) $pickers .= ',datepicker: false'; + if(!$picktime) $pickers .= ',timepicker: false'; + $extra_js = ''; + if($minfrom != '') + $extra_js .= "\$('#$minfrom').data('xdsoft_datetimepicker').setOptions({onChangeDateTime: function (currentDateTime) { \$('#$id').data('xdsoft_datetimepicker').setOptions({minDate: currentDateTime})}})"; + if($maxfrom != '') + $extra_js .= "\$('#$maxfrom').data('xdsoft_datetimepicker').setOptions({onChangeDateTime: function (currentDateTime) { \$('#$id').data('xdsoft_datetimepicker').setOptions({maxDate: currentDateTime})}})"; + $readable_format = $dateformat; + $readable_format = str_replace('Y','yyyy',$readable_format); + $readable_format = str_replace('m','mm',$readable_format); + $readable_format = str_replace('d','dd',$readable_format); + $readable_format = str_replace('H','HH',$readable_format); + $readable_format = str_replace('i','MM',$readable_format); + $o .= "
"; + $o .= '
'; + $o .= ""; return $o; }} - - - - - - - // implements "3 seconds ago" etc. // based on $posted_date, (UTC). // Results relative to current timezone // Limited to range of timestamps if(! function_exists('relative_date')) { -function relative_date($posted_date) { +function relative_date($posted_date,$format = null) { $localtime = datetime_convert('UTC',date_default_timezone_get(),$posted_date); @@ -250,6 +262,13 @@ function relative_date($posted_date) { return t('less than a second ago'); } + /* + $time_append = ''; + if ($etime >= 86400) { + $time_append = ' ('.$localtime.')'; + } + */ + $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')), @@ -264,7 +283,9 @@ function relative_date($posted_date) { if ($d >= 1) { $r = round($d); // translators - e.g. 22 hours ago, 1 minute ago - return sprintf( t('%1$d %2$s ago'),$r, (($r == 1) ? $str[0] : $str[1])); + if(! $format) + $format = t('%1$d %2$s ago'); + return sprintf( $format,$r, (($r == 1) ? $str[0] : $str[1])); } } }} @@ -435,11 +456,13 @@ function update_contact_birthdays() { * */ - $bdtext = t('Birthday:') . ' [url=' . $rr['url'] . ']' . $rr['name'] . '[/url]' ; + $bdtext = sprintf( t('%s\'s birthday'), $rr['name']); + $bdtext2 = sprintf( t('Happy Birthday %s'), ' [url=' . $rr['url'] . ']' . $rr['name'] . '[/url]') ; + - $r = q("INSERT INTO `event` (`uid`,`cid`,`created`,`edited`,`start`,`finish`,`desc`,`type`,`adjust`) - VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%d' ) ", + $r = q("INSERT INTO `event` (`uid`,`cid`,`created`,`edited`,`start`,`finish`,`summary`,`desc`,`type`,`adjust`) + VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d' ) ", intval($rr['uid']), intval($rr['id']), dbesc(datetime_convert()), @@ -447,14 +470,15 @@ function update_contact_birthdays() { dbesc(datetime_convert('UTC','UTC', $nextbd)), dbesc(datetime_convert('UTC','UTC', $nextbd . ' + 1 day ')), dbesc($bdtext), + dbesc($bdtext2), dbesc('birthday'), intval(0) ); - + // update bdyear - q("UPDATE `contact` SET `bdyear` = '%s', `bd` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1", + q("UPDATE `contact` SET `bdyear` = '%s', `bd` = '%s' WHERE `uid` = %d AND `id` = %d", dbesc(substr($nextbd,0,4)), dbesc($nextbd), intval($rr['uid']),