Skip to content

Commit ef5e75f

Browse files
committed
Fall back to 'en' if format_date is called with a falsy value
Refs python-babel/babel#1183
1 parent 2fa51bb commit ef5e75f

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

sphinx/util/i18n.py

+8
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,14 @@ def babel_format_date(
228228
if not hasattr(date, 'tzinfo'):
229229
formatter = babel.dates.format_date
230230

231+
if not locale:
232+
# Babel would not accept a falsy locale
233+
# (or would try to fall back to the LC_TIME
234+
# locale, which would be not what was requested),
235+
# so we can just short-cut to English, as we
236+
# would for the `"fallback to English"` case.
237+
locale = 'en'
238+
231239
try:
232240
return formatter(date, format, locale=locale)
233241
except (ValueError, babel.core.UnknownLocaleError):

tests/test_util/test_util_i18n.py

-7
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44

55
import datetime
66
import os
7-
import sys
87
import time
98
from pathlib import Path
109
from typing import TYPE_CHECKING
1110

12-
import babel
1311
import pytest
1412
from babel.messages.mofile import read_mo
1513

@@ -60,11 +58,6 @@ def test_catalog_write_mo(tmp_path):
6058
assert read_mo(f) is not None
6159

6260

63-
# https://github.com/python-babel/babel/issues/1183
64-
@pytest.mark.xfail(
65-
sys.platform == 'win32' and babel.__version__ == '2.17.0',
66-
reason='Windows tests fail with Babel 2.17',
67-
)
6861
def test_format_date():
6962
date = datetime.date(2016, 2, 7)
7063

0 commit comments

Comments
 (0)