Skip to content

Bug: Logger - Invalid ISO 8601 timestamp (T24:00:00) when TZ is set to any non-UTC value #4083

Closed
@ogis-tkash

Description

@ogis-tkash

Expected Behavior

When the TZ environment variable is set to any value other than UTC (for example, ":/etc/localtime", "Europe/London", etc.), the logger should output timestamps in valid ISO 8601 format. Specifically, the hour portion should never be 24 (e.g., 2025-05-09T24:00:33 is invalid ISO 8601); it should be to 00, according to ISO 8601.

Current Behavior

When running AWS Lambda Powertools for TypeScript with TZ set to any non-UTC value, the logger may emit timestamps such as 2025-05-09T24:00:33, which is not a valid ISO 8601 value. This seems to occur when logging events exactly at midnight, likely due to the use of Intl.DateTimeFormat and how it interprets some timezones.

Code snippet

see Steps to Reproduce.

Steps to Reproduce

  1. Deploy a Lambda function using Powertools for AWS Lambda (TypeScript)
  2. Set the environment variable TZ to any value other than UTC (such as :/etc/localtime, Europe/London, etc.)
  3. Trigger a log event at exactly midnight (00:00:33)
  4. Observe the generated timestamp in the logs; it may appear as T24:00:33

Possible Solution

For example, you could use a Unicode extension for your locale to change the hour cycle from 24 (Hour system using 1–24) to 23 (Hour system using 0–23).
see Unicode extension

return new Intl.DateTimeFormat('en', {

    return new Intl.DateTimeFormat('en', {
      year: 'numeric',
      month: twoDigitFormatOption,
      day: twoDigitFormatOption,
      hour: twoDigitFormatOption,
      minute: twoDigitFormatOption,
      second: twoDigitFormatOption,
      hour12: false,
      timeZone: validTimeZone,
    });

↓↓↓

    return new Intl.DateTimeFormat('en-u-hc-h23', {
      year: 'numeric',
      month: twoDigitFormatOption,
      day: twoDigitFormatOption,
      hour: twoDigitFormatOption,
      minute: twoDigitFormatOption,
      second: twoDigitFormatOption,
      hour12: false,
      timeZone: validTimeZone,
    });

Powertools for AWS Lambda (TypeScript) version

latest

AWS Lambda function runtime

20.x

Packaging format used

npm

Execution logs

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcompletedThis item is complete and has been merged/shippedloggerThis item relates to the Logger Utility

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions