diff --git a/pyeds/report/converters/__init__.py b/pyeds/report/converters/__init__.py index cd111f3..3f2cb19 100644 --- a/pyeds/report/converters/__init__.py +++ b/pyeds/report/converters/__init__.py @@ -3,6 +3,7 @@ # import objects from .converter import CONVERTERS, register, ValueConverter +from . import datetimes from . import arrays from . import spectrum from . import pattern diff --git a/pyeds/report/converters/datetimes.py b/pyeds/report/converters/datetimes.py new file mode 100644 index 0000000..18cd7f8 --- /dev/null +++ b/pyeds/report/converters/datetimes.py @@ -0,0 +1,33 @@ +# Created by Martin Strohalm, Thermo Fisher Scientific + +# import modules +from datetime import datetime +from .converter import register, ValueConverter + + +@register("1BDE1686-0CF2-4921-832B-B1EEFF4EB779") +class DateTime(ValueConverter): + """ + The pyeds.DateTime is used to convert datetime string with format + %m/%d/%Y %H:%M:%S into datetime object. + """ + + + def Convert(self, value): + """ + Converts string to datetime. + + Args: + value: str + String data as stored in result file. + + Returns: + datetime or None + Parsed datetime. + """ + + # check value + if not value: + return None + + return datetime.strptime(value, '%m/%d/%Y %H:%M:%S')