0

I've noticed a very strange behavior for POST requests - when I send, for example, 01-01-1928, everything is fine, however, when I send 01-01-1926, I get a weird date in the payload of the POST request: enter image description here

Instead of 00:00:00 I get 22:23:26.

Here is a sandbox with a date before 1927 (demonstrates the issue): https://codesandbox.io/s/axios-post-data-form-forked-1wvyk?file=/src/index.js

Here is a sandbox with a date after 1927 (everything is as expected): https://codesandbox.io/s/axios-post-data-form-forked-6g6gt?file=/src/index.js

I can't find anything about this online. What in the world is this?

By the way - Axios is used in the sandbox.

GeForce RTX 4090
  • 3,091
  • 11
  • 32
  • 58

1 Answers1

1

You are using old dates, when timezones were not so standardized.

In you case, from Time Zone Database:

# Zone  NAME            GMTOFF  RULES   FORMAT  [UNTIL]
Zone    Europe/Minsk    1:50:16 -       LMT     1880
                        1:50    -       MMT     1924 May  2 # Minsk Mean Time
                        2:00    -       EET     1930 Jun 21
                        3:00    -       MSK     1941 Jun 28
                        1:00    C-Eur   CE%sT   1944 Jul  3
                        3:00    Russia  MSK/MSD 1990
                        3:00    -       MSK     1991 Mar 31  2:00s
                        2:00    1:00    EEST    1991 Sep 29  2:00s
                        2:00    -       EET     1992 Mar 29  0:00s
                        2:00    1:00    EEST    1992 Sep 27  0:00s
                        2:00    Russia  EE%sT   2011 Mar 27  2:00s
                        3:00    -       FET     2014 Oct 26  1:00s
                        3:00    -       MSK

As you see for Minsk, there were 1:50 differences between 1924 and 1930, but 1:50:16 from 1880 and 1924. Before that, there were not standardized time, usually every town had own solar time.

# Zone  NAME            GMTOFF  RULES   FORMAT  [UNTIL]
Zone    Europe/Tallinn  1:39:00 -       LMT     1880
                        1:39:00 -       TMT     1918 Feb    # Tallinn Mean Time
                        1:00    C-Eur   CE%sT   1919 Jul
                        1:39:00 -       TMT     1921 May
                        2:00    -       EET     1940 Aug  6
                        3:00    -       MSK     1941 Sep 15
                        1:00    C-Eur   CE%sT   1944 Sep 22
                        3:00    Russia  MSK/MSD 1989 Mar 26  2:00s
                        2:00    1:00    EEST    1989 Sep 24  2:00s
                        2:00    C-Eur   EE%sT   1998 Sep 22
                        2:00    EU      EE%sT   1999 Oct 31  4:00
                        2:00    -       EET     2002 Feb 21
                        2:00    EU      EE%sT


Zone    Europe/Riga     1:36:34 -       LMT     1880
                        1:36:34 -       RMT     1918 Apr 15  2:00 # Riga MT
                        1:36:34 1:00    LST     1918 Sep 16  3:00 # Latvian ST
                        1:36:34 -       RMT     1919 Apr  1  2:00
                        1:36:34 1:00    LST     1919 May 22  3:00
                        1:36:34 -       RMT     1926 May 11
                        2:00    -       EET     1940 Aug  5
(...)

# Zone  NAME            GMTOFF  RULES   FORMAT  [UNTIL]
Zone    Europe/Vilnius  1:41:16 -       LMT     1880
                        1:24:00 -       WMT     1917        # Warsaw Mean Time
                        1:35:36 -       KMT     1919 Oct 10 # Kaunas Mean Time
                        1:00    -       CET     1920 Jul 12
                        2:00    -       EET     1920 Oct  9
                        1:00    -       CET     1940 Aug  3
(...)
(etc. for other zones)

So just you get the correct offset from GMT.

Giacomo Catenazzi
  • 8,519
  • 2
  • 24
  • 32
  • Additionally, based on the specific date returned, @gfels is running this in `Europe/Riga`: `TZ=Europe/Riga node -e "console.log(new Date('01-01-1925'))"` => `1924-12-31T22:23:26.000Z` `TZ=Europe/Riga node -e "console.log(new Date('01-01-1927'))"` => `1926-12-31T22:00:00.000Z` – msbit Dec 04 '20 at 02:49
  • This is a little problematic, because the app I'm working on is supposed to be used from various time zones. What would be a viable approach of normalizing time zone issues like this? – GeForce RTX 4090 Dec 04 '20 at 10:29
  • @gfels: Do no use time zones. I think you are using "wall clock" and "wall calendar" times, so they are independent to timezones. [These "wall X" means that you care only on the number you see on wall, not about relation with UTC, etc.]. DOB is one of this. You get the DOB as the certificate (also if you were in an other timezone) – Giacomo Catenazzi Dec 04 '20 at 19:12
  • @gfelsYou may want, `new Date(Date.UTC(1925, 0, 1, 0, 0, 0))` – chinesedfan Dec 07 '20 at 06:37
  • Ended up changing the logic not to use time zones. Thanks, guys! ;) – GeForce RTX 4090 Dec 11 '20 at 22:56