Skip to content

Commit

Permalink
Merge pull request #314 from EasyPost/310_fix_request_response_timest…
Browse files Browse the repository at this point in the history
…amps

fix: UTC timezone bug for request/response timestamps
  • Loading branch information
Justintime50 committed Nov 20, 2023
2 parents 2b9d3c6 + 629bb6d commit 8b3b9fa
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## v6.9.1 (2023-11-20)

- Fixes a bug that globally reset the timezone to UTC instead of setting the timezone per-request (closes #310)

## v6.9.0 (2023-10-11)

- Deprecates API key-related functions in the `user` service and introduces the replacement functions in the `api_keys` service
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "easypost/easypost-php",
"description": "EasyPost Shipping API Client Library for PHP",
"version": "6.9.0",
"version": "6.9.1",
"keywords": [
"shipping",
"api",
Expand Down
2 changes: 1 addition & 1 deletion lib/EasyPost/Constant/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract class Constants
const BETA_API_VERSION = 'beta';

// Library constants
const LIBRARY_VERSION = '6.9.0';
const LIBRARY_VERSION = '6.9.1';
const SUPPORT_EMAIL = '[email protected]';

// Validation
Expand Down
9 changes: 2 additions & 7 deletions lib/EasyPost/Http/Requestor.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,7 @@ private static function requestRaw($client, $method, $url, $params, $beta = fals
];

$requestUuid = uniqid();
$originalTimezone = date_default_timezone_get();
date_default_timezone_set('UTC');
$requestTimestamp = microtime(true);
$requestTimestamp = (float) (new DateTime('now', new DateTimeZone('UTC')))->format('U.u');
($client->requestEvent)([
'method' => $method,
'path' => $absoluteUrl,
Expand Down Expand Up @@ -226,7 +224,7 @@ private static function requestRaw($client, $method, $url, $params, $beta = fals
$responseHeaders = $response->getHeaders();
}

$responseTimestamp = microtime(true);
$responseTimestamp = (float) (new DateTime('now', new DateTimeZone('UTC')))->format('U.u');
($client->responseEvent)([
'http_status' => $httpStatus,
'method' => $method,
Expand All @@ -238,9 +236,6 @@ private static function requestRaw($client, $method, $url, $params, $beta = fals
'request_uuid' => $requestUuid,
]);

// Reset the timezone after we've done our UTC calculations so we don't affect user code
date_default_timezone_set($originalTimezone);

return [$responseBody, $httpStatus];
}

Expand Down

0 comments on commit 8b3b9fa

Please sign in to comment.