Fix issue with activities longer than 24h

This commit is contained in:
Justin Foell
2019-08-02 14:56:49 -05:00
parent 8444866558
commit 3e14f06a48
3 changed files with 18 additions and 1 deletions
+5 -1
View File
@@ -33,9 +33,13 @@ abstract class WPStrava_SOM {
* Create a time string of hours:minutes:seconds from just seconds.
*
* @return string Time formatted as 'H:i:s'.
* @see https://stackoverflow.com/a/20870843/2146022
*/
public function time( $seconds ) {
return date( 'H:i:s', mktime( 0, 0, $seconds ) );
$zero = new DateTime( '@0' );
$offset = new DateTime( "@{$seconds}" );
$diff = $zero->diff( $offset );
return sprintf( '%02d:%02d:%02d', $diff->days * 24 + $diff->h, $diff->i, $diff->s );
}
/**
+1
View File
@@ -86,6 +86,7 @@ WP-Strava caches activity for one hour so your site doesn't hit the Strava API o
= 1.7.2 =
Added setting to hide elevation.
Fixed hours for activities greater than 24 hours.
= 1.7.1 =
+12
View File
@@ -80,4 +80,16 @@ class WPStrava_SOMEnglishTest extends TestCase {
$this->assertEquals( '01:20:05', $this->som->time( 4805 ) );
}
/**
* Test that 221071 seconds is 61:24:31 time (H:i:s) using both string and float inputs.
*
* @author Justin Foell <justin@foell.org>
* @since 1.7.2
*/
public function test_time_greater24h() {
$this->assertEquals( '61:24:31', $this->som->time( '221071' ) );
$this->assertEquals( '61:24:31', $this->som->time( 221071 ) );
}
}