Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Merge 18444b4 into 05774e7
Browse files Browse the repository at this point in the history
  • Loading branch information
leenagupte committed Mar 3, 2016
2 parents 05774e7 + 18444b4 commit 30457d3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
47 changes: 39 additions & 8 deletions backdrop/core/records.py
Expand Up @@ -75,31 +75,62 @@ def parse_timestamps(record):
>>> record
{'_timestamp': 'invalid'}
>>> error
'_timestamp is not a valid timestamp, it must be ISO8601'
'the _timestamp must be a date in the format yyyy-MM-ddT00:00:00Z'
>>> record, error = parse_timestamps({'_timestamp': '31-11-12T00:00:00'})
>>> record
{'_timestamp': '31-11-12T00:00:00'}
>>> error
'31-11-12T00:00:00 in the _timestamp field is not a valid date'
>>> record, error = parse_timestamps({'_start_at': 'invalid'})
>>> record
{'_start_at': 'invalid'}
>>> error
'_start_at is not a valid timestamp, it must be ISO8601'
'_start_at must be a date in the format yyyy-MM-ddT00:00:00Z'
>>> record, error = parse_timestamps({'_start_at': '31-11-12T00:00:00'})
>>> record
{'_start_at': '31-11-12T00:00:00'}
>>> error
'31-11-12T00:00:00 in the _start_at field is not a valid date'
>>> record, error = parse_timestamps({'_end_at': 'invalid'})
>>> record
{'_end_at': 'invalid'}
>>> error
'_end_at must be a date in the format yyyy-MM-ddT00:00:00Z'
>>> record, error = parse_timestamps({'_end_at': '31-11-12T00:00:00'})
>>> record
{'_end_at': '31-11-12T00:00:00'}
>>> error
'31-11-12T00:00:00 in the _end_at field is not a valid date'
"""
error = None
if '_timestamp' in record:
try:
record['_timestamp'] = parse_time_as_utc(record['_timestamp'])
except (TypeError, ValueError):
error = '_timestamp is not a valid timestamp, it must be ISO8601'
except TypeError:
error = 'the _timestamp must be a date in the format ' \
'yyyy-MM-ddT00:00:00Z'
except ValueError:
error = '{} in the _timestamp field is not a valid date'.format(
record['_timestamp'])

if '_start_at' in record:
try:
record['_start_at'] = parse_time_as_utc(record['_start_at'])
except (TypeError, ValueError):
error = '_start_at is not a valid timestamp, it must be ISO8601'
except TypeError:
error = '_start_at must be a date in the format ' \
'yyyy-MM-ddT00:00:00Z'
except ValueError:
error = '{} in the _start_at field is not a valid date'.format(
record['_start_at'])

if '_end_at' in record:
try:
record['_end_at'] = parse_time_as_utc(record['_end_at'])
except (TypeError, ValueError):
error = '_end_at is not a valid timestamp, it must be ISO8601'
except TypeError:
error = '_end_at must be a date in the format yyyy-MM-ddT00:00:00Z'
except ValueError:
error = '{} in the _end_at field is not a valid date'.format(
record['_end_at'])

return (record, error)

Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_data_set.py
Expand Up @@ -168,7 +168,7 @@ def test_store_returns_array_of_errors_if_errors(
is_(True)
)
assert_that(
'_timestamp is not a valid timestamp, it must be ISO8601'
'the _timestamp must be a date in the format yyyy-MM-ddT00:00:00Z'
in errors,
is_(True)
)
Expand Down

0 comments on commit 30457d3

Please sign in to comment.