Moment() returning incorrect local timestamp

Hello, I was under the impressions that calling moment() should return local timestamp by default. However, that is not what I’m getting running this code. Can someone please clarify this for me? Thank you.

Hey @Mariusz_Kolaszewski ,

What are you expecting this code to output here? It looks like lines 2 and 3 get the current time in America/New_York and Africa/Abidjan (what’s being detected as your current TZ).

Hey Mitchel, my TZ is not ā€˜Africa/Abidjan’. I expect moment() to return local timezone ā€˜America/New York’.

That’s almost certainly the explanation for why you’re seeing moment() returning a time zone you’re not expecting. Line 8 indicates that it’s detecting your local time zone as Africa/Abidjan. Are you running a VPN or do you have your computer set to a specific time zone?

For reference, this is what I see when running your code. I’m on NY time zone so moment() and moment.tz(ā€˜America/New_York’) return the same value as expected.

Running the following outside of Retool returns correct timezone.

So this is definitely a Retool issue.

1 Like

Hey @Mariusz_Kolaszewski - thanks for reaching out. The JS code you're writing is in a workflow block and, as such, gets executed within the context of our backend server where Intl.DateTimeFormat().resolvedOptions().timeZone resolves to UTC. This is the expected behavior so I don't think there's necessarily anything wrong here. Let me know if you have any follow up questions!

1 Like

Hey Darren, I also get UTC when running moment() inside the app. Which is not consistent with what’s reported by @Mitchel_Smith who is getting ā€˜America/New York’.

1 Like

Hey @Mariusz_Kolaszewski! The moment library has a UTC method you can use to get local time. Just replace item.CREATED with your actual time string you are trying to localize:

{{ moment.utc(item.CREATED).format('hh:mm:ss') }}

Ah thanks for checking and confirming, @Mariusz_Kolaszewski. There are definitely ways around this, but the behavior that you're describing certainly sounds unexpected. Are you loading any custom JS libraries into your app environment? Do you observe the same behavior in a brand new empty app?