usebruno / bruno

Opensource IDE For Exploring and Testing Api's (lightweight alternative to postman/insomnia)
https://www.usebruno.com/
MIT License
24.88k stars 1.13k forks source link

humanizeDate utility function returns inconsistent results based on the time zone #2377

Closed KameronKeller closed 1 week ago

KameronKeller commented 3 months ago

I have checked the following:

Describe the bug

While writing tests for the utility functions found in packages/bruno-app/src/utils/common/index.js, I noticed that the humanizeDate function does not reliably return the date it is passed. This is caused by the Date object in JavaScript, which considers time zones when parsing a date.

See the discussions here for further explanation:

File in question: packages/bruno-app/src/utils/common/index.js

Code in question:

export const humanizeDate = (dateString) => {
  const date = new Date(dateString);
  return date.toLocaleDateString('en-US', {
    year: 'numeric',
    month: 'long',
    day: 'numeric'
  });
};

The below screenshot illustrates this phenomenon.

.bru file to reproduce the bug

No response

Screenshots/Live demo link

image

KameronKeller commented 3 months ago

See this PR for a proposed fix and tests: https://github.com/usebruno/bruno/pull/2378

helloanoop commented 1 week ago

PR Merged