[PR #402] [CLOSED] Added microsecond support for JSON serialized DateTime objects #1128

Closed
opened 2026-03-04 03:05:30 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Seldaek/monolog/pull/402
Author: @holtkamp
Created: 7/31/2014
Status: Closed

Base: masterHead: microsecond-support-for-json-serialized-datetimes


📝 Commits (4)

  • a193537 Added microsecond support for JSON serialized DateTime objects
  • ce7a8b6 Removed need to override createFromFormat()
  • 737b328 Merge remote-tracking branch 'upstream/master' into microsecond-support-for-json-serialized-datetimes
  • 6347b4d Bumped PHP version to 5.4, which supports JsonSerializable

📊 Changes

3 files changed (+54 additions, -2 deletions)

View changed files

📝 composer.json (+1 -1)
src/Monolog/DateTime.php (+35 -0)
📝 src/Monolog/Logger.php (+18 -1)

📄 Description

When using the JsonFormatter, all records are encoded using json_encode(). For the timestamp this would mean that a DateTime object results in something like:

    "datetime": {
        "date": "2014-07-31 11:15:22",
        "timezone_type": 3,
        "timezone": "Europe/Amsterdam"
    }

This way we 'loose' the ability to format the timestamp with microsecond precision. A way to avoid this loss of detail is to extend the native DateTime class with one that implements JsonSerializable which appends the microseconds.

Note that due to https://bugs.php.net/bug.php?id=60302, this means we can no longer use DateTime::createFromFormat(), so I isolated it in a private function.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Seldaek/monolog/pull/402 **Author:** [@holtkamp](https://github.com/holtkamp) **Created:** 7/31/2014 **Status:** ❌ Closed **Base:** `master` ← **Head:** `microsecond-support-for-json-serialized-datetimes` --- ### 📝 Commits (4) - [`a193537`](https://github.com/Seldaek/monolog/commit/a19353766e7e880c2c9dcbf65c3dd001fc6e4580) Added microsecond support for JSON serialized DateTime objects - [`ce7a8b6`](https://github.com/Seldaek/monolog/commit/ce7a8b63e11106cba19d6b69b6992ac5b11c5dac) Removed need to override createFromFormat() - [`737b328`](https://github.com/Seldaek/monolog/commit/737b328669c760f6532ee783fc63451e17558828) Merge remote-tracking branch 'upstream/master' into microsecond-support-for-json-serialized-datetimes - [`6347b4d`](https://github.com/Seldaek/monolog/commit/6347b4d63bc6b8ec58c73cca4fe583e4ce27e1ad) Bumped PHP version to 5.4, which supports JsonSerializable ### 📊 Changes **3 files changed** (+54 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `composer.json` (+1 -1) ➕ `src/Monolog/DateTime.php` (+35 -0) 📝 `src/Monolog/Logger.php` (+18 -1) </details> ### 📄 Description When using the JsonFormatter, all records are encoded using json_encode(). For the timestamp this would mean that a DateTime object results in something like: ``` "datetime": { "date": "2014-07-31 11:15:22", "timezone_type": 3, "timezone": "Europe/Amsterdam" } ``` This way we 'loose' the ability to format the timestamp with microsecond precision. A way to avoid this loss of detail is to extend the native DateTime class with one that implements [JsonSerializable](http://php.net/manual/en/class.jsonserializable.php) which appends the microseconds. Note that due to https://bugs.php.net/bug.php?id=60302, this means we can no longer use DateTime::createFromFormat(), so I isolated it in a private function. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-04 03:05:30 +03:00
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#1128
No description provided.