Skip to content

Commit 4b5918a

Browse files
committed
debug wip
1 parent 500b9f6 commit 4b5918a

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

src/wtforms/fields/datetime.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def __init__(
3434
def _value(self):
3535
if self.raw_data:
3636
return " ".join(self.raw_data)
37-
return self.data and self.data.strftime(self.format[0]) or ""
37+
format = self.format[0]
38+
return self.data and self.data.strftime(format) or ""
3839

3940
def process_formdata(self, valuelist):
4041
if not valuelist:

src/wtforms/utils.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import os
12
import re
23

4+
_LEADING_SYMBOL = "#" if os.name == "nt" else "-"
5+
36
# https://docs.python.org/3/library/datetime.html#technical-detail (see NOTE #9)
47
_DATETIME_STRIP_ZERO_PADDING_FORMATS_RE = re.compile(
5-
"%-["
8+
f"%{_LEADING_SYMBOL}["
69
"d" # day of month
710
"m" # month
811
"H" # hour (24-hour)
@@ -25,7 +28,7 @@ def clean_datetime_format_for_strptime(formats):
2528
return [
2629
re.sub(
2730
_DATETIME_STRIP_ZERO_PADDING_FORMATS_RE,
28-
lambda m: m[0].replace("-", ""),
31+
lambda m: m[0].replace(_LEADING_SYMBOL, ""),
2932
format,
3033
)
3134
for format in formats

tests/fields/test_datetime.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from datetime import datetime
23

34
from tests.common import DummyPostData
@@ -12,7 +13,9 @@ def make_form(name="F", **fields):
1213
class F(Form):
1314
a = DateTimeField()
1415
b = DateTimeField(format="%Y-%m-%d %H:%M")
15-
c = DateTimeField(format="%-m/%-d/%Y %-I:%M")
16+
c = DateTimeField(
17+
format="%#m/%#d/%Y %#I:%M" if os.name == "nt" else "%-m/%-d/%Y %-I:%M"
18+
)
1619

1720

1821
def test_basic():

tests/fields/test_datetimelocal.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from datetime import datetime
23

34
from tests.common import DummyPostData
@@ -12,7 +13,9 @@ def make_form(name="F", **fields):
1213
class F(Form):
1314
a = DateTimeLocalField()
1415
b = DateTimeLocalField(format="%Y-%m-%d %H:%M")
15-
c = DateTimeLocalField(format="%-m/%-d/%Y %-I:%M")
16+
c = DateTimeLocalField(
17+
format="%#m/%#d/%Y %#I:%M" if os.name == "nt" else "%-m/%-d/%Y %-I:%M"
18+
)
1619

1720

1821
def test_basic():

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ deps =
1111
babel
1212
email_validator
1313
commands =
14-
pytest --tb=short --basetemp={envtmpdir} {posargs}
14+
pytest --tb=short -l --basetemp={envtmpdir} {posargs}
1515

1616
[testenv:coverage]
1717
deps =

0 commit comments

Comments
 (0)