Repository: crsmithdev/arrow
Pull request #677 (2019-09-16 14:43:20)

i18n(locales): add week granularity localization for Spanish
Add week granularity for Spanish location.
Related issue: https://github.com/crsmithdev/arrow/issues/676


Patch:
diff --git a/arrow/locales.py b/arrow/locales.py
index 0be975d..c27a11e 100644
--- a/arrow/locales.py
+++ b/arrow/locales.py
@@ -374,6 +374,8 @@ class SpanishLocale(Locale):
         "hours": "{0} horas",
         "day": "un día",
         "days": "{0} días",
+        "week": "una semana",
+        "weeks": "{0} semanas",
         "month": "un mes",
         "months": "{0} meses",
         "year": "un año",


Test patch:
diff --git a/tests/locales_tests.py b/tests/locales_tests.py
index acc744e..86f6f5f 100644
--- a/tests/locales_tests.py
+++ b/tests/locales_tests.py
@@ -150,6 +150,54 @@ class SpanishLocalesTests(Chai):
 
         self.assertEqual(locale.ordinal_number(1), "1º")
 
+    def test_format_timeframe(self):
+        locale = locales.SpanishLocale()
+        self.assertEqual(locale._format_timeframe("now", 0), "ahora")
+        self.assertEqual(locale._format_timeframe("seconds", 1), "segundos")
+        self.assertEqual(locale._format_timeframe("seconds", 3), "segundos")
+        self.assertEqual(locale._format_timeframe("seconds", 30), "segundos")
+        self.assertEqual(locale._format_timeframe("minute", 1), "un minuto")
+        self.assertEqual(locale._format_timeframe("minutes", 4), "4 minutos")
+        self.assertEqual(locale._format_timeframe("minutes", 40), "40 minutos")
+        self.assertEqual(locale._format_timeframe("hour", 1), "una hora")
+        self.assertEqual(locale._format_timeframe("hours", 5), "5 horas")
+        self.assertEqual(locale._format_timeframe("hours", 23), "23 horas")
+        self.assertEqual(locale._format_timeframe("day", 1), "un día")
+        self.assertEqual(locale._format_timeframe("days", 6), "6 días")
+        self.assertEqual(locale._format_timeframe("days", 12), "12 días")
+        self.assertEqual(locale._format_timeframe("week", 1), "una semana")
+        self.assertEqual(locale._format_timeframe("weeks", 2), "2 semanas")
+        self.assertEqual(locale._format_timeframe("weeks", 3), "3 semanas")
+        self.assertEqual(locale._format_timeframe("month", 1), "un mes")
+        self.assertEqual(locale._format_timeframe("months", 7), "7 meses")
+        self.assertEqual(locale._format_timeframe("months", 11), "11 meses")
+        self.assertEqual(locale._format_timeframe("year", 1), "un año")
+        self.assertEqual(locale._format_timeframe("years", 8), "8 años")
+        self.assertEqual(locale._format_timeframe("years", 12), "12 años")
+
+        self.assertEqual(locale._format_timeframe("now", 0), "ahora")
+        self.assertEqual(locale._format_timeframe("seconds", -1), "segundos")
+        self.assertEqual(locale._format_timeframe("seconds", -9), "segundos")
+        self.assertEqual(locale._format_timeframe("seconds", -12), "segundos")
+        self.assertEqual(locale._format_timeframe("minute", -1), "un minuto")
+        self.assertEqual(locale._format_timeframe("minutes", -2), "2 minutos")
+        self.assertEqual(locale._format_timeframe("minutes", -10), "10 minutos")
+        self.assertEqual(locale._format_timeframe("hour", -1), "una hora")
+        self.assertEqual(locale._format_timeframe("hours", -3), "3 horas")
+        self.assertEqual(locale._format_timeframe("hours", -11), "11 horas")
+        self.assertEqual(locale._format_timeframe("day", -1), "un día")
+        self.assertEqual(locale._format_timeframe("days", -2), "2 días")
+        self.assertEqual(locale._format_timeframe("days", -12), "12 días")
+        self.assertEqual(locale._format_timeframe("week", -1), "una semana")
+        self.assertEqual(locale._format_timeframe("weeks", -2), "2 semanas")
+        self.assertEqual(locale._format_timeframe("weeks", -3), "3 semanas")
+        self.assertEqual(locale._format_timeframe("month", -1), "un mes")
+        self.assertEqual(locale._format_timeframe("months", -3), "3 meses")
+        self.assertEqual(locale._format_timeframe("months", -13), "13 meses")
+        self.assertEqual(locale._format_timeframe("year", -1), "un año")
+        self.assertEqual(locale._format_timeframe("years", -4), "4 años")
+        self.assertEqual(locale._format_timeframe("years", -14), "14 años")
+
 
 class FrenchLocalesTests(Chai):
     def test_ordinal_number(self):