[GH-ISSUE #832] DateTimeImmutable ignores timezones when useMicrosecondTimestamps() is set #322

Closed
opened 2026-03-04 02:14:07 +03:00 by kerem · 2 comments
Owner

Originally created by @dhm80 on GitHub (Aug 3, 2016).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/832

If I set a timezone to "non UTC" and enable using microseconds the timezone is completely ignored:

$logger = new Logger('console');
$logger->setTimezone(new DateTimeZone('Europe/Berlin'));
$logger->useMicrosecondTimestamps(true);
$logger->pushHandler(new StreamHandler('php://stdout'));
$logger->debug("Test");

The problem it this part here I think:
github.com/Seldaek/monolog@cc1fe9fa91/src/Monolog/DateTimeImmutable.php (L27-L33)

Only if I set something like this as well the correct time would be logged:

date_default_timezone_set("Europe/Berlin");

But that can't be the solution as I would overwrite global settings and may want the logger to have it's only timezone... that's what the parameter / method is for, right? ;)

Originally created by @dhm80 on GitHub (Aug 3, 2016). Original GitHub issue: https://github.com/Seldaek/monolog/issues/832 If I set a timezone to "non UTC" and enable using microseconds the timezone is completely ignored: ``` php $logger = new Logger('console'); $logger->setTimezone(new DateTimeZone('Europe/Berlin')); $logger->useMicrosecondTimestamps(true); $logger->pushHandler(new StreamHandler('php://stdout')); $logger->debug("Test"); ``` The problem it this part here I think: https://github.com/Seldaek/monolog/blob/cc1fe9fa91de4a9c98a244b6f7d1302c6b0ad656/src/Monolog/DateTimeImmutable.php#L27-L33 Only if I set something like this as well the correct time would be logged: ``` php date_default_timezone_set("Europe/Berlin"); ``` But that can't be the solution as I would overwrite global settings and may want the logger to have it's only timezone... that's what the parameter / method is for, right? ;)
kerem 2026-03-04 02:14:07 +03:00
  • closed this issue
  • added the
    Bug
    label
Author
Owner

@Seldaek commented on GitHub (Sep 18, 2016):

I tried to fix this in #853 - which works if your default timezone is UTC, but otherwise it fails, at least for CET.. for Europe/Zurich for example it works, but I don't get why. Don't have time to dig further right now.

<!-- gh-comment-id:247859244 --> @Seldaek commented on GitHub (Sep 18, 2016): I tried to fix this in #853 - which works if your default timezone is UTC, but otherwise it fails, at least for CET.. for Europe/Zurich for example it works, but I don't get why. Don't have time to dig further right now.
Author
Owner

@Seldaek commented on GitHub (Sep 19, 2016):

OK I found a way using an intermediate datetime object, it's not pretty but works.

<!-- gh-comment-id:247969011 --> @Seldaek commented on GitHub (Sep 19, 2016): OK I found a way using an intermediate datetime object, it's not pretty but works.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#322
No description provided.