Skip to content

Commit

Permalink
Fix incorrect time formatting of locale month (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
nasyxx authored and Delgan committed Jan 16, 2019
1 parent 856d81e commit 63d5742
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Unreleased
==========

- Fix incorrect time formatting of locale month using ``MMM`` and ``MMMM`` tokens (`#34 <https://github.com/Delgan/loguru/pull/34>`_, thanks `@nasyxx <https://github.com/nasyxx>`_)
- Fix race condition permitting to write on a stopped handler


Expand Down
4 changes: 2 additions & 2 deletions loguru/_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def __format__(self, spec):
"YYYY": "%04d" % year,
"YY": "%02d" % (year % 100),
"Q": "%d" % ((month - 1) // 3 + 1),
"MMMM": month_name[month - 1],
"MMM": month_abbr[month - 1],
"MMMM": month_name[month],
"MMM": month_abbr[month],
"MM": "%02d" % month,
"M": "%d" % month,
"DDDD": "%03d" % yearday,
Expand Down
9 changes: 9 additions & 0 deletions tests/test_datetime.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import datetime
from loguru import logger
import sys

Expand Down Expand Up @@ -38,6 +39,14 @@ def test_formatting(writer, monkeypatch_date, time_format, date, expected):
assert result == expected + "\n"


def test_locale_formatting(writer, monkeypatch_date):
date = (2011, 1, 1, 22, 22, 22, 0)
monkeypatch_date(*date)
logger.add(writer, format="{time:MMMM MMM dddd ddd}")
logger.debug("Test")
assert writer.read() == datetime.datetime(*date).strftime("%B %b %A %a\n")


def test_stdout_formatting(monkeypatch_date, capsys):
monkeypatch_date(2015, 12, 25, 19, 13, 18, 0, "A", 5400)
logger.add(sys.stdout, format="{time:YYYY [MM] DD HHmmss Z} {message}")
Expand Down

0 comments on commit 63d5742

Please sign in to comment.