Skip to content

Commit

Permalink
Add ja_JP locale for datetime (#1888)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanghsieh authored Jul 12, 2023
1 parent 8fb332e commit 696d11e
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
54 changes: 54 additions & 0 deletions faker/providers/date_time/ja_JP/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from .. import Provider as DateTimeProvider


class Provider(DateTimeProvider):
MONTH_NAMES = {
"01": "一月",
"02": "二月",
"03": "三月",
"04": "四月",
"05": "五月",
"06": "六月",
"07": "七月",
"08": "八月",
"09": "九月",
"10": "十月",
"11": "十一月",
"12": "十二月",
}

TRADITIONAL_MONTH_NAMES = {
"01": "睦月",
"02": "如月",
"03": "弥生",
"04": "卯月",
"05": "皐月",
"06": "水無月",
"07": "文月",
"08": "葉月",
"09": "長月",
"10": "神無月",
"11": "霜月",
"12": "師走",
}
DAY_NAMES = {
"0": "日曜日",
"1": "月曜日",
"2": "火曜日",
"3": "水曜日",
"4": "木曜日",
"5": "金曜日",
"6": "土曜日",
}

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 traditional_month_name(self) -> str:
month = self.month()
return self.TRADITIONAL_MONTH_NAMES[month]
19 changes: 19 additions & 0 deletions tests/providers/test_date_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from faker.providers.date_time.fr_FR import Provider as FrFrProvider
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
from faker.providers.date_time.nl_NL import Provider as NlProvider
from faker.providers.date_time.no_NO import Provider as NoNoProvider
from faker.providers.date_time.pl_PL import Provider as PlProvider
Expand Down Expand Up @@ -1264,3 +1265,21 @@ def test_day(self):
def test_month(self):
day = self.fake.month_name()
assert day in FrFrProvider.MONTH_NAMES.values()


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

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

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

def test_traditional_month(self):
month = self.fake.traditional_month_name()
assert month in JaJpProvider.TRADITIONAL_MONTH_NAMES.values()

0 comments on commit 696d11e

Please sign in to comment.