date-fns / utc

date-fns UTC utils
70 stars 5 forks source link

fix: interprets strings as UTC #6

Closed timozander closed 4 months ago

timozander commented 4 months ago

Calling new UTCDate() with a string yields wrong results. For example, if I am right of UTC (e.g. Berlin), then I would expect

console.log(new UTCDate("2025-07-01"))
//=> 'Tue Jul 1 2025 00:00:00 GMT+0000 (Coordinated Universal Time)'

However, it insteads outputs it in local time:

//=> 'Mon Jun 30 2025 22:00:00 GMT+0000 (Coordinated Universal Time)'

This PR fixes it by treating the string as UTC

kossnocorp commented 3 months ago

Hey! Could you please explain a bit why did you close the PR? I didn't get into the details, but it seems the library confused you. I want to address it.

timozander commented 3 months ago

Hi thanks for the response. I thought I'd ran into a problem with the library but I was ultimately just parsing a non-compliant string (like 2020-01-1 with a missing 0) which is not guaranteed to give any consistent output. So I would also not expect UTCDate to do so 😁