Skip to content

Commit 8b3b9fa

Browse files
authored
Merge pull request #314 from EasyPost/310_fix_request_response_timestamps
fix: UTC timezone bug for request/response timestamps
2 parents 2b9d3c6 + 629bb6d commit 8b3b9fa

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## v6.9.1 (2023-11-20)
4+
5+
- Fixes a bug that globally reset the timezone to UTC instead of setting the timezone per-request (closes #310)
6+
37
## v6.9.0 (2023-10-11)
48

59
- Deprecates API key-related functions in the `user` service and introduces the replacement functions in the `api_keys` service

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "easypost/easypost-php",
33
"description": "EasyPost Shipping API Client Library for PHP",
4-
"version": "6.9.0",
4+
"version": "6.9.1",
55
"keywords": [
66
"shipping",
77
"api",

lib/EasyPost/Constant/Constants.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ abstract class Constants
1111
const BETA_API_VERSION = 'beta';
1212

1313
// Library constants
14-
const LIBRARY_VERSION = '6.9.0';
14+
const LIBRARY_VERSION = '6.9.1';
1515
const SUPPORT_EMAIL = '[email protected]';
1616

1717
// Validation

lib/EasyPost/Http/Requestor.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,7 @@ private static function requestRaw($client, $method, $url, $params, $beta = fals
183183
];
184184

185185
$requestUuid = uniqid();
186-
$originalTimezone = date_default_timezone_get();
187-
date_default_timezone_set('UTC');
188-
$requestTimestamp = microtime(true);
186+
$requestTimestamp = (float) (new DateTime('now', new DateTimeZone('UTC')))->format('U.u');
189187
($client->requestEvent)([
190188
'method' => $method,
191189
'path' => $absoluteUrl,
@@ -226,7 +224,7 @@ private static function requestRaw($client, $method, $url, $params, $beta = fals
226224
$responseHeaders = $response->getHeaders();
227225
}
228226

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

241-
// Reset the timezone after we've done our UTC calculations so we don't affect user code
242-
date_default_timezone_set($originalTimezone);
243-
244239
return [$responseBody, $httpStatus];
245240
}
246241

0 commit comments

Comments
 (0)