Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/record created timestamp #1127

Merged
merged 6 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions includes/functions.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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' );
}
}