From 7b475b61f9291ea3558b44d6946510b527b0509d Mon Sep 17 00:00:00 2001 From: Adrian Gibbons Date: Sun, 16 Aug 2015 11:20:43 +0800 Subject: [PATCH] timestamp fault tolerance --- demo/swim.php | 4 ++-- php-FIT-File-Analysis.php | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/demo/swim.php b/demo/swim.php index c73d5cb..cc380bc 100644 --- a/demo/swim.php +++ b/demo/swim.php @@ -23,10 +23,10 @@ $units = 'm'; $pool_length = $pFFA->data_mesgs['session']['pool_length']; - $total_distance = number_format($pFFA->data_mesgs['record']['distance']); + $total_distance = number_format(max($pFFA->data_mesgs['record']['distance'])); if($pFFA->enum_data('display_measure', $pFFA->data_mesgs['session']['pool_length_unit']) == 'statute') { $pool_length = round($pFFA->data_mesgs['session']['pool_length'] * 1.0936133); - $total_distance = number_format($pFFA->data_mesgs['record']['distance'] * 1.0936133); + $total_distance = number_format(max($pFFA->data_mesgs['record']['distance']) * 1.0936133); $units = 'yd'; } ?> diff --git a/php-FIT-File-Analysis.php b/php-FIT-File-Analysis.php index d2f27fd..0a184d4 100644 --- a/php-FIT-File-Analysis.php +++ b/php-FIT-File-Analysis.php @@ -762,9 +762,16 @@ private function read_data_records() { } // Process the temporary array and load values into the public data messages array - if(isset($tmp_record_array['timestamp'])) { - $timestamp = $tmp_record_array['timestamp']; - unset($tmp_record_array['timestamp']); + if(!empty($tmp_record_array)) { + $timestamp = isset($this->data_mesgs['record']['timestamp']) ? max($this->data_mesgs['record']['timestamp']) + 1 : 0; + + if(isset($tmp_record_array['timestamp'])) { + if($tmp_record_array['timestamp'] > 0) { + $timestamp = $tmp_record_array['timestamp']; + } + unset($tmp_record_array['timestamp']); + } + $this->data_mesgs['record']['timestamp'][] = $timestamp; foreach($tmp_record_array as $key => $value) {