mirror of
https://github.com/10h30/wp-strava.git
synced 2026-07-16 05:03:41 +09:00
Fix issue with activities longer than 24h
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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 ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user