Make date fields be datetime objects #24
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #12
This PR makes the date fields of all the classes in this library be
datetime
objects and, perhaps more importantly, adds atests.py
file that tests all of these fields.I looked into putting the parsing logic in utils.py as proposed in the issue. However, I ran into the problem that the OpenFEC API returns a number of formats for its various date fields. I considered adding a dependency on dateutil, but wanted to keep the list of dependencies to a minimum.Alsoyield cls(**result)
gets called in multiple places in utils.py. It seemed like less repetition to handle conversion from string to datetime in the constructor of every class than to iterate over every key of every result in multiple places in utils.py.Update (6/15/2018) I just updated this PR to use a utility function for setting attributes of an an instance, provided an object of date fields, with the value being a format string that can be passed to datetime.strptime.
I'm definitely open to doing this another way, though. I'd love to hear your thoughts.