Skip to content

Add initial Hindi locale support#645

Open
omeshkumarfso wants to merge 1 commit into
wanasit:masterfrom
kodikasin:feat/hindi-support
Open

Add initial Hindi locale support#645
omeshkumarfso wants to merge 1 commit into
wanasit:masterfrom
kodikasin:feat/hindi-support

Conversation

@omeshkumarfso

Copy link
Copy Markdown

Summary

This PR adds initial Hindi locale support to Chrono.

Supported Features

  • Hindi month names
  • Hindi numeral parsing
  • Casual Hindi expressions
  • Hindi date parsing
  • Hindi time parsing

Supported Examples

  • 5 मई 2026
  • ५ मई २०२६
  • आज
  • अभी
  • बीता कल
  • आने वाला कल
  • शाम ५ बजे
  • सुबह 10:15

Tests

Added unit tests for:

  • absolute dates
  • Hindi numerals
  • casual dates
  • Hindi time expressions
  • combined date and time parsing

All tests and builds pass successfully.

@omeshkumarfso

Copy link
Copy Markdown
Author

Hi!
Just following up on this PR.
The implementation is complete, tests are passing, and there are no merge conflicts.
I'd be happy to make any requested changes if needed.

If the project is still maintained, I'd appreciate a review.

Thanks!

@wanasit

wanasit commented Jul 11, 2026

Copy link
Copy Markdown
Owner

Hello @omeshkumarfso! Thank you so much for putting this together and starting the initial Hindi locale support!

I do not speak the language and, thus, I need to use AI assist to review you change and I agree with its feedback. Could you please address following feedback?


1. Deterministic Tests

In test/hi/hi.test.ts, tests for relative words like "आज" (today), "बीता कल" (yesterday), and "आने वाला कल" (tomorrow) do not specify a reference date. Because these depend on when the tests are run, they can become flaky or run into timezone/date rollover issues.

  • Suggestion: We use the helper testSingleCase to pass a fixed reference date, ensuring tests are completely deterministic. For example:
    import { testSingleCase } from "../test_util";
    
    test("Parse बीता कल", () => {
        testSingleCase(chrono.hi, "बीता कल", new Date(2026, 4, 10), (result) => { // May 10, 2026
            expect(result.start.get("year")).toBe(2026);
            expect(result.start.get("month")).toBe(5); // May is index 5 in Chrono
            expect(result.start.get("day")).toBe(9);   // May 9
        });
    });

2. Time Suffix Matching Bug

In HITimeExpressionParser.ts, if the input has minutes followed by a suffix (e.g., "10:30 बजे"), the parser currently extracts "10:30" but leaves out "बजे" (which means "o'clock"). This is because the regex alternative matches the minutes and finishes before reaching "बजे".

  • Suggestion: We can adjust the regex pattern to optionally allow "बजे" after the minutes group so it extracts the full phrase:
    const PATTERN = /(?:(||||)\s*)?([-0-9]{1,2})(?:(?:\s*:\s*([-0-9]{1,2}))(?:\s*)?|(?:\s*))/i;

3. Common Spelling Variations and Synonyms

To make the parser robust for everyday Hindi usage, it would be great to support some common synonyms and spellings:

  • Weekdays:
    • Sunday: इतवार (very common in casual speech)
    • Thursday: बृहस्पतिवार and वीरवार
    • Saturday: शनि (often used instead of शनिवार)
  • Months:
    • For September, November, and December, Hindi writers commonly use both the anusvara () and the traditional half-m spelling. Adding the half-m variants will prevent parsing failures:
      • September: सितम्बर (in addition to सितंबर)
      • November: नवम्बर (in addition to नवंबर)
      • December: दिसम्बर (in addition to दिसंबर)

Let me know if you disagree with any of those or if you want to defer the change.
Thank you again for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants