From d86921ba287147d1696127d79ceddf3c1c5c4691 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sat, 17 Dec 2016 12:16:31 +0000 Subject: [PATCH] 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() --- .../src/codepot/helpers/codepot_helper.php | 76 +++++++++++-------- codepot/src/codepot/views/code_blame.php | 2 +- codepot/src/codepot/views/code_diff.php | 4 +- codepot/src/codepot/views/code_file.php | 2 +- codepot/src/codepot/views/code_folder.php | 6 +- codepot/src/codepot/views/code_history.php | 2 +- codepot/src/codepot/views/code_revision.php | 2 +- codepot/src/codepot/views/log.php | 11 +-- codepot/src/codepot/views/project_home.php | 2 +- codepot/src/codepot/views/site_home.php | 9 +-- 10 files changed, 60 insertions(+), 56 deletions(-) diff --git a/codepot/src/codepot/helpers/codepot_helper.php b/codepot/src/codepot/helpers/codepot_helper.php index ed81f0c5..3310b34c 100644 --- a/codepot/src/codepot/helpers/codepot_helper.php +++ b/codepot/src/codepot/helpers/codepot_helper.php @@ -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')) { - 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) - { - 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)); - } + if (CODEPOT_DATABASE_STORE_GMT) $dbdate .= ' +0000'; + $unixtime = strtotime($dbdate); + return codepot_unixtimetodispdate ($unixtime, $format, $timezone); } } @@ -127,7 +146,7 @@ if ( !function_exists ('codepot_json_encode')) $json .= sprintf("\\u%04x", ($c1 - 192) * 64 + $c2 - 128); continue; } - + # Triple $c3 = ord($string[++$i]); if( ($c1 & 16) === 0 ) @@ -183,7 +202,7 @@ if ( !function_exists ('codepot_delete_files')) } } @closedir($current_dir); - + if ($del_dir == TRUE /*&& $level > 0*/) { @rmdir($path); @@ -276,8 +295,6 @@ if ( !function_exists ('codepot_unzip_file')) $zip = new ZipArchive(); if ($zip->open ($path) === FALSE) return FALSE; - - if ($zip->extractTo ($output_dir) === FALSE) { $zip->close (); @@ -289,7 +306,7 @@ if ( !function_exists ('codepot_unzip_file')) { array_push ($names, $zip->getNameIndex($i)); } - + $zip->close (); return $names; } @@ -346,7 +363,7 @@ if ( !function_exists ('codepot_find_matching_sequences')) { $stack = array (); $result = array (); - + if (is_array($old) && is_array($new)) { $old_size = count($old); @@ -361,14 +378,14 @@ if ( !function_exists ('codepot_find_matching_sequences')) { return FALSE; } - + // push the whole range for the initial search. array_push ($stack, array (0, 0, $old_size, 0, $new_size)); - + while (count($stack) > 0) { $item = array_pop($stack); - + if ($item[0] == 0) { $old_seg_pos = $item[1]; @@ -403,8 +420,7 @@ if ( !function_exists ('codepot_find_matching_sequences')) array_push ($result, array_slice ($item, 1, 3)); } } - - + return $result; } } @@ -535,10 +551,10 @@ if ( ! function_exists('codepot_readfile')) header ("HTTP/1.0 505 Internal server error"); return; } - + $begin = 0; $end = $size; - + if (isset($_SERVER['HTTP_RANGE'])) { 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 ($end < $begin) $end = $begin; - + if ($begin > 0 || $end < $size) { header('HTTP/1.0 206 Partial Content'); @@ -558,7 +574,7 @@ if ( ! function_exists('codepot_readfile')) { header('HTTP/1.0 200 OK'); } - + header("Content-Type: $mimeType"); header('Cache-Control: public, must-revalidate, max-age=0'); header('Pragma: no-cache'); @@ -570,16 +586,16 @@ if ( ! function_exists('codepot_readfile')) header("Last-Modified: $time"); header('Connection: close'); flush (); - + $cur = $begin; fseek ($fm, $begin, 0); - + while (!feof($fm) && $cur < $end && (connection_status()==0)) { $len = min(1024*16,$end-$cur); $x = fread ($fm, $len); if ($x === FALSE) break; - + print $x; $cur += $len; } @@ -588,6 +604,4 @@ if ( ! function_exists('codepot_readfile')) } } - } - diff --git a/codepot/src/codepot/views/code_blame.php b/codepot/src/codepot/views/code_blame.php index a546ffc9..11832d49 100644 --- a/codepot/src/codepot/views/code_blame.php +++ b/codepot/src/codepot/views/code_blame.php @@ -249,7 +249,7 @@ $this->load->view ( print '
'; printf ('[%s] ', $file['created_rev']); - print strftime ('%Y-%m-%d %H:%M:%S %z', $file['time_t']); + print codepot_unixtimetodispdate ($file['time_t']); print '
'; ?>
diff --git a/codepot/src/codepot/views/code_diff.php b/codepot/src/codepot/views/code_diff.php index 01375cea..c1c631ed 100644 --- a/codepot/src/codepot/views/code_diff.php +++ b/codepot/src/codepot/views/code_diff.php @@ -242,7 +242,7 @@ $this->load->view ( print '
'; 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 '
' ?> @@ -280,7 +280,7 @@ $this->load->view ( print '
'; printf ('[%s] ', $file['created_rev']); - print strftime ('%Y-%m-%d %H:%M:%S %z', $file['time_t']); + print codepot_unixtimetodispdate ($file['time_t']); print '
' ?> diff --git a/codepot/src/codepot/views/code_file.php b/codepot/src/codepot/views/code_file.php index 3ab16739..d443e49e 100644 --- a/codepot/src/codepot/views/code_file.php +++ b/codepot/src/codepot/views/code_file.php @@ -623,7 +623,7 @@ $this->load->view ( print '
'; printf ('[%s] ', $file['created_rev']); - print strftime ('%Y-%m-%d %H:%M:%S %z', $file['time_t']); + print codepot_unixtimetodispdate ($file['time_t']); print '
'; ?>
diff --git a/codepot/src/codepot/views/code_folder.php b/codepot/src/codepot/views/code_folder.php index 16785f16..9700076b 100644 --- a/codepot/src/codepot/views/code_folder.php +++ b/codepot/src/codepot/views/code_folder.php @@ -1002,7 +1002,7 @@ $this->load->view ( print '
'; 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 '
'; ?>
@@ -1207,7 +1207,7 @@ $this->load->view ( print htmlspecialchars($f['last_author']); print ''; print ''; - print strftime('%Y-%m-%d', $f['time_t']); + print codepot_unixtimetodispdate ($f['time_t'], 'Y-m-d'); print ''; print ''; print ''; @@ -1243,7 +1243,7 @@ $this->load->view ( print htmlspecialchars($f['last_author']); print ''; print ''; - print strftime('%Y-%m-%d', $f['time_t']); + print codepot_unixtimetodispdate ($f['time_t'], 'Y-m-d'); print ''; print ''; diff --git a/codepot/src/codepot/views/code_history.php b/codepot/src/codepot/views/code_history.php index d37c59ce..290241d3 100644 --- a/codepot/src/codepot/views/code_history.php +++ b/codepot/src/codepot/views/code_history.php @@ -154,7 +154,7 @@ $this->load->view ( print ''; print ''; - print strftime('%Y-%m-%d', strtotime($h['date'])); + print codepot_unixtimetodispdate(strtotime($h['date']), 'Y-m-d'); print ''; print ''; diff --git a/codepot/src/codepot/views/code_revision.php b/codepot/src/codepot/views/code_revision.php index 34e1cd1b..1e9d3d98 100644 --- a/codepot/src/codepot/views/code_revision.php +++ b/codepot/src/codepot/views/code_revision.php @@ -665,7 +665,7 @@ $history = $file['history']; print '
'; printf ('[%s] ', $history['rev']); - print strftime ('%Y-%m-%d %H:%M:%S %z', strtotime($history['date'])); + print codepot_unixtimetodispdate (strtotime($history['date'])); print '
'; ?> diff --git a/codepot/src/codepot/views/log.php b/codepot/src/codepot/views/log.php index fb2e0f12..bc5cda0f 100644 --- a/codepot/src/codepot/views/log.php +++ b/codepot/src/codepot/views/log.php @@ -177,14 +177,9 @@ $this->load->view ( { if ($log['type'] == 'code') $code = $log['message']; - if (CODEPOT_DATABASE_STORE_GMT) - $createdon = $log['createdon'] . ' +0000'; - else - $createdon = $log['createdon']; - - $tzoff = strftime ('%z', strtotime($createdon)); - $date = strftime ('%Y-%m-%d', strtotime($createdon)); - $time = strftime ('%H:%M:%S', strtotime($createdon)); + $tzoff = codepot_dbdatetodispdate ($log['createdon'], 'O'); + $date = codepot_dbdatetodispdate ($log['createdon'], 'Y-m-d'); + $time = codepot_dbdatetodispdate ($log['createdon'], 'H:i:s'); if ($curdate != $date) { diff --git a/codepot/src/codepot/views/project_home.php b/codepot/src/codepot/views/project_home.php index 628157b1..c289bcd2 100644 --- a/codepot/src/codepot/views/project_home.php +++ b/codepot/src/codepot/views/project_home.php @@ -220,7 +220,7 @@ foreach ($urls as $url) 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') { diff --git a/codepot/src/codepot/views/site_home.php b/codepot/src/codepot/views/site_home.php index 2ecc809d..ab6c1f01 100644 --- a/codepot/src/codepot/views/site_home.php +++ b/codepot/src/codepot/views/site_home.php @@ -357,18 +357,13 @@ $this->load->view ( $xdot = $this->converter->AsciiToHex ('.'); foreach ($log_entries as $log) { - if (CODEPOT_DATABASE_STORE_GMT) - $createdon = $log['createdon'] . ' +0000'; - else - $createdon = $log['createdon']; - if ($log['type'] == 'code') { $x = $log['message']; print ''; print ''; - print strftime ('%m-%d', strtotime($createdon)); + print codepot_dbdatetodispdate ($log['createdon'], 'Y-m-d'); print ''; print ''; /* @@ -428,7 +423,7 @@ $this->load->view ( { print ''; print ''; - print strftime ('%m-%d', strtotime($createdon)); + print codepot_dbdatetodispdate ($log['createdon'], 'Y-m-d'); print ''; print '';