Skip to content

Commit

Permalink
Remove system time reliance in StringFromTime constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
odygrd committed Aug 25, 2024
1 parent 293bf16 commit b15b414
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
- Fixed an issue where `char*` and `char[]` types could be incorrectly selected by the Codec template in `Array.h`
- The library no longer defines `__STDC_WANT_LIB_EXT1__`, as the bounds-checking functions from the extensions are no
longer needed.
- `StringFromTime` constructor no longer relies on the system's current time, improving performance in simulations where
timestamps differ from system time. ([#541](https://github.com/odygrd/quill/issues/541))
- The `Frontend::create_or_get_logger(...)` function now accepts a `PatternFormatterOptions` parameter, simplifying the
API. This is a breaking change. To migrate quickly, wrap the existing formatting parameters in a
`PatternFormatterOptions` object.
Expand Down
27 changes: 5 additions & 22 deletions include/quill/backend/StringFromTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,6 @@ class StringFromTime

// Populate the initial parts that we will use to generate a pre-formatted string
_populate_initial_parts(_timestamp_format);

// Get the current timestamp now
time_t timestamp;
std::time(&timestamp);

if (_time_zone == Timezone::LocalTime)
{
// If localtime is used, we will recalculate every 15 minutes. This approach accounts for DST
// changes and simplifies handling transitions around midnight. Recalculating every 15 minutes
// ensures coverage for all possible timezones without additional computations.
_next_recalculation_timestamp = _next_quarter_hour_timestamp(timestamp);
}
else if (_time_zone == Timezone::GmtTime)
{
// otherwise we will only recalculate every noon and midnight. the reason for this is in case
// user is using PM, AM format etc
_next_recalculation_timestamp = _next_noon_or_midnight_timestamp(timestamp);
}

// Now populate a pre-formatted string for this hour,
// also cache any indexes of the time modifier in the string
_populate_pre_formatted_string_and_cached_indexes(timestamp);
}

/***/
Expand Down Expand Up @@ -116,10 +94,15 @@ class StringFromTime

if (_time_zone == Timezone::LocalTime)
{
// If localtime is used, we will recalculate every 15 minutes. This approach accounts for
// DST changes and simplifies handling transitions around midnight. Recalculating every 15
// minutes ensures coverage for all possible timezones without additional computations.
_next_recalculation_timestamp = _next_quarter_hour_timestamp(timestamp);
}
else if (_time_zone == Timezone::GmtTime)
{
// otherwise we will only recalculate every noon and midnight. the reason for this is in
// case user is using PM, AM format etc
_next_recalculation_timestamp = _next_noon_or_midnight_timestamp(timestamp);
}
}
Expand Down

0 comments on commit b15b414

Please sign in to comment.