Add Temporal::MYSQL constant

- Rename Temporal::convert() parameter names
This commit is contained in:
Hypolite Petovan 2018-01-25 22:05:05 -05:00
parent b854905150
commit 38ff1b455b
5 changed files with 21 additions and 20 deletions

View file

@ -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("Y-m-d H:i:s", time() - 24*60*60);
$datefrom = date(Temporal::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("Y-m-d H:i:s", time() - 24*60*60*7);
$datefrom = date(Temporal::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("Y-m-d H:i:s", time() - 24*60*60*30);
$datefrom = date(Temporal::MYSQL, time() - 24*60*60*30);
$r = q(
"SELECT COUNT(*) AS `posts_month` FROM `item` WHERE `uid`=%d AND `wall`

View file

@ -9,6 +9,7 @@ use Friendica\Core\Config;
use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Protocol\PortableContact;
use Friendica\Util\Temporal;
function poco_init(App $a) {
$system_mode = false;
@ -43,7 +44,7 @@ function poco_init(App $a) {
if ($a->argc > 1 && $a->argv[1] === '@global') {
// List of all profiles that this server recently had data from
$global = true;
$update_limit = date("Y-m-d H:i:s", time() - 30 * 86400);
$update_limit = date(Temporal::MYSQL, time() - 30 * 86400);
}
if ($a->argc > 2 && $a->argv[2] === '@me') {
$justme = true;
@ -80,7 +81,7 @@ function poco_init(App $a) {
$sql_extra = sprintf(" AND `contact`.`id` = %d ", intval($cid));
}
if (x($_GET, 'updatedSince')) {
$update_limit = date("Y-m-d H:i:s", strtotime($_GET['updatedSince']));
$update_limit = date(Temporal::MYSQL, strtotime($_GET['updatedSince']));
}
if ($global) {
$contacts = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `updated` >= '%s' AND `updated` >= `last_failure` AND NOT `hide` AND `network` IN ('%s', '%s', '%s')",

View file

@ -236,7 +236,7 @@ function profile_content(App $a, $update = 0)
if ($is_owner || !$last_updated) {
$sql_extra4 = " AND `item`.`unseen`";
} else {
$gmupdate = gmdate("Y-m-d H:i:s", $last_updated);
$gmupdate = gmdate(Temporal::MYSQL, $last_updated);
$sql_extra4 = " AND `item`.`received` > '" . $gmupdate . "'";
}

View file

@ -144,7 +144,7 @@ class PortableContact
}
if (isset($entry->updated)) {
$updated = date("Y-m-d H:i:s", strtotime($entry->updated));
$updated = date(Temporal::MYSQL, strtotime($entry->updated));
}
if (isset($entry->network)) {
@ -1507,7 +1507,7 @@ class PortableContact
$timeframe = 30;
}
$updatedSince = date("Y-m-d H:i:s", time() - $timeframe * 86400);
$updatedSince = date(Temporal::MYSQL, time() - $timeframe * 86400);
// Fetch all global contacts from the other server (Not working with Redmatrix and Friendica versions before 3.3)
$url = $server["poco"]."/@global?updatedSince=".$updatedSince."&fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation";
@ -1654,7 +1654,7 @@ class PortableContact
}
if (isset($entry->updated)) {
$updated = date("Y-m-d H:i:s", strtotime($entry->updated));
$updated = date(Temporal::MYSQL, strtotime($entry->updated));
}
if (isset($entry->network)) {

View file

@ -22,6 +22,7 @@ require_once 'include/text.php';
class Temporal
{
const ATOM = 'Y-m-d\TH:i:s\Z';
const MYSQL = 'Y-m-d H:i:s';
/**
* @brief Two-level sort for timezones.
@ -123,17 +124,17 @@ class Temporal
}
/**
* @brief General purpose date parse/convert function.
* @brief General purpose date parse/convert/format function.
*
* @param string $s Some parseable date/time string
* @param string $from Source timezone
* @param string $to Dest timezone
* @param string $fmt Output format recognised from php's DateTime class
* @param string $tz_to Destination timezone
* @param string $tz_from Source timezone
* @param string $format Output format recognised from php's DateTime class
* http://www.php.net/manual/en/datetime.format.php
*
* @return string Formatted date according to given format
*/
public static function convert($s = 'now', $to = 'UTC', $from = 'UTC', $fmt = "Y-m-d H:i:s")
public static function convert($s = 'now', $tz_to = 'UTC', $tz_from = 'UTC', $format = self::MYSQL)
{
// Defaults to UTC if nothing is set, but throws an exception if set to empty string.
// Provide some sane defaults regardless.
@ -155,14 +156,13 @@ class Temporal
* 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.
*/
if (substr($s, 0, 10) <= '0001-01-01') {
$d = new DateTime($s . ' + 32 days', new DateTimeZone('UTC'));
return str_replace('1', '0', $d->format($fmt));
return str_replace('1', '0', $d->format($format));
}
try {
$from_obj = new DateTimeZone($from);
$from_obj = new DateTimeZone($tz_from);
} catch (Exception $e) {
$from_obj = new DateTimeZone('UTC');
}
@ -175,14 +175,14 @@ class Temporal
}
try {
$to_obj = new DateTimeZone($to);
$to_obj = new DateTimeZone($tz_to);
} catch (Exception $e) {
$to_obj = new DateTimeZone('UTC');
}
$d->setTimeZone($to_obj);
return $d->format($fmt);
return $d->format($format);
}
/**