From 1596feef1f66b139a65be5f39a70d1bdebf25516 Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Tue, 27 Jun 2023 01:08:42 -0500 Subject: [PATCH] sheetsync: Treat end time "--" as same as start time This is a common idiom, which we previously treated like a blank end time (no end time set yet) but it makes more sense to treat as "same as start". --- sheetsync/sheetsync/main.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/sheetsync/sheetsync/main.py b/sheetsync/sheetsync/main.py index 95ddce2..2f77639 100644 --- a/sheetsync/sheetsync/main.py +++ b/sheetsync/sheetsync/main.py @@ -111,8 +111,8 @@ class SheetSync(object): # interpreted as None. # Columns missing from this map default to simply using the string value. self.column_parsers = { - 'event_start': self.parse_bustime, - 'event_end': self.parse_bustime, + 'event_start': lambda v: self.parse_bustime(v), + 'event_end': lambda v: self.parse_bustime(v, preserve_dash=True), 'poster_moment': lambda v: v == '[\u2713]', # check mark 'image_links': lambda v: [link.strip() for link in v.split()] if v.strip() else [], 'tags': lambda v: [tag.strip() for tag in v.split(',') if tag.strip()], @@ -137,10 +137,15 @@ class SheetSync(object): 'error', ] - def parse_bustime(self, value): - """Convert from HH:MM or HH:MM:SS format to datetime""" - if value.strip() in ('--', ''): + def parse_bustime(self, value, preserve_dash=False): + """Convert from HH:MM or HH:MM:SS format to datetime. + If preserve_dash=True and value is "--", returns "--" + as a sentinel value instead of None. "" will still result in None. + """ + if not value.strip(): return None + if value.strip() == "--": + return "--" if preserve_dash else None bustime = common.parse_bustime(value) return common.bustime_to_dt(self.bustime_start, bustime) @@ -261,6 +266,9 @@ class SheetSync(object): ] + (['Poster Moment'] if row_dict['poster_moment'] else []) + row_dict['tags'] ) + # As a special case, treat an end time of "--" as equal to the start time. + if row_dict["event_end"] == "--": + row_dict["event_end"] = row_dict["event_start"] return row_dict def sync_row(self, worksheet, row_index, row, event):