Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
Date & Time Update V3 [IN PROGRESS]
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / Torrent Trader / v3 Mods in Progress

2024-09-12 06:31:12
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

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_date

find
utc_to_tz( 

to
user_timezone_date


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
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 warn on 2024-09-20 16:28:24
2024-09-12 10:04:48
Nice to see you back, mate...


www.exyusubs.com
TorrentTrader V3.8.3 (SE)
OS: AlmaLinux 9.9 (BC)
Apache version: 2.4.71
PHP version: 8.5.13 (PHP-FPM)
MySQL version: 10.11.18-MariaDB
Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 2
  • Members: 0
  • Guests online: 2
  • Comments: 3
  • Messages: 1,728