advanced patterns When Using Day.js with Time Zones - Incorrect UTC Offsets
I keep running into I'm migrating some code and I'm using Day.js (version 1.10.4) to handle date and time in my React application, but I'm running into an scenario with time zones that I need to seem to resolve. I've set up Day.js with the UTC and timezone plugins, but when I try to display a date in a specific time zone, the output seems to be off by several hours. Here's the code snippet that I'm using: ```javascript import dayjs from 'dayjs'; import utc from 'dayjs/plugin/utc'; import timezone from 'dayjs/plugin/timezone'; dayjs.extend(utc); dayjs.extend(timezone); const dateInUTC = dayjs.utc('2023-10-01T12:00:00Z'); const dateInNY = dateInUTC.tz('America/New_York'); console.log(dateInNY.format('YYYY-MM-DD HH:mm:ss')); // Expected: 2023-10-01 08:00:00 ``` However, when I run this code, the console logs `2023-10-01 07:00:00` instead of the expected `2023-10-01 08:00:00`. I've double-checked that New York is in UTC-4 for daylight saving time during that period, so it should be converting correctly. I've also tried using the `dayjs().local()` method before converting, but that doesn't seem to change the outcome either. I’ve confirmed that my system time and time zone settings are accurate. Is there something obvious that I might be overlooking, or do I need to consider a specific configuration in Day.js? Any insights would be greatly appreciated! I'm working with Javascript in a Docker container on Ubuntu 22.04. Is there a simpler solution I'm overlooking? I'm working on a CLI tool that needs to handle this. Any ideas what could be causing this?