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));
}
} }
} }
@ -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 ();
@ -404,7 +421,6 @@ if ( !function_exists ('codepot_find_matching_sequences'))
} }
} }
return $result; return $result;
} }
} }
@ -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">';