// 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`
$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`
$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`
use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Protocol\PortableContact;
+use Friendica\Util\Temporal;
function poco_init(App $a) {
$system_mode = false;
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;
$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')",
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 . "'";
}
}
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)) {
$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";
}
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)) {
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.
}
/**
- * @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 $s Some parseable date/time string
+ * @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.
* 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');
}
}
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);
}
/**