Skip to content

Commit 5086d1b

Browse files
committed
Rename formatters submodule and classes to converters
resolves #100
1 parent 759ec58 commit 5086d1b

File tree

18 files changed

+166
-165
lines changed

18 files changed

+166
-165
lines changed

src/undate/converters/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from undate.converters.base import BaseDateConverter as BaseDateConverter
Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"""
2-
Base class for date format parsing and serializing
2+
Base class for converting date between different formats and calendars.
33
4-
To add support for a new date format:
4+
To add support for a new date format or conversion:
55
6-
- create a new file under undate/dateformat
7-
- extend BaseDateFormat and implement parse and to_string methods
6+
- create a new file or module under undate/converters
7+
- extend BaseDateConverter and implement parse and to_string methods
88
as desired/appropriate
99
10-
It should be loaded automatically and included in the formatters
11-
returned by :meth:`BaseDateFormat.available_formatters`
10+
The new subclass should be loaded automatically and included in the converters
11+
returned by :meth:`BaseDateConverter.available_converters`
1212
1313
"""
1414

@@ -21,11 +21,12 @@
2121
logger = logging.getLogger(__name__)
2222

2323

24-
class BaseDateFormat:
25-
"""Base class for parsing and formatting dates for specific formats."""
24+
class BaseDateConverter:
25+
"""Base class for parsing, formatting, and converting dates to handle
26+
specific formats and different calendars."""
2627

2728
# Subclasses should define a unique name.
28-
name: str = "Base Formatter"
29+
name: str = "Base Converter"
2930

3031
def parse(self, value: str):
3132
# can't add type hint here because of circular import
@@ -40,22 +41,22 @@ def to_string(self, undate) -> str:
4041
# cache import class method to ensure we only import once
4142
@classmethod
4243
@cache
43-
def import_formatters(cls) -> int:
44-
"""Import all undate.dateformat formatters
45-
so that they will be included in available formatters
44+
def import_converters(cls) -> int:
45+
"""Import all undate converters
46+
so that they will be included in available converters
4647
even if not explicitly imported. Only import once.
4748
returns the count of modules imported."""
4849

49-
logger.debug("Loading formatters under undate.dateformat")
50-
import undate.dateformat
50+
logger.debug("Loading converters under undate.converters")
51+
import undate.converters
5152

5253
# load packages under this path with curent package prefix
53-
formatter_path = undate.dateformat.__path__
54-
formatter_prefix = f"{undate.dateformat.__name__}."
54+
converter_path = undate.converters.__path__
55+
converter_prefix = f"{undate.converters.__name__}."
5556

5657
import_count = 0
5758
for importer, modname, ispkg in pkgutil.iter_modules(
58-
formatter_path, formatter_prefix
59+
converter_path, converter_prefix
5960
):
6061
# import everything except the current file
6162
if not modname.endswith(".base"):
@@ -65,7 +66,7 @@ def import_formatters(cls) -> int:
6566
return import_count
6667

6768
@classmethod
68-
def available_formatters(cls) -> Dict[str, Type["BaseDateFormat"]]:
69-
# ensure undate formatters are imported
70-
cls.import_formatters()
69+
def available_converters(cls) -> Dict[str, Type["BaseDateConverter"]]:
70+
# ensure undate converters are imported
71+
cls.import_converters()
7172
return {c.name: c for c in cls.__subclasses__()} # type: ignore
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from undate.converters.edtf.converter import EDTFDateConverter as EDTFDateConverter

src/undate/dateformat/edtf/formatter.py renamed to src/undate/converters/edtf/converter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
from lark.exceptions import UnexpectedCharacters
44

5+
from undate.converters.base import BaseDateConverter
6+
from undate.converters.edtf.parser import edtf_parser
7+
from undate.converters.edtf.transformer import EDTFTransformer
58
from undate.date import DatePrecision
6-
from undate.dateformat.base import BaseDateFormat
7-
from undate.dateformat.edtf.parser import edtf_parser
8-
from undate.dateformat.edtf.transformer import EDTFTransformer
99
from undate.undate import Undate, UndateInterval
1010

1111
EDTF_UNSPECIFIED_DIGIT: str = "X"
1212

1313

14-
class EDTFDateFormat(BaseDateFormat):
14+
class EDTFDateConverter(BaseDateConverter):
1515
name: str = "EDTF"
1616

1717
def __init__(self):

src/undate/dateformat/iso8601.py renamed to src/undate/converters/iso8601.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from typing import Dict, List, Union
22

3-
from undate.dateformat.base import BaseDateFormat
3+
from undate.converters.base import BaseDateConverter
44
from undate.undate import Undate, UndateInterval
55

66

7-
class ISO8601DateFormat(BaseDateFormat):
7+
class ISO8601DateFormat(BaseDateConverter):
88
# NOTE: do we care about validation? could use regex
99
# but maybe be permissive, warn if invalid but we can parse
1010

src/undate/dateformat/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/undate/dateformat/edtf/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)