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

[Bug]: Timezone is changed and not changed back #310

Closed
robgridley opened this issue Oct 3, 2023 · 9 comments · Fixed by #311 or #314
Closed

[Bug]: Timezone is changed and not changed back #310

robgridley opened this issue Oct 3, 2023 · 9 comments · Fixed by #311 or #314
Labels
triage Issue is being researched

Comments

@robgridley
Copy link

Software Version

6.8.1

Language Version

8.1.11

Operating System

Ubuntu

What happened?

Your client is forcing the timezone to UTC to get a UTC timestamp in microseconds, but you're not switching it back. Line 186 in lib/EasyPost/Http/Requestor.php.

What was expected?

As of PHP 7.1 the built-in DateTime class supports microseconds. You can create a new DateTime instance, change the timezone of the instance to UTC, then format it as a timestamp. You could also store the current timezone, set it to UTC, call microtime(), then change the timezone back.

Sample Code

No response

Relevant logs

No response

@robgridley robgridley added the triage Issue is being researched label Oct 3, 2023
@Justintime50
Copy link
Member

Hey @robgridley, thanks for writing in. I'm still not perfectly clear on the ask here. Are you looking to have the timezone your code is running in to be respected when getting the timing metrics of a request hook? We intentionally set UTC to provide a consistent experience for all users. Are you not able to convert the UTC time returned into the timezone you need?

@robgridley
Copy link
Author

By using date_default_timezone_set(), you're not just changing the timezone for your library, you're changing the timezone for my application.

@Justintime50
Copy link
Member

Ah understood, thank you for clarifying! Yeah we'll definitely want to fix that. Let me toss up a PR here shortly and get this resolved.

@robgridley
Copy link
Author

Thanks! For now I'm storing my app's timezone and switching it back after every API call.

@Justintime50
Copy link
Member

Mind double-checking my PR to make sure it's along the lines of what you had in mind?

@robgridley
Copy link
Author

Looks good. That's exactly what I'm doing.

Justintime50 added a commit that referenced this issue Oct 4, 2023
fix: reset timezone to original (closes #310)
@Justintime50
Copy link
Member

Perfect, we'll get this released shortly. Thanks again for reporting this!

@NHZEX
Copy link

NHZEX commented Nov 18, 2023

The current fix did not completely resolve this issue. During the process of restoring the time zone, there are HTTP requests (IO operations) involved. In the 'Fiber' or 'Swoole' runtime environment, any IO operation will cause coroutine switching. The current global methods will contaminate the entire process space. Please use the 'DateTime' object to safely resolve this problem.

I used a translation tool to translate this error report. Please let me know if there are any inaccuracies or if you need any further clarification.

@Justintime50
Copy link
Member

This should be fixed for good with the release of v6.9.1. Let us know if that's not the case!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Issue is being researched
Projects
None yet
3 participants