Changeset 2e37e80 in rattail


Ignore:
Timestamp:
06/24/2022 02:18:01 PM (5 months ago)
Author:
Lance Edgar <lance@…>
Branches:
master
Children:
a45fe4b
Parents:
f458072
Message:

Add basic date parsing for ExcelReaderXLSX

at least *try* to parse, if given a string value

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rattail/excel.py

    rf458072 r2e37e80  
    128128
    129129    def __init__(self, path, header_row=1, strip_fieldnames=True,
    130                  **kwargs):
     130                 datefmt='%Y-%m-%d', **kwargs):
    131131        """
    132132        Constructor; opens an Excel file for reading.
     
    145145
    146146        self.header_row = header_row
     147        self.datefmt = datefmt
    147148
    148149        self.fields = None
     
    183184    # and/or remove it though
    184185    def parse_date(self, value, fmt=None):
     186        if isinstance(value, six.string_types):
     187            if not value:
     188                return
     189            return datetime.datetime.strptime(value, fmt or self.datefmt).date()
    185190        return value
    186191
Note: See TracChangeset for help on using the changeset viewer.