question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Date filter converts time to local timezone

See original GitHub issue

Hi there,

There is an issue with the date filter that uses javascript’s native dates. The timezone of the javascript date is always set to the user’s timezone (this is different behaviour than in ruby). For example:

new Date("1990-12-31T23:00:00Z")
// -> Tue Jan 01 1991 01:00:00 GMT+0200 (Eastern European Standard Time)

The input is parsed correctly, but it’s converted to local timezone. (Note that this loses the information of the timezone of the input value). Now if I want to format the date it will show wrong year etc. depending on my timezone. For example, if your computer is set to some other timezone than utc, then the following test will fail:

// test/integration/builtin/filters/date.ts

it('should not convert timezones', async function () {
  return test('{{ "1990-12-31T23:00:00Z" | date: "%Y-%m-%dT%H:%M:%S"}}', '1990-12-31T23:00:00')
})

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
wyozicommented, Nov 3, 2020

@petuomin imo the “conversion to the target timezone” is the difficult part. There is no easy way to convert to given timezone since it’s not as simple as addition (unless only numeric fixed offset timezones are supported, and even then DST might pose some problems). For instance, how would you modify the custom strftime to convert the given date to Asia/Shanghai timezone?

Taking advantage of Intl.DateTimeFormat would be an option, but as far as I can tell it would require a complete overhaul of strftime and add additional browser requirements. Maybe that’s the only way to have a “proper” timezone support though. The author of Luxon goes a bit deeper into this here.

It seems that one major issue here is the automatic conversion to local timezone. If the date filter just kept the dates and times the same (give timestamp with hour=20, get formatted string with hour=20), the issue would be partially solved. That’s why I suggested dropping timezone as one potential solution/workaround.

0reactions
harttlecommented, Dec 18, 2020

🎉 This issue has been resolved in version 9.19.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

Convert UTC date time to local date time - Stack Overflow
4 · Hello, I had similar problems, I solved it by converting the date/time, before sending to the server, using: var date =...
Read more >
How to Convert UTC to Local Time Zone in SQL Server
It uses the host server time as the basis for generating the output of getdate() . To convert a UTC timestamp to a...
Read more >
Converting times between time zones - Microsoft Learn
Indicates whether a specified date and time falls in the range of daylight saving time for the current TimeZoneInfo object's time zone.
Read more >
Relative Date Slicer for Your Local Time Zone in Power BI
Relative Date Slicer for Your Local Time Zone in Power BI ... Relative Date slicer is a great way to filter data by...
Read more >
Relative Date filter is set to UTC, need to change to AEDT
You can convert data captured in a local time zone to UTC using the Query Editor. Eyelyn9_0-1640594719847.png. Refer to: Handling Different Time Zones...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found