fixed some date/time display bugs when database_store_gmt is yes.

added codepot_unixtimetodispdate() 
minimized use of strftime() in favor of codepot_unixtimetodispdate() and codepot_dbdatetodispdate()
This commit is contained in:
hyung-hwan 2016-12-17 12:16:31 +00:00
parent 750db30352
commit d86921ba28
10 changed files with 60 additions and 56 deletions

View File

@ -58,19 +58,38 @@ if ( ! function_exists('codepot_unixtimetodbdate'))
} }
} }
if ( ! function_exists('codepot_unixtimetodispdate'))
{
function codepot_unixtimetodispdate($unixtime, $format = NULL, $timezone = NULL)
{
if ($timezone != NULL && function_exists('date_create'))
{
$d = @date_create ('@' . $unixtime);
if ($d !== FALSE)
{
$tz = @timezone_open ($timezone);
if ($tz !== FALSE)
{
@date_timezone_set ($d, $tz);
$ts = @date_format ($d, ($format == NULL? 'Y-m-d H:i:s O': $format));
if ($ts !== FALSE) return $ts;
}
}
}
// display time is in the local time zone or in the given time zone.
// if DateTime is not available, $timezone is ignored.
return date(($format == NULL? 'Y-m-d H:i:s O': $format), $unixtime);
}
}
if ( ! function_exists('codepot_dbdatetodispdate')) if ( ! function_exists('codepot_dbdatetodispdate'))
{ {
function codepot_dbdatetodispdate($dbdate, $format = NULL) function codepot_dbdatetodispdate($dbdate, $format = NULL, $timezone = NULL)
{ {
// display time is in the local time zone. if (CODEPOT_DATABASE_STORE_GMT) $dbdate .= ' +0000';
if (CODEPOT_DATABASE_STORE_GMT) $unixtime = strtotime($dbdate);
{ return codepot_unixtimetodispdate ($unixtime, $format, $timezone);
return strftime(($format == NULL? '%Y-%m-%d %H:%M:%S %z': $format), strtotime($dbdate . ' +0000'));
}
else
{
return strftime(($format == NULL? '%Y-%m-%d %H:%M:%S %z': $format), strtotime($dbdate));
}
} }
} }
@ -127,7 +146,7 @@ if ( !function_exists ('codepot_json_encode'))
$json .= sprintf("\\u%04x", ($c1 - 192) * 64 + $c2 - 128); $json .= sprintf("\\u%04x", ($c1 - 192) * 64 + $c2 - 128);
continue; continue;
} }
# Triple # Triple
$c3 = ord($string[++$i]); $c3 = ord($string[++$i]);
if( ($c1 & 16) === 0 ) if( ($c1 & 16) === 0 )
@ -183,7 +202,7 @@ if ( !function_exists ('codepot_delete_files'))
} }
} }
@closedir($current_dir); @closedir($current_dir);
if ($del_dir == TRUE /*&& $level > 0*/) if ($del_dir == TRUE /*&& $level > 0*/)
{ {
@rmdir($path); @rmdir($path);
@ -276,8 +295,6 @@ if ( !function_exists ('codepot_unzip_file'))
$zip = new ZipArchive(); $zip = new ZipArchive();
if ($zip->open ($path) === FALSE) return FALSE; if ($zip->open ($path) === FALSE) return FALSE;
if ($zip->extractTo ($output_dir) === FALSE) if ($zip->extractTo ($output_dir) === FALSE)
{ {
$zip->close (); $zip->close ();
@ -289,7 +306,7 @@ if ( !function_exists ('codepot_unzip_file'))
{ {
array_push ($names, $zip->getNameIndex($i)); array_push ($names, $zip->getNameIndex($i));
} }
$zip->close (); $zip->close ();
return $names; return $names;
} }
@ -346,7 +363,7 @@ if ( !function_exists ('codepot_find_matching_sequences'))
{ {
$stack = array (); $stack = array ();
$result = array (); $result = array ();
if (is_array($old) && is_array($new)) if (is_array($old) && is_array($new))
{ {
$old_size = count($old); $old_size = count($old);
@ -361,14 +378,14 @@ if ( !function_exists ('codepot_find_matching_sequences'))
{ {
return FALSE; return FALSE;
} }
// push the whole range for the initial search. // push the whole range for the initial search.
array_push ($stack, array (0, 0, $old_size, 0, $new_size)); array_push ($stack, array (0, 0, $old_size, 0, $new_size));
while (count($stack) > 0) while (count($stack) > 0)
{ {
$item = array_pop($stack); $item = array_pop($stack);
if ($item[0] == 0) if ($item[0] == 0)
{ {
$old_seg_pos = $item[1]; $old_seg_pos = $item[1];
@ -403,8 +420,7 @@ if ( !function_exists ('codepot_find_matching_sequences'))
array_push ($result, array_slice ($item, 1, 3)); array_push ($result, array_slice ($item, 1, 3));
} }
} }
return $result; return $result;
} }
} }
@ -535,10 +551,10 @@ if ( ! function_exists('codepot_readfile'))
header ("HTTP/1.0 505 Internal server error"); header ("HTTP/1.0 505 Internal server error");
return; return;
} }
$begin = 0; $begin = 0;
$end = $size; $end = $size;
if (isset($_SERVER['HTTP_RANGE'])) if (isset($_SERVER['HTTP_RANGE']))
{ {
if (preg_match('/bytes=\h*(\d+)-(\d*)[\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches)) if (preg_match('/bytes=\h*(\d+)-(\d*)[\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches))
@ -547,9 +563,9 @@ if ( ! function_exists('codepot_readfile'))
if (!empty($matches[2])) $end = intval($matches[2]) + 1; if (!empty($matches[2])) $end = intval($matches[2]) + 1;
} }
} }
if ($end < $begin) $end = $begin; if ($end < $begin) $end = $begin;
if ($begin > 0 || $end < $size) if ($begin > 0 || $end < $size)
{ {
header('HTTP/1.0 206 Partial Content'); header('HTTP/1.0 206 Partial Content');
@ -558,7 +574,7 @@ if ( ! function_exists('codepot_readfile'))
{ {
header('HTTP/1.0 200 OK'); header('HTTP/1.0 200 OK');
} }
header("Content-Type: $mimeType"); header("Content-Type: $mimeType");
header('Cache-Control: public, must-revalidate, max-age=0'); header('Cache-Control: public, must-revalidate, max-age=0');
header('Pragma: no-cache'); header('Pragma: no-cache');
@ -570,16 +586,16 @@ if ( ! function_exists('codepot_readfile'))
header("Last-Modified: $time"); header("Last-Modified: $time");
header('Connection: close'); header('Connection: close');
flush (); flush ();
$cur = $begin; $cur = $begin;
fseek ($fm, $begin, 0); fseek ($fm, $begin, 0);
while (!feof($fm) && $cur < $end && (connection_status()==0)) while (!feof($fm) && $cur < $end && (connection_status()==0))
{ {
$len = min(1024*16,$end-$cur); $len = min(1024*16,$end-$cur);
$x = fread ($fm, $len); $x = fread ($fm, $len);
if ($x === FALSE) break; if ($x === FALSE) break;
print $x; print $x;
$cur += $len; $cur += $len;
} }
@ -588,6 +604,4 @@ if ( ! function_exists('codepot_readfile'))
} }
} }
} }

View File

@ -249,7 +249,7 @@ $this->load->view (
print '<div class="metadata-commit-date">'; print '<div class="metadata-commit-date">';
printf ('[%s] ', $file['created_rev']); printf ('[%s] ', $file['created_rev']);
print strftime ('%Y-%m-%d %H:%M:%S %z', $file['time_t']); print codepot_unixtimetodispdate ($file['time_t']);
print '</div>'; print '</div>';
?> ?>
<div style='clear: both'></div> <div style='clear: both'></div>

View File

@ -242,7 +242,7 @@ $this->load->view (
print '<div class="metadata-commit-date">'; print '<div class="metadata-commit-date">';
printf ('[%s] ', $file['against']['created_rev']); printf ('[%s] ', $file['against']['created_rev']);
print strftime ('%Y-%m-%d %H:%M:%S %z', $file['against']['time_t']); print codepot_unixtimetodispdate ($file['against']['time_t']);
print '</div>' print '</div>'
?> ?>
@ -280,7 +280,7 @@ $this->load->view (
print '<div class="metadata-commit-date">'; print '<div class="metadata-commit-date">';
printf ('[%s] ', $file['created_rev']); printf ('[%s] ', $file['created_rev']);
print strftime ('%Y-%m-%d %H:%M:%S %z', $file['time_t']); print codepot_unixtimetodispdate ($file['time_t']);
print '</div>' print '</div>'
?> ?>

View File

@ -623,7 +623,7 @@ $this->load->view (
print '<div class="metadata-commit-date">'; print '<div class="metadata-commit-date">';
printf ('[%s] ', $file['created_rev']); printf ('[%s] ', $file['created_rev']);
print strftime ('%Y-%m-%d %H:%M:%S %z', $file['time_t']); print codepot_unixtimetodispdate ($file['time_t']);
print '</div>'; print '</div>';
?> ?>
<div style='clear: both'></div> <div style='clear: both'></div>

View File

@ -1002,7 +1002,7 @@ $this->load->view (
print '<div class="metadata-commit-date">'; print '<div class="metadata-commit-date">';
printf ('[%s] ', $file['created_rev']); printf ('[%s] ', $file['created_rev']);
print strftime ('%Y-%m-%d %H:%M:%S %z', strtotime($file['last_changed_date'])); print codepot_unixtimetodispdate(strtotime($file['last_changed_date']));
print '</div>'; print '</div>';
?> ?>
<div style='clear: both;'></div> <div style='clear: both;'></div>
@ -1207,7 +1207,7 @@ $this->load->view (
print htmlspecialchars($f['last_author']); print htmlspecialchars($f['last_author']);
print '</td>'; print '</td>';
print '<td><tt>'; print '<td><tt>';
print strftime('%Y-%m-%d', $f['time_t']); print codepot_unixtimetodispdate ($f['time_t'], 'Y-m-d');
print '</tt></td>'; print '</tt></td>';
print '<td></td>'; print '<td></td>';
print '<td></td>'; print '<td></td>';
@ -1243,7 +1243,7 @@ $this->load->view (
print htmlspecialchars($f['last_author']); print htmlspecialchars($f['last_author']);
print '</td>'; print '</td>';
print '<td><tt>'; print '<td><tt>';
print strftime('%Y-%m-%d', $f['time_t']); print codepot_unixtimetodispdate ($f['time_t'], 'Y-m-d');
print '</tt></td>'; print '</tt></td>';
print '<td>'; print '<td>';

View File

@ -154,7 +154,7 @@ $this->load->view (
print '</td>'; print '</td>';
print '<td class="commit-date-td"><tt>'; print '<td class="commit-date-td"><tt>';
print strftime('%Y-%m-%d', strtotime($h['date'])); print codepot_unixtimetodispdate(strtotime($h['date']), 'Y-m-d');
print '</tt></td>'; print '</tt></td>';
print '<td class="commit-message-td">'; print '<td class="commit-message-td">';

View File

@ -665,7 +665,7 @@ $history = $file['history'];
print '<div class="metadata-commit-date">'; print '<div class="metadata-commit-date">';
printf ('[%s] ', $history['rev']); printf ('[%s] ', $history['rev']);
print strftime ('%Y-%m-%d %H:%M:%S %z', strtotime($history['date'])); print codepot_unixtimetodispdate (strtotime($history['date']));
print '</div>'; print '</div>';
?> ?>

View File

@ -177,14 +177,9 @@ $this->load->view (
{ {
if ($log['type'] == 'code') $code = $log['message']; if ($log['type'] == 'code') $code = $log['message'];
if (CODEPOT_DATABASE_STORE_GMT) $tzoff = codepot_dbdatetodispdate ($log['createdon'], 'O');
$createdon = $log['createdon'] . ' +0000'; $date = codepot_dbdatetodispdate ($log['createdon'], 'Y-m-d');
else $time = codepot_dbdatetodispdate ($log['createdon'], 'H:i:s');
$createdon = $log['createdon'];
$tzoff = strftime ('%z', strtotime($createdon));
$date = strftime ('%Y-%m-%d', strtotime($createdon));
$time = strftime ('%H:%M:%S', strtotime($createdon));
if ($curdate != $date) if ($curdate != $date)
{ {

View File

@ -220,7 +220,7 @@ foreach ($urls as $url)
foreach ($log_entries as $log) foreach ($log_entries as $log)
{ {
$createdon_mmdd = codepot_dbdatetodispdate ($log['createdon'], '%m-%d'); $createdon_mmdd = codepot_dbdatetodispdate ($log['createdon'], 'm-d');
if ($log['type'] == 'code') if ($log['type'] == 'code')
{ {

View File

@ -357,18 +357,13 @@ $this->load->view (
$xdot = $this->converter->AsciiToHex ('.'); $xdot = $this->converter->AsciiToHex ('.');
foreach ($log_entries as $log) foreach ($log_entries as $log)
{ {
if (CODEPOT_DATABASE_STORE_GMT)
$createdon = $log['createdon'] . ' +0000';
else
$createdon = $log['createdon'];
if ($log['type'] == 'code') if ($log['type'] == 'code')
{ {
$x = $log['message']; $x = $log['message'];
print '<tr class="odd">'; print '<tr class="odd">';
print '<td class="date">'; print '<td class="date">';
print strftime ('%m-%d', strtotime($createdon)); print codepot_dbdatetodispdate ($log['createdon'], 'Y-m-d');
print '</td>'; print '</td>';
print '<td class="projectid">'; print '<td class="projectid">';
/* /*
@ -428,7 +423,7 @@ $this->load->view (
{ {
print '<tr class="odd">'; print '<tr class="odd">';
print '<td class="date">'; print '<td class="date">';
print strftime ('%m-%d', strtotime($createdon)); print codepot_dbdatetodispdate ($log['createdon'], 'Y-m-d');
print '</td>'; print '</td>';
print '<td class="project">'; print '<td class="project">';