-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
42 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from datetime import datetime | ||
|
||
from parasolr.utils import solr_timestamp_to_datetime | ||
|
||
|
||
def test_solr_timestamp_to_datetime(): | ||
# with microseconds | ||
solr_dt = solr_timestamp_to_datetime('2018-07-02T21:08:46.428Z') | ||
assert solr_dt == datetime(2018, 7, 2, 21, 8, 46) | ||
# without | ||
solr_dt = solr_timestamp_to_datetime('2018-07-02T21:08:46Z') | ||
assert solr_dt == datetime(2018, 7, 2, 21, 8, 46) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from datetime import datetime | ||
|
||
|
||
def solr_timestamp_to_datetime(solr_time): | ||
"""Convert Solr timestamp (isoformat that may or may not include | ||
microseconds) to :class:`datetime.datetime`""" | ||
# Solr stores date in isoformat; convert to datetime object | ||
# - microseconds only included when second is not exact; strip out if | ||
# they are present | ||
if '.' in solr_time: | ||
solr_time = '%sZ' % solr_time.split('.')[0] | ||
return datetime.strptime(solr_time, '%Y-%m-%dT%H:%M:%SZ') |