Skip to content

Commit

Permalink
Add datetime provider for gu_IN locale (#2123)
Browse files Browse the repository at this point in the history
  • Loading branch information
wh0th3h3llam1 authored Oct 21, 2024
1 parent 55ccb6f commit 033b99f
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
76 changes: 76 additions & 0 deletions faker/providers/date_time/gu_IN/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from .. import Provider as DateTimeProvider


class Provider(DateTimeProvider):

DAY_NAMES = {
"0": "Ravivar",
"1": "Somvar",
"2": "Mangalvar",
"3": "Budhvar",
"4": "Guruvar",
"5": "Shukravar",
"6": "Shanivar",
}

DAY_NAMES_IN_GUJARATI = {
"0": "રવિવાર",
"1": "સોમવાર",
"2": "મંગળવાર",
"3": "બુધવાર",
"4": "ગુરુવાર",
"5": "શુક્રવાર",
"6": "શનિવાર",
}

MONTH_NAMES = {
"01": "Kartak",
"02": "Magshar",
"03": "Posh",
"04": "Maha",
"05": "Fagan",
"06": "Chaitra",
"07": "Vaishakh",
"08": "Jeth",
"09": "Ashadh",
"10": "Shravan",
"11": "Bhadarvo",
"12": "Aaso",
}

MONTH_NAMES_IN_GUJARATI = {
"01": "કારતક",
"02": "માગશર",
"03": "પોષ",
"04": "મહા",
"05": "ફાગણ",
"06": "ચૈત્ર",
"07": "વૈશાખ",
"08": "જેઠ",
"09": "અષાઢ",
"10": "શ્રાવણ",
"11": "ભાદરવો",
"12": "આસો",
}

def day_of_week(self) -> str:
day = self.date("%w")
return self.DAY_NAMES[day]

def month_name(self) -> str:
month = self.month()
return self.MONTH_NAMES[month]

def day_of_week_in_guj(self) -> str:
"""Returns day of the week in `Gujarati`"""
day = self.date("%w")
return self.DAY_NAMES_IN_GUJARATI[day]

def month_name_in_guj(self) -> str:
"""Returns month name in `Gujarati`"""
month = self.month()
return self.MONTH_NAMES_IN_GUJARATI[month]

def month_in_guj(self) -> str:
"""Returns month name in `Gujarati`"""
return self.month_name()
30 changes: 30 additions & 0 deletions tests/providers/test_date_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from faker.providers.date_time.el_GR import Provider as ElGrProvider
from faker.providers.date_time.es_ES import Provider as EsEsProvider
from faker.providers.date_time.fr_FR import Provider as FrFrProvider
from faker.providers.date_time.gu_IN import Provider as GuINProvider
from faker.providers.date_time.hy_AM import Provider as HyAmProvider
from faker.providers.date_time.it_IT import Provider as ItItProvider
from faker.providers.date_time.ja_JP import Provider as JaJpProvider
Expand Down Expand Up @@ -1357,6 +1358,35 @@ def test_month(self):
assert day in FrFrProvider.MONTH_NAMES.values()


class TestGuIN(unittest.TestCase):
"""Test `gu_IN` (Gujarati) provider for date_time"""

def setUp(self):
self.fake = Faker("gu_IN")
Faker.seed(0)

def test_day(self):
day = self.fake.day_of_week()
assert day in GuINProvider.DAY_NAMES.values()

def test_month(self):
month = self.fake.month_name()
assert month in GuINProvider.MONTH_NAMES.values()

def test_day_in_guj(self):
day = self.fake.day_of_week_in_guj()
assert day in GuINProvider.DAY_NAMES_IN_GUJARATI.values()

def test_month_in_guj(self):
"""Test `month_in_guj` and `month_names_in_guj` methods"""

month = self.fake.month_name_in_guj()
assert month in GuINProvider.MONTH_NAMES_IN_GUJARATI.values()

month = self.fake.month_in_guj()
assert month in GuINProvider.MONTH_NAMES_IN_GUJARATI.values()

Check failure on line 1387 in tests/providers/test_date_time.py

View workflow job for this annotation

GitHub Actions / test_ubuntu (3.9)

AssertionError

Check failure on line 1387 in tests/providers/test_date_time.py

View workflow job for this annotation

GitHub Actions / test_ubuntu (3.11)

AssertionError


class TestJaJp(unittest.TestCase):
def setUp(self):
self.fake = Faker("ja_JP")
Expand Down

0 comments on commit 033b99f

Please sign in to comment.