Skip to content

Commit

Permalink
Bugfix/record created timestamp (#1127)
Browse files Browse the repository at this point in the history
  • Loading branch information
kasparsd committed Jul 7, 2020
1 parent d465e35 commit 4f85afb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
13 changes: 4 additions & 9 deletions includes/functions.php
Expand Up @@ -41,8 +41,8 @@ function wp_stream_filter_var( $var, $filter = null, $options = array() ) {
/**
* Converts a time into an ISO 8601 extended formatted string.
*
* @param int|bool $time Seconds since unix epoch.
* @param int $offset Timezone offset.
* @param int|bool $time Seconds since unix epoch.
* @param int $offset Timezone offset.
*
* @return string an ISO 8601 extended formatted time
*/
Expand All @@ -54,17 +54,12 @@ function wp_stream_get_iso_8601_extended_date( $time = false, $offset = 0 ) {
}

$micro_seconds = sprintf( '%06d', ( $microtime - floor( $microtime ) ) * 1000000 );
$offset_string = sprintf( 'Etc/GMT%s%s', $offset < 0 ? '+' : '-', abs( $offset ) );
$offset_string = sprintf( 'Etc/GMT%s%d', $offset < 0 ? '+' : '-', abs( $offset ) );

$timezone = new DateTimeZone( $offset_string );
$date = new DateTime( gmdate( 'Y-m-d H:i:s.' . $micro_seconds, $microtime ), $timezone );

return sprintf(
'%s%03d%s',
$date->format( 'Y-m-d\TH:i:s.' ),
floor( $date->format( 'u' ) / 1000 ),
$date->format( 'O' )
);
return $date->format( 'Y-m-d\TH:i:sO' );
}

/**
Expand Down
14 changes: 14 additions & 0 deletions tests/tests/test-functions.php
@@ -0,0 +1,14 @@
<?php
namespace WP_Stream;

class Test_Functions extends WP_StreamTestCase {
public function test_wp_stream_get_iso_8601_extended_date() {
$time = '1095379198';

$date = wp_stream_get_iso_8601_extended_date( $time );
$this->assertSame( $date, '2004-09-16T23:59:58+0000' );

$offset_date = wp_stream_get_iso_8601_extended_date( $time, 5 );
$this->assertSame( $offset_date, '2004-09-16T23:59:58+0500' );
}
}

0 comments on commit 4f85afb

Please sign in to comment.