dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

Wrong meridiem in Arabic locale when time is 12 PM

Open dev-mashael-otb opened this issue 2 months ago • 7 comments

Hi, I noticed a bug when using the Arabic locale (ar-sa) in Day.js

When the time is 12 PM Day.js returns the meridiem as "ص" (AM) instead of "م" (PM)

This only happens at 12 PM other PM hours like 1 PM, 2 PM, etc.. work fine

I also tested it using Vitest and the test fails for the same reason

So it seems like the Arabic locale logic doesn’t handle 12 PM correctly


import { describe, expect, test } from "vitest";
import dayjs from "dayjs";
import "dayjs/locale/ar-sa";

describe("Dayjs Arabic & English", () => {
  test("12:41 PM should be م in Arabic", () => {
    const result = dayjs("2025-10-28T09:41:10.000000Z").locale("ar-sa").format("hh:mm a");
    expect(result).toBe("12:41 م");
  });

  test("12:41 PM should be pm in English", () => {
    const result = dayjs("2025-10-28T09:41:10.000000Z").format("hh:mm a");
    expect(result).toBe("12:41 pm");
  });
});

AssertionError: expected '12:41 ص' to be '12:41 م' // Object.is equality

Expected: "12:41 م"
Received: "12:41 ص"

dev-mashael-otb avatar Oct 31 '25 18:10 dev-mashael-otb

@devmashael1-prog what version of dayjs where you able to replicate this ?

AnslemHack avatar Oct 31 '25 18:10 AnslemHack

@devmashael1-prog was able to replicate this, here's a simple fix https://github.com/iamkun/dayjs/pull/2952 now waiting for feedback from the maintainer

AnslemHack avatar Oct 31 '25 19:10 AnslemHack

"dayjs": "^1.11.10",

dev-mashael-otb avatar Oct 31 '25 20:10 dev-mashael-otb

@AnslemHack Great, thanks for the quick fix 🙌 I will test it after merge

dev-mashael-otb avatar Oct 31 '25 22:10 dev-mashael-otb

I think the same meridiem condition might also need to be updated in the other Arabic locales

dev-mashael-otb avatar Nov 02 '25 05:11 dev-mashael-otb

@dev-mashael-otb Good point I’ll review the other Arabic locale files and align the meridiem logic for consistency. Appreciate the heads-up!

AnslemHack avatar Nov 02 '25 12:11 AnslemHack

@dev-mashael-otb I have now extended the fix to other arabic locales @iamkun care to look at this

AnslemHack avatar Dec 02 '25 20:12 AnslemHack