Recently working on times and dates on my version and thought i'd share
This is for a test site only and re-writes lots of files we need a mass file editor
If testing backup ALL files, V3 uses utc for unix but this update makes it more universal and some of the times/dates are complex this sets a common approach
This mod is installed here working fully its in progress because it will cause errors due to some of the complex time eg date(time(date)) this is why we have the update.
fixing the errors is easy and ill post a few examples
when looking through errors we just need to remember do we want time (int) or date (string)
If you test please post any errors for my to add - posting just the line is enough the dates are easy to fix
in backend/functions.php search
replace with - we dont need to check for method above php 4
remove
remove
remove
remove
find
replace with
now for the mass edit search and replace the following in order
find
to
find
to
find
to
find
to
find
to
find
to
find
to
so example was
$deadtime = get_date_time(gmtime() - CONFIG['ANNOUNCEINTERVAL']);
should
$deadtime = date("Y-m-d H:i:s", time() - CONFIG['ANNOUNCEINTERVAL']);
some dates are more complex then they need to be - which might cause a few errors which are easy to solve - this is why its testing for v3 - I leave a guide at the bottom
example of error - we no longer need date
was
$added = date("M d, Y", utc_to_tz_time($row['added']));
should be
$added = user_timezone_date($row['added']);
guide
for insert we use time() for int & date() for date
to return date from int we use
to return string from time we use
to return user Timezone date we use
to return user Timezone time (number) we use
This is for a test site only and re-writes lots of files we need a mass file editor
If testing backup ALL files, V3 uses utc for unix but this update makes it more universal and some of the times/dates are complex this sets a common approach
This mod is installed here working fully its in progress because it will cause errors due to some of the complex time eg date(time(date)) this is why we have the update.
fixing the errors is easy and ill post a few examples
when looking through errors we just need to remember do we want time (int) or date (string)
If you test please post any errors for my to add - posting just the line is enough the dates are easy to fix
in backend/functions.php search
if (function_exists("date_default_timezone_set"))
date_default_timezone_set("Europe/London");
replace with - we dont need to check for method above php 4
date_default_timezone_set('Europe/London');
remove
function gmtime() {
return sql_timestamp_to_unix_timestamp(get_date_time());
}
remove
function sql_timestamp_to_unix_timestamp($s){
return mktime(substr($s, 11, 2), substr($s, 14, 2), substr($s, 17, 2), substr($s, 5, 2), substr($s, 8, 2), substr($s, 0, 4));
}
remove
function get_date_time($timestamp = 0){
if ($timestamp)
return date("Y-m-d H:i:s", $timestamp);
else
return gmdate("Y-m-d H:i:s");
}
remove
// Convert UTC to user's timezone
function utc_to_tz ($timestamp=0) {
GLOBAL $CURUSER, $tzs;
if (method_exists("DateTime", "setTimezone")) {
if (!$timestamp)
$timestamp = get_date_time();
$date = new DateTime($timestamp, new DateTimeZone("UTC"));
$date->setTimezone(new DateTimeZone($CURUSER ? $tzs[$CURUSER["tzoffset"]][1] : "Europe/London"));
return $date->format('Y-m-d H:i:s');
}
if (!is_numeric($timestamp))
$timestamp = sql_timestamp_to_unix_timestamp($timestamp);
if ($timestamp == 0)
$timestamp = gmtime();
$timestamp = $timestamp + ($CURUSER['tzoffset']*60);
if (date("I")) $timestamp += 3600; // DST Fix
return date("Y-m-d H:i:s", $timestamp);
}
find
function utc_to_tz_time ($timestamp=0) {
GLOBAL $CURUSER, $tzs;
if (method_exists("DateTime", "setTimezone")) {
if (!$timestamp)
$timestamp = get_date_time();
$date = new DateTime($timestamp, new DateTimeZone("UTC"));
$date->setTimezone(new DateTimeZone($CURUSER ? $tzs[$CURUSER["tzoffset"]][1] : "Europe/London"));
return sql_timestamp_to_unix_timestamp($date->format('Y-m-d H:i:s'));
}
if (!is_numeric($timestamp))
$timestamp = sql_timestamp_to_unix_timestamp($timestamp);
if ($timestamp == 0)
$timestamp = gmtime();
$timestamp = $timestamp + ($CURUSER['tzoffset']*60);
if (date("I")) $timestamp += 3600; // DST Fix
return $timestamp;
}
replace with
// Get Date By User Timezone
function user_timezone_date($timestamp, $return_int = false)
{
if (!is_numeric($timestamp)) {
$timestamp = strtotime($timestamp); // date to time
}
$timestamp = $timestamp + ($_SESSION['tzoffset']*60); // do time adjust
/*
if (date("I")) {
$timestamp += 3600; // DST Fix
}
*/
if ($return_int) {
return $timestamp;
}
return date("Y-m-d H:i:s", $timestamp);
}
now for the mass edit search and replace the following in order
find
get_date_time()
to
date()find
get_date_time( to
date("Y-m-d H:i:s", find
gmdate( to
date(find
gmtime() to
time()find
sql_timestamp_to_unix_timestamp( to
strtotime(find
utc_to_tz_time( to
user_timezone_datefind
utc_to_tz( to
user_timezone_dateso example was
$deadtime = get_date_time(gmtime() - CONFIG['ANNOUNCEINTERVAL']);
should
$deadtime = date("Y-m-d H:i:s", time() - CONFIG['ANNOUNCEINTERVAL']);
some dates are more complex then they need to be - which might cause a few errors which are easy to solve - this is why its testing for v3 - I leave a guide at the bottom
example of error - we no longer need date
was
$added = date("M d, Y", utc_to_tz_time($row['added']));
should be
$added = user_timezone_date($row['added']);
guide
for insert we use time() for int & date() for date
to return date from int we use
date("Y-m-d H:i:s", $int_var)to return string from time we use
strtotime($date_var);to return user Timezone date we use
user_timezone_date($row['added']);to return user Timezone time (number) we use
user_timezone_date($row['added'], true);
Last edited by M-jay
on 2024-09-20 16:28:24
on 2024-09-20 16:28:24