Move Temporal::convert() to DateTimeFormat::convert()

This commit is contained in:
Hypolite Petovan 2018-01-26 21:38:34 -05:00
parent b7a7355292
commit 5e7285b9ba
64 changed files with 568 additions and 551 deletions

View file

@ -36,8 +36,8 @@ use Friendica\Network\HTTPException\TooManyRequestsException;
use Friendica\Network\HTTPException\UnauthorizedException;
use Friendica\Object\Image;
use Friendica\Protocol\Diaspora;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\Temporal;
use Friendica\Util\XML;
require_once 'include/bbcode.php';
@ -111,7 +111,7 @@ function api_source()
function api_date($str)
{
// Wed May 23 06:01:13 +0000 2007
return Temporal::utc($str, "D M d H:i:s +0000 Y");
return DateTimeFormat::utc($str, "D M d H:i:s +0000 Y");
}
/**
@ -460,7 +460,7 @@ function api_rss_extra(App $a, $arr, $user_info)
'self' => System::baseUrl() . "/" . $a->query_string,
'base' => System::baseUrl(),
'updated' => api_date(null),
'atom_updated' => Temporal::utcNow(Temporal::ATOM),
'atom_updated' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
'language' => $user_info['language'],
'logo' => System::baseUrl() . "/images/friendica-32.png",
];
@ -1162,7 +1162,7 @@ function api_statuses_update($type)
// Check for throttling (maximum posts per day, week and month)
$throttle_day = Config::get('system', 'throttle_limit_day');
if ($throttle_day > 0) {
$datefrom = date(Temporal::MYSQL, time() - 24*60*60);
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60);
$r = q(
"SELECT COUNT(*) AS `posts_day` FROM `item` WHERE `uid`=%d AND `wall`
@ -1186,7 +1186,7 @@ function api_statuses_update($type)
$throttle_week = Config::get('system', 'throttle_limit_week');
if ($throttle_week > 0) {
$datefrom = date(Temporal::MYSQL, time() - 24*60*60*7);
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*7);
$r = q(
"SELECT COUNT(*) AS `posts_week` FROM `item` WHERE `uid`=%d AND `wall`
@ -1210,7 +1210,7 @@ function api_statuses_update($type)
$throttle_month = Config::get('system', 'throttle_limit_month');
if ($throttle_month > 0) {
$datefrom = date(Temporal::MYSQL, time() - 24*60*60*30);
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*30);
$r = q(
"SELECT COUNT(*) AS `posts_month` FROM `item` WHERE `uid`=%d AND `wall`
@ -3207,7 +3207,7 @@ function api_account_rate_limit_status($type)
'@attributes' => ["type" => "integer"],
'hourly-limit' => '150',
'@attributes2' => ["type" => "integer"],
'reset-time' => Temporal::utc('now + 1 hour', Temporal::ATOM),
'reset-time' => DateTimeFormat::utc('now + 1 hour', DateTimeFormat::ATOM),
'@attributes3' => ["type" => "datetime"],
'reset_time_in_seconds' => strtotime('now + 1 hour'),
'@attributes4' => ["type" => "integer"],
@ -3217,7 +3217,7 @@ function api_account_rate_limit_status($type)
'reset_time_in_seconds' => strtotime('now + 1 hour'),
'remaining_hits' => '150',
'hourly_limit' => '150',
'reset_time' => api_date(Temporal::utc('now + 1 hour', Temporal::ATOM)),
'reset_time' => api_date(DateTimeFormat::utc('now + 1 hour', DateTimeFormat::ATOM)),
];
}
@ -4216,7 +4216,7 @@ function api_fr_photo_create_update($type)
$result = q(
"UPDATE `photo` SET %s, `edited`='%s' WHERE `uid` = %d AND `resource-id` = '%s' AND `album` = '%s'",
$sql_extra,
Temporal::utcNow(), // update edited timestamp
DateTimeFormat::utcNow(), // update edited timestamp
intval(api_user()),
dbesc($photo_id),
dbesc($album)
@ -4420,7 +4420,7 @@ function api_account_update_profile_image($type)
q(
"UPDATE `contact` SET `avatar-date` = '%s' WHERE `self` = 1 AND `uid` = %d",
dbesc(Temporal::utcNow()),
dbesc(DateTimeFormat::utcNow()),
intval(local_user())
);

View file

@ -7,7 +7,7 @@ use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Model\Contact;
use Friendica\Network\Probe;
use Friendica\Util\Temporal;
use Friendica\Util\DateTimeFormat;
use League\HTMLToMarkdown\HtmlConverter;
require_once 'include/event.php';
@ -245,15 +245,15 @@ function format_event_diaspora($ev) {
// @todo What. Is. Going. On. With. This. Useless. Ternary. Operator? - mrpetovan
$o .= L10n::t('Starts:') . ' ' . '[' . day_translate(
$ev['adjust'] ? Temporal::utc($ev['start'], $bd_format) : Temporal::utc($ev['start'], $bd_format)
$ev['adjust'] ? DateTimeFormat::utc($ev['start'], $bd_format) : DateTimeFormat::utc($ev['start'], $bd_format)
)
. '](' . System::baseUrl() . '/localtime/?f=&time=' . urlencode(Temporal::utc($ev['start'])) . ")\n";
. '](' . System::baseUrl() . '/localtime/?f=&time=' . urlencode(DateTimeFormat::utc($ev['start'])) . ")\n";
if (! $ev['nofinish']) {
$o .= L10n::t('Finishes:') . ' ' . '[' . day_translate(
$ev['adjust'] ? Temporal::utc($ev['finish'], $bd_format) : Temporal::utc($ev['finish'], $bd_format)
$ev['adjust'] ? DateTimeFormat::utc($ev['finish'], $bd_format) : DateTimeFormat::utc($ev['finish'], $bd_format)
)
. '](' . System::baseUrl() . '/localtime/?f=&time=' . urlencode(Temporal::utc($ev['finish'])) . ")\n";
. '](' . System::baseUrl() . '/localtime/?f=&time=' . urlencode(DateTimeFormat::utc($ev['finish'])) . ")\n";
}
if (strlen($ev['location'])) {

View file

@ -17,7 +17,7 @@ use Friendica\Model\Profile;
use Friendica\Object\Post;
use Friendica\Util\XML;
use Friendica\Object\Thread;
use Friendica\Util\Temporal;
use Friendica\Util\DateTimeFormat;
require_once "include/bbcode.php";
require_once "include/acl_selectors.php";
@ -790,7 +790,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
'categories' => $categories,
'folders' => $folders,
'text' => strip_tags($body_e),
'localtime' => Temporal::local($item['created'], 'r'),
'localtime' => DateTimeFormat::local($item['created'], 'r'),
'ago' => (($item['app']) ? L10n::t('%s from %s', relative_date($item['created']),$item['app']) : relative_date($item['created'])),
'location' => $location_e,
'indent' => '',

View file

@ -4,7 +4,7 @@ use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Database\DBStructure;
use Friendica\Util\Temporal;
use Friendica\Util\DateTimeFormat;
require_once('include/datetime.php');
@ -190,7 +190,7 @@ class dba {
if ($log) {
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
@file_put_contents($a->config["system"]["db_log_index"], Temporal::utcNow()."\t".
@file_put_contents($a->config["system"]["db_log_index"], DateTimeFormat::utcNow()."\t".
$row['key']."\t".$row['rows']."\t".$row['Extra']."\t".
basename($backtrace[1]["file"])."\t".
$backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t".
@ -495,7 +495,7 @@ class dba {
$duration = round($duration, 3);
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
@file_put_contents($a->config["system"]["db_log"], Temporal::utcNow()."\t".$duration."\t".
@file_put_contents($a->config["system"]["db_log"], DateTimeFormat::utcNow()."\t".$duration."\t".
basename($backtrace[1]["file"])."\t".
$backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t".
substr(self::replace_parameters($sql, $args), 0, 2000)."\n", FILE_APPEND);

View file

@ -8,8 +8,8 @@ use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Emailer;
use Friendica\Util\Temporal;
require_once 'include/bbcode.php';
require_once 'include/html2bbcode.php';
@ -451,7 +451,7 @@ function notification($params)
$datarray['name_cache'] = strip_tags(bbcode($params['source_name']));
$datarray['url'] = $params['source_link'];
$datarray['photo'] = $params['source_photo'];
$datarray['date'] = Temporal::utcNow();
$datarray['date'] = DateTimeFormat::utcNow();
$datarray['uid'] = $params['uid'];
$datarray['link'] = $itemlink;
$datarray['iid'] = $item_id;

View file

@ -12,8 +12,8 @@ use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Model\Item;
use Friendica\Model\Profile;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Map;
use Friendica\Util\Temporal;
require_once 'include/bbcode.php';
require_once 'include/datetime.php';
@ -28,14 +28,14 @@ function format_event_html($ev, $simple = false) {
$event_start = day_translate(
$ev['adjust'] ?
Temporal::local($ev['start'], $bd_format)
: Temporal::utc($ev['start'], $bd_format)
DateTimeFormat::local($ev['start'], $bd_format)
: DateTimeFormat::utc($ev['start'], $bd_format)
);
$event_end = day_translate(
$ev['adjust'] ?
Temporal::local($ev['finish'], $bd_format)
: Temporal::utc($ev['finish'], $bd_format)
DateTimeFormat::local($ev['finish'], $bd_format)
: DateTimeFormat::utc($ev['finish'], $bd_format)
);
if ($simple) {
@ -61,13 +61,13 @@ function format_event_html($ev, $simple = false) {
$o .= '<div class="summary event-summary">' . bbcode($ev['summary']) . '</div>' . "\r\n";
$o .= '<div class="event-start"><span class="event-label">' . L10n::t('Starts:') . '</span>&nbsp;<span class="dtstart" title="'
. Temporal::utc($ev['start'], (($ev['adjust']) ? Temporal::ATOM : 'Y-m-d\TH:i:s' ))
. DateTimeFormat::utc($ev['start'], (($ev['adjust']) ? DateTimeFormat::ATOM : 'Y-m-d\TH:i:s' ))
. '" >'.$event_start
. '</span></div>' . "\r\n";
if (! $ev['nofinish']) {
$o .= '<div class="event-end" ><span class="event-label">' . L10n::t('Finishes:') . '</span>&nbsp;<span class="dtend" title="'
. Temporal::utc($ev['finish'], (($ev['adjust']) ? Temporal::ATOM : 'Y-m-d\TH:i:s' ))
. DateTimeFormat::utc($ev['finish'], (($ev['adjust']) ? DateTimeFormat::ATOM : 'Y-m-d\TH:i:s' ))
. '" >'.$event_end
. '</span></div>' . "\r\n";
}
@ -200,8 +200,8 @@ function sort_by_date($a) {
function ev_compare($a,$b) {
$date_a = (($a['adjust']) ? Temporal::local($a['start']) : $a['start']);
$date_b = (($b['adjust']) ? Temporal::local($b['start']) : $b['start']);
$date_a = (($a['adjust']) ? DateTimeFormat::local($a['start']) : $a['start']);
$date_b = (($b['adjust']) ? DateTimeFormat::local($b['start']) : $b['start']);
if ($date_a === $date_b) {
return strcasecmp($a['desc'], $b['desc']);
@ -244,8 +244,8 @@ function event_store($arr) {
$a = get_app();
$arr['created'] = (($arr['created']) ? $arr['created'] : Temporal::utcNow());
$arr['edited'] = (($arr['edited']) ? $arr['edited'] : Temporal::utcNow());
$arr['created'] = (($arr['created']) ? $arr['created'] : DateTimeFormat::utcNow());
$arr['edited'] = (($arr['edited']) ? $arr['edited'] : DateTimeFormat::utcNow());
$arr['type'] = (($arr['type']) ? $arr['type'] : 'event' );
$arr['cid'] = ((intval($arr['cid'])) ? intval($arr['cid']) : 0);
$arr['uri'] = (x($arr, 'uri') ? $arr['uri'] : item_new_uri($a->get_hostname(), $arr['uid']));
@ -595,15 +595,15 @@ function process_events($arr) {
$fmt = L10n::t('l, F j');
if (count($arr)) {
foreach ($arr as $rr) {
$j = (($rr['adjust']) ? Temporal::local($rr['start'], 'j') : Temporal::utc($rr['start'], 'j'));
$d = (($rr['adjust']) ? Temporal::local($rr['start'], $fmt) : Temporal::utc($rr['start'], $fmt));
$j = (($rr['adjust']) ? DateTimeFormat::local($rr['start'], 'j') : DateTimeFormat::utc($rr['start'], 'j'));
$d = (($rr['adjust']) ? DateTimeFormat::local($rr['start'], $fmt) : DateTimeFormat::utc($rr['start'], $fmt));
$d = day_translate($d);
$start = (($rr['adjust']) ? Temporal::local($rr['start'], 'c') : Temporal::utc($rr['start'], 'c'));
$start = (($rr['adjust']) ? DateTimeFormat::local($rr['start'], 'c') : DateTimeFormat::utc($rr['start'], 'c'));
if ($rr['nofinish']) {
$end = null;
} else {
$end = (($rr['adjust']) ? Temporal::local($rr['finish'], 'c') : Temporal::utc($rr['finish'], 'c'));
$end = (($rr['adjust']) ? DateTimeFormat::local($rr['finish'], 'c') : DateTimeFormat::utc($rr['finish'], 'c'));
}
$is_first = ($d !== $last_date);
@ -930,27 +930,27 @@ function format_event_item($item) {
// Convert the time to different formats.
$dtstart_dt = day_translate(
$item['event-adjust'] ?
Temporal::local($item['event-start'], $dformat)
: Temporal::utc($item['event-start'], $dformat)
DateTimeFormat::local($item['event-start'], $dformat)
: DateTimeFormat::utc($item['event-start'], $dformat)
);
$dtstart_title = Temporal::utc($item['event-start'], $item['event-adjust'] ? Temporal::ATOM : 'Y-m-d\TH:i:s');
$dtstart_title = DateTimeFormat::utc($item['event-start'], $item['event-adjust'] ? DateTimeFormat::ATOM : 'Y-m-d\TH:i:s');
// Format: Jan till Dec.
$month_short = day_short_translate(
$item['event-adjust'] ?
Temporal::local($item['event-start'], 'M')
: Temporal::utc($item['event-start'], 'M')
DateTimeFormat::local($item['event-start'], 'M')
: DateTimeFormat::utc($item['event-start'], 'M')
);
// Format: 1 till 31.
$date_short = $item['event-adjust'] ?
Temporal::local($item['event-start'], 'j')
: Temporal::utc($item['event-start'], 'j');
DateTimeFormat::local($item['event-start'], 'j')
: DateTimeFormat::utc($item['event-start'], 'j');
$start_time = $item['event-adjust'] ?
Temporal::local($item['event-start'], $tformat)
: Temporal::utc($item['event-start'], $tformat);
DateTimeFormat::local($item['event-start'], $tformat)
: DateTimeFormat::utc($item['event-start'], $tformat);
$start_short = day_short_translate(
$item['event-adjust'] ?
Temporal::local($item['event-start'], $dformat_short)
: Temporal::utc($item['event-start'], $dformat_short)
DateTimeFormat::local($item['event-start'], $dformat_short)
: DateTimeFormat::utc($item['event-start'], $dformat_short)
);
// If the option 'nofinisch' isn't set, we need to format the finish date/time.
@ -958,18 +958,18 @@ function format_event_item($item) {
$finish = true;
$dtend_dt = day_translate(
$item['event-adjust'] ?
Temporal::local($item['event-finish'], $dformat)
: Temporal::utc($item['event-finish'], $dformat)
DateTimeFormat::local($item['event-finish'], $dformat)
: DateTimeFormat::utc($item['event-finish'], $dformat)
);
$dtend_title = Temporal::utc($item['event-finish'], $item['event-adjust'] ? Temporal::ATOM : 'Y-m-d\TH:i:s');
$dtend_title = DateTimeFormat::utc($item['event-finish'], $item['event-adjust'] ? DateTimeFormat::ATOM : 'Y-m-d\TH:i:s');
$end_short = day_short_translate(
$item['event-adjust'] ?
Temporal::local($item['event-finish'], $dformat_short)
: Temporal::utc($item['event-finish'], $dformat_short)
DateTimeFormat::local($item['event-finish'], $dformat_short)
: DateTimeFormat::utc($item['event-finish'], $dformat_short)
);
$end_time = $item['event-adjust'] ?
Temporal::local($item['event-finish'], $tformat)
: Temporal::utc($item['event-finish'], $tformat);
DateTimeFormat::local($item['event-finish'], $tformat)
: DateTimeFormat::utc($item['event-finish'], $tformat);
// Check if start and finish time is at the same day.
if (substr($dtstart_title, 0, 10) === substr($dtend_title, 0, 10)) {
$same_date = true;

View file

@ -9,22 +9,14 @@ use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\PConfig;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\Conversation;
use Friendica\Model\GContact;
use Friendica\Model\Group;
use Friendica\Model\Item;
use Friendica\Model\Term;
use Friendica\Model\User;
use Friendica\Object\Image;
use Friendica\Protocol\DFRN;
use Friendica\Protocol\Feed;
use Friendica\Util\Network;
use Friendica\Protocol\OStatus;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\ParseUrl;
use Friendica\Util\Temporal;
require_once 'include/bbcode.php';
require_once 'include/tags.php';
@ -416,7 +408,7 @@ function drop_item($id) {
/* arrange the list in years */
function list_post_dates($uid, $wall) {
$dnow = Temporal::localNow('Y-m-d');
$dnow = DateTimeFormat::localNow('Y-m-d');
$dthen = Item::firstPostDate($uid, $wall);
if (!$dthen) {
@ -437,14 +429,14 @@ function list_post_dates($uid, $wall) {
$dyear = intval(substr($dnow, 0, 4));
$dstart = substr($dnow, 0, 8) . '01';
$dend = substr($dnow, 0, 8) . get_dim(intval($dnow), intval(substr($dnow, 5)));
$start_month = Temporal::utc($dstart, 'Y-m-d');
$end_month = Temporal::utc($dend, 'Y-m-d');
$str = day_translate(Temporal::utc($dnow, 'F'));
$start_month = DateTimeFormat::utc($dstart, 'Y-m-d');
$end_month = DateTimeFormat::utc($dend, 'Y-m-d');
$str = day_translate(DateTimeFormat::utc($dnow, 'F'));
if (!$ret[$dyear]) {
$ret[$dyear] = [];
}
$ret[$dyear][] = [$str, $end_month, $start_month];
$dnow = Temporal::utc($dnow . ' -1 month', 'Y-m-d');
$dnow = DateTimeFormat::utc($dnow . ' -1 month', 'Y-m-d');
}
return $ret;
}
@ -474,7 +466,7 @@ function posted_date_widget($url, $uid, $wall) {
return $o;
}
$cutoff_year = intval(Temporal::localNow('Y')) - $visible_years;
$cutoff_year = intval(DateTimeFormat::localNow('Y')) - $visible_years;
$cutoff = ((array_key_exists($cutoff_year, $ret))? true : false);
$o = replace_macros(get_markup_template('posted_date_widget.tpl'),[

View file

@ -10,7 +10,7 @@ use Friendica\Core\PConfig;
use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Model\Group;
use Friendica\Util\Temporal;
use Friendica\Util\DateTimeFormat;
/**
* @brief Calculate the hash that is needed for the "Friendica" cookie
@ -142,10 +142,10 @@ function authenticate_success($user_record, $login_initial = false, $interactive
header('X-Account-Management-Status: active; name="' . $a->user['username'] . '"; id="' . $a->user['nickname'] . '"');
if ($login_initial || $login_refresh) {
dba::update('user', ['login_date' => Temporal::utcNow()], ['uid' => $_SESSION['uid']]);
dba::update('user', ['login_date' => DateTimeFormat::utcNow()], ['uid' => $_SESSION['uid']]);
// Set the login date for all identities of the user
dba::update('user', ['login_date' => Temporal::utcNow()],
dba::update('user', ['login_date' => DateTimeFormat::utcNow()],
['password' => $master_record['password'], 'email' => $master_record['email'], 'account_removed' => false]);
}

View file

@ -15,8 +15,8 @@ use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Model\Profile;
use Friendica\Model\Term;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Map;
use Friendica\Util\Temporal;
require_once "mod/proxy.php";
require_once "include/conversation.php";
@ -723,7 +723,7 @@ function logger($msg, $level = 0) {
$callers = debug_backtrace();
$logline = sprintf("%s@%s\t[%s]:%s:%s:%s\t%s\n",
Temporal::utcNow(Temporal::ATOM),
DateTimeFormat::utcNow(DateTimeFormat::ATOM),
$process_id,
$LOGGER_LEVELS[$level],
basename($callers[0]['file']),
@ -789,7 +789,7 @@ function dlogger($msg, $level = 0) {
$callers = debug_backtrace();
$logline = sprintf("%s@\t%s:\t%s:\t%s\t%s\t%s\n",
Temporal::utcNow(),
DateTimeFormat::utcNow(),
$process_id,
basename($callers[0]['file']),
$callers[0]['line'],