"toAbsoluteLocaleDate" test doesn't pass when system locale is not en-US #14273

Closed
opened 2025-11-02 11:08:14 -06:00 by GiteaMirror · 1 comment
Owner

Originally created by @YaFou on GitHub (Mar 19, 2025).

Description

When I run the tests from source using make test-frontend, the toAbsoluteLocaleDate doesn't pass.

 FAIL  web_src/js/webcomponents/absolute-date.test.ts > toAbsoluteLocaleDate
AssertionError: expected '14/03/2024 20:00:00' to deeply equal '3/14/2024, 8:00:00 PM'

Expected: "3/14/2024, 8:00:00 PM"
Received: "14/03/2024 20:00:00"

I succeeded to fix the bug by setting the locale in the test:

@@ -20,7 +20,7 @@ test('toAbsoluteLocaleDate', () => {
   // test different timezone
   const oldTZ = process.env.TZ;
   process.env.TZ = 'America/New_York';
-  expect(new Date('2024-03-15').toLocaleString()).toEqual('3/14/2024, 8:00:00 PM');
-  expect(toAbsoluteLocaleDate('2024-03-15')).toEqual('3/15/2024, 12:00:00 AM');
+  expect(new Date('2024-03-15').toLocaleString('en-US')).toEqual('3/14/2024, 8:00:00 PM');
+  expect(toAbsoluteLocaleDate('2024-03-15', 'en-US')).toEqual('3/15/2024, 12:00:00 AM');
   process.env.TZ = oldTZ;
 });

I can open a pull request if you want.

Gitea Version

39fc2e7285

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

Arch Linux

How are you running Gitea?

I installed Gitea from source using the documentation. I'm using Arch Linux with the fr_FR locale.

Database

None

Originally created by @YaFou on GitHub (Mar 19, 2025). ### Description When I run the tests from source using `make test-frontend`, the `toAbsoluteLocaleDate` doesn't pass. ```bash FAIL web_src/js/webcomponents/absolute-date.test.ts > toAbsoluteLocaleDate AssertionError: expected '14/03/2024 20:00:00' to deeply equal '3/14/2024, 8:00:00 PM' Expected: "3/14/2024, 8:00:00 PM" Received: "14/03/2024 20:00:00" ``` I succeeded to fix the bug by setting the locale in the test: ```diff @@ -20,7 +20,7 @@ test('toAbsoluteLocaleDate', () => { // test different timezone const oldTZ = process.env.TZ; process.env.TZ = 'America/New_York'; - expect(new Date('2024-03-15').toLocaleString()).toEqual('3/14/2024, 8:00:00 PM'); - expect(toAbsoluteLocaleDate('2024-03-15')).toEqual('3/15/2024, 12:00:00 AM'); + expect(new Date('2024-03-15').toLocaleString('en-US')).toEqual('3/14/2024, 8:00:00 PM'); + expect(toAbsoluteLocaleDate('2024-03-15', 'en-US')).toEqual('3/15/2024, 12:00:00 AM'); process.env.TZ = oldTZ; }); ``` I can open a pull request if you want. ### Gitea Version 39fc2e7285 ### Can you reproduce the bug on the Gitea demo site? Yes ### Log Gist _No response_ ### Screenshots _No response_ ### Git Version _No response_ ### Operating System Arch Linux ### How are you running Gitea? I installed Gitea from source using [the documentation](https://docs.gitea.com/development/hacking-on-gitea). I'm using Arch Linux with the `fr_FR` locale. ### Database None
GiteaMirror added the type/bug label 2025-11-02 11:08:14 -06:00
Author
Owner

@wxiaoguang commented on GitHub (Mar 19, 2025):

I can open a pull request if you want.

Thank you very much. It is very welcome!

@wxiaoguang commented on GitHub (Mar 19, 2025): > I can open a pull request if you want. Thank you very much. It is very welcome!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#14273