-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from JGreenlee/datepicker-fixes
📅 Datepicker: set initial range, use unambiguous date format, use `arrow`, dropdown for `timezone` option
- Loading branch information
Showing
6 changed files
with
167 additions
and
126 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ python-jose==3.3.0 | |
flask==2.2.5 | ||
flask-talisman==1.0.0 | ||
dash_auth==2.0.0 | ||
arrow==1.3.0 |
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,32 @@ | ||
import arrow | ||
|
||
MAX_EPOCH_TIME = 2 ** 31 - 1 | ||
|
||
|
||
def iso_range_to_ts_range(start_date: str, end_date: str, tz: str): | ||
""" | ||
Returns a tuple of (start_ts, end_ts) as epoch timestamps, given start_date and end_date in | ||
ISO format and the timezone mode in which the dates should be resolved to timestamps ('utc' or 'local') | ||
""" | ||
start_ts, end_ts = None, MAX_EPOCH_TIME | ||
if start_date is not None: | ||
if tz == 'utc': | ||
start_ts = arrow.get(start_date).timestamp() | ||
elif tz == 'local': | ||
start_ts = arrow.get(start_date, tzinfo='local').timestamp() | ||
if end_date is not None: | ||
if tz == 'utc': | ||
end_ts = arrow.get(end_date).replace( | ||
hour=23, minute=59, second=59).timestamp() | ||
elif tz == 'local': | ||
end_ts = arrow.get(end_date, tzinfo='local').replace( | ||
hour=23, minute=59, second=59).timestamp() | ||
return (start_ts, end_ts) | ||
|
||
|
||
def iso_to_date_only(*iso_strs: str): | ||
""" | ||
For each ISO date string in the input, returns only the date part in the format 'YYYY-MM-DD' | ||
e.g. '2021-01-01T00:00:00.000Z' -> '2021-01-01' | ||
""" | ||
return [iso_str[:10] if iso_str else None for iso_str in iso_strs] |
Oops, something went wrong.