Skip to content

Commit

Permalink
Converter for datetime column
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinStrohalm committed Nov 3, 2023
1 parent 426af7e commit 48e22cc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyeds/report/converters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# import objects
from .converter import CONVERTERS, register, ValueConverter

from . import datetimes
from . import arrays
from . import spectrum
from . import pattern
Expand Down
33 changes: 33 additions & 0 deletions pyeds/report/converters/datetimes.py
Original file line number Diff line number Diff line change
@@ -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')

0 comments on commit 48e22cc

Please sign in to comment.