Skip to content

Commit

Permalink
Merge pull request #17 from LauraMBraun/main
Browse files Browse the repository at this point in the history
Added Deutsch
  • Loading branch information
Proteusiq authored Aug 1, 2023
2 parents 05ede7e + 391904a commit 1b55dc4
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
82 changes: 82 additions & 0 deletions saa/luga/de/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from dataclasses import dataclass
from saa.core.language import Luga

@dataclass(init=False, eq=False, repr=False, frozen=False)
class Deutsch(Luga):
time = {
"to": "{minute} {time_indicator} vor {hour} Uhr",
"past": "{minute} {time_indicator} nach {hour} Uhr",
0: "{hour} Uhr",
15: "Viertel nach {hour}",
45: "Viertel vor {hour}",
30: "Halb {hour}",
}
number_connector = "und"
connect_format = "{0}{1}{2}"
numbers = {
0: "null",
1: "ein", # ein und zwanzig / eine Minute / ein Uhr
2: "zwei",
3: "drei",
4: "vier",
5: "fünf",
6: "sechs",
7: "sieben",
8: "acht",
9: "neun",
10: "zehn",
11: "elf",
12: "zwölf",
13: "dreizehn",
14: "vierzehn",
15: "fünfzehn",
16: "sechzehn",
17: "siebzehn",
18: "achtzehn",
19: "neunzehn",
20: "zwanzig",
30: "dreißig",
40: "vierzig",
50: "fünfzig",
}

@staticmethod
def time_logic(hour, minute) -> tuple[int, int, str, str]:
if minute in [0, 15, 30, 45]:
if minute == 45 or minute == 30:
hour += 1
return (hour, minute, '', '')

is_to = "to" if minute > 30 else "past"
time_indicator = "Minuten" if minute not in [1,59] else "Minute"

if is_to == "to":
hour += 1
minute = 60 - minute

if minute <= 20 or minute == 30 or minute == 40 or minute == 50:
if minute == 1:
minute = Deutsch.numbers[minute][1] if is_to == 'to' else Deutsch.numbers[minute][0]
else:
minute = Deutsch.numbers[minute]
else:
tens = minute // 10 * 10
ones = minute % 10
minute = Deutsch.connect_format.format(Deutsch.numbers[ones], Deutsch.number_connector, Deutsch.numbers[tens])

hour = Deutsch.numbers[hour]

return hour, minute, is_to, time_indicator


@staticmethod
def post_logic(hour, minute, is_to, time_indicator) -> str:
if is_to:
return Deutsch.time[is_to].format(minute=minute, time_indicator=time_indicator, hour=hour)
else:
return Deutsch.time[minute].format(hour=hour)

class Language(Deutsch):
pass


30 changes: 30 additions & 0 deletions tests/test_clock/test_clock_de.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from datetime import time
import pytest
from saa.core.watch import Watch
from saa.core.plugins import supported_languages

German = supported_languages.get("de")

test_cases = [
(time(hour=13, minute=45), German, "viertel vor zwei"),
(time(hour=13, minute=15), German, "viertel nach eins"),
(time(hour=13, minute=30), German, "halb zwei"),
]


@pytest.mark.parametrize("test_input, language, test_output", test_cases)
def test_clocks(test_input, language, test_output):
clock = Watch(language=language)
assert test_output == clock(test_input)


test_plural_cases = [
(time(hour=13, minute=1), German, "eine Minute nach eins"),
(time(hour=6, minute=17), German, "siebzehn Minuten nach sechs"),
]


@pytest.mark.parametrize("test_input, language, test_output", test_plural_cases)
def test_cases(test_input, language, test_output):
clock = Watch(language=language)
assert test_output == clock(test_input)

0 comments on commit 1b55dc4

Please sign in to comment.