Merge branch 'nulldate' into dev

This commit is contained in:
redmatrix
2016-09-26 18:17:38 -07:00
21 changed files with 155 additions and 149 deletions

View File

@@ -548,8 +548,8 @@ function account_approve($hash) {
*/
function downgrade_accounts() {
$r = q("select * from account where not ( account_flags & %d )>0
and account_expires != '%s'
$r = q("select * from account where not ( account_flags & %d ) > 0
and account_expires > '%s'
and account_expires < %s ",
intval(ACCOUNT_EXPIRED),
dbesc(NULL_DATE),

View File

@@ -1212,7 +1212,7 @@ function advanced_profile(&$a) {
if(App::$profile['partner'])
$profile['marital']['partner'] = bbcode(App::$profile['partner']);
if(strlen(App::$profile['howlong']) && App::$profile['howlong'] !== NULL_DATE) {
if(strlen(App::$profile['howlong']) && App::$profile['howlong'] > NULL_DATE) {
$profile['howlong'] = relative_date(App::$profile['howlong'], t('for %1$d %2$s'));
}

View File

@@ -721,7 +721,7 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $
'isotime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'c'),
'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
'editedtime' => (($item['edited'] != $item['created']) ? sprintf( t('last edited: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r')) : ''),
'expiretime' => (($item['expires'] !== NULL_DATE) ? sprintf( t('Expires: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['expires'], 'r')):''),
'expiretime' => (($item['expires'] > NULL_DATE) ? sprintf( t('Expires: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['expires'], 'r')):''),
'location' => $location,
'indent' => '',
'owner_name' => $owner_name,

View File

@@ -24,6 +24,13 @@ function timezone_cmp($a, $b) {
return ( t($a) < t($b)) ? -1 : 1;
}
function is_null_date($s) {
if($s === '0000-00-00 00:00:00' || $s === '0001-01-01 00:00:00')
return true;
return false;
}
/**
* @brief Return timezones grouped (primarily) by continent.
*
@@ -78,15 +85,20 @@ function datetime_convert($from = 'UTC', $to = 'UTC', $s = 'now', $fmt = "Y-m-d
if( ($s === '') || (! is_string($s)) )
$s = 'now';
if(is_null_date($s)) {
$d = new DateTime('0001-01-01 00:00:00', new DateTimeZone('UTC'));
return $d->format($fmt);
}
// Slight hackish adjustment so that 'zero' datetime actually returns what is intended
// 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.
if(substr($s,0,10) == '0000-00-00') {
$d = new DateTime($s . ' + 32 days', new DateTimeZone('UTC'));
return str_replace('1', '0', $d->format($fmt));
}
// if(substr($s,0,10) == '0000-00-00') {
// $d = new DateTime($s . ' + 32 days', new DateTimeZone('UTC'));
// return str_replace('1', '0', $d->format($fmt));
// }
try {
$from_obj = new DateTimeZone($from);
@@ -268,7 +280,7 @@ function relative_date($posted_date, $format = null) {
$abs = strtotime($localtime);
if (is_null($posted_date) || $posted_date === NULL_DATE || $abs === false) {
if (is_null($posted_date) || is_null_date($posted_date) || $abs === false) {
return t('never');
}

View File

@@ -86,7 +86,7 @@ class DBA {
abstract class dba_driver {
// legacy behavior
const INSTALL_SCRIPT='install/schema_mysql.sql';
const NULL_DATE = '0000-00-00 00:00:00';
const NULL_DATE = '0001-01-01 00:00:00';
const UTC_NOW = 'UTC_TIMESTAMP()';
protected $db;
@@ -276,12 +276,9 @@ function dbunescbin($str) {
}
function dbescdate($date) {
if(ACTIVE_DBTYPE == DBTYPE_POSTGRES && $date == '0000-00-00 00:00:00') {
$date = NULL_DATE;
} else if(ACTIVE_DBTYPE != DBTYPE_POSTGRES && $date == '0001-01-01 00:00:00') {
$date = NULL_DATE;
}
return $date;
if(is_null_date($date))
return $dba->escape(NULL_DATE);
return $dba->escape($date);
}
function db_quoteinterval($txt) {
@@ -376,11 +373,8 @@ function dbq($sql) {
function dbesc_array_cb(&$item, $key) {
if(is_string($item)) {
if($item == '0000-00-00 00:00:00' && ACTIVE_DBTYPE == DBTYPE_POSTGRES)
$item = '0001-01-01 00:00:00';
else if($item == '0001-01-01 00:00:00' && ACTIVE_DBTYPE == DBTYPE_MYSQL)
$item = '0000-00-00 00:00:00';
if(is_null_date($item))
$item = NULL_DATE;
$item = dbesc($item);
}
}

View File

@@ -227,7 +227,7 @@ function sync_directories($dirmode) {
$token = get_config('system','realm_token');
$syncdate = (($rr['site_sync'] === NULL_DATE) ? datetime_convert('UTC','UTC','now - 2 days') : $rr['site_sync']);
$syncdate = (($rr['site_sync'] <= NULL_DATE) ? datetime_convert('UTC','UTC','now - 2 days') : $rr['site_sync']);
$x = z_fetch_url($rr['site_directory'] . '?f=&sync=' . urlencode($syncdate) . (($token) ? '&t=' . $token : ''));
if (! $x['success'])

View File

@@ -33,7 +33,7 @@ function get_public_feed($channel, $params) {
// put a sane lower limit on feed requests if not specified
// if($params['begin'] === NULL_DATE)
// if($params['begin'] <= NULL_DATE)
// $params['begin'] = datetime_convert('UTC','UTC','now - 1 month');
switch($params['type']) {
@@ -884,7 +884,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) {
$datarray['owner_xchan'] = $contact['xchan_hash'];
if(array_key_exists('created',$datarray) && $datarray['created'] != NULL_DATE && $expire_days) {
if(array_key_exists('created',$datarray) && $datarray['created'] > NULL_DATE && $expire_days) {
$t1 = $datarray['created'];
$t2 = datetime_convert('UTC','UTC','now - ' . $expire_days . 'days');
if($t1 < $t2) {

View File

@@ -422,9 +422,9 @@ function sync_apps($channel,$apps) {
);
}
if(! $app['app_created'] || $app['app_created'] === NULL_DATE)
if((! $app['app_created']) || ($app['app_created'] <= NULL_DATE))
$app['app_created'] = datetime_convert();
if(! $app['app_edited'] || $app['app_edited'] === NULL_DATE)
if((! $app['app_edited']) || ($app['app_edited'] <= NULL_DATE))
$app['app_edited'] = datetime_convert();
$app['app_channel'] = $channel['channel_id'];
@@ -536,9 +536,9 @@ function sync_chatrooms($channel,$chatrooms) {
unset($chatroom['cr_aid']);
unset($chatroom['cr_uid']);
if(! $chatroom['cr_created'] || $chatroom['cr_created'] === NULL_DATE)
if((! $chatroom['cr_created']) || ($chatroom['cr_created'] <= NULL_DATE))
$chatroom['cr_created'] = datetime_convert();
if(! $chatroom['cr_edited'] || $chatroom['cr_edited'] === NULL_DATE)
if((! $chatroom['cr_edited']) || ($chatroom['cr_edited'] <= NULL_DATE))
$chatroom['cr_edited'] = datetime_convert();
$chatroom['cr_aid'] = $channel['channel_account_id'];

View File

@@ -163,7 +163,7 @@ function collect_recipients($item, &$private_envelope) {
}
function comments_are_now_closed($item) {
if($item['comments_closed'] !== NULL_DATE) {
if($item['comments_closed'] > NULL_DATE) {
$d = datetime_convert();
if($d > $item['comments_closed'])
return true;
@@ -1090,7 +1090,7 @@ function encode_item($item,$mirror = false) {
if($y = encode_item_flags($item))
$x['flags'] = $y;
if($item['comments_closed'] !== NULL_DATE)
if($item['comments_closed'] > NULL_DATE)
$x['comments_closed'] = $item['comments_closed'];
$x['public_scope'] = $scope;
@@ -1439,7 +1439,7 @@ function get_mail_elements($x) {
$arr['conv_guid'] = (($x['conv_guid'])? htmlspecialchars($x['conv_guid'],ENT_COMPAT,'UTF-8',false) : '');
$arr['created'] = datetime_convert('UTC','UTC',$x['created']);
if((! array_key_exists('expires',$x)) || ($x['expires'] === NULL_DATE))
if((! array_key_exists('expires',$x)) || ($x['expires'] <= NULL_DATE))
$arr['expires'] = NULL_DATE;
else
$arr['expires'] = datetime_convert('UTC','UTC',$x['expires']);
@@ -2065,7 +2065,7 @@ function item_store_update($arr,$allow_exec = false, $deliver = true) {
$arr['edited'] = ((x($arr,'edited') !== false) ? datetime_convert('UTC','UTC',$arr['edited']) : datetime_convert());
$arr['expires'] = ((x($arr,'expires') !== false) ? datetime_convert('UTC','UTC',$arr['expires']) : $orig[0]['expires']);
if(array_key_exists('comments_closed',$arr) && $arr['comments_closed'] != NULL_DATE)
if(array_key_exists('comments_closed',$arr) && $arr['comments_closed'] > NULL_DATE)
$arr['comments_closed'] = datetime_convert('UTC','UTC',$arr['comments_closed']);
else
$arr['comments_closed'] = $orig[0]['comments_closed'];
@@ -3832,7 +3832,7 @@ function zot_feed($uid,$observer_hash,$arr) {
$limit = " LIMIT 100 ";
if($mindate != NULL_DATE) {
if($mindate > NULL_DATE) {
$sql_extra .= " and ( created > '$mindate' or changed > '$mindate' ) ";
}