more logging, more ideas

This commit is contained in:
Daniel Tsvetkov 2021-05-11 15:25:50 +02:00
parent 8c68d50964
commit 4b5122ab39
4 changed files with 37 additions and 5 deletions

View File

@ -7,6 +7,12 @@ python tww QUERY [--debug] [--full]
``` ```
* Supported `QUERY` types: * Supported `QUERY` types:
- Just time: `<datetime-like>`:
- `now`
- `in 5 hours`
- `5 January 2012`
- `4:26 PM`
- `April 2020`
- Timezone translation `<datetime-like> in <timezone/location> to <destination timezone/location>` or `<datetime-like> to <timezone/location>` (assumes datetime is `local`) - Timezone translation `<datetime-like> in <timezone/location> to <destination timezone/location>` or `<datetime-like> to <timezone/location>` (assumes datetime is `local`)
- `04:26 in japan to local` - `04:26 in japan to local`
- `03:14 in local to IST` - `03:14 in local to IST`
@ -19,8 +25,7 @@ python tww QUERY [--debug] [--full]
- (Approximate) workdays calculation (assumes monday-friday are work days - ignores public/local holidays (for now)): `work days/hours since/until <datetime-like>` or ` - (Approximate) workdays calculation (assumes monday-friday are work days - ignores public/local holidays (for now)): `work days/hours since/until <datetime-like>` or `
- `workdays since 2021-01-05` - `workdays since 2021-01-05`
- `work hours until Friday` - `work hours until Friday`
- Milliseconds since epoch: `(time/seconds) since epoch` - Milliseconds since epoch: `(time/(milli)seconds) since epoch` or datetime to epoch: `<datetime-like> to epoch` or `(milli)seconds since <datetime-like>/epoch`
- Datetime to epoch: `<datetime-like> to epoch` or `(milli)seconds since <datetime-like>/epoch`
- `2021-01:01 to epoch` - `2021-01:01 to epoch`
- `milliseconds since epoch` - `milliseconds since epoch`
@ -93,3 +98,23 @@ Time in one timezone (pst) to another in city:
$ tww 3/14 15 9:26:53 PST to sofia $ tww 3/14 15 9:26:53 PST to sofia
2015-03-14 19:26:53+02:00 2015-03-14 19:26:53+02:00
``` ```
## TODO
* Calculate time differences:
- parse `timedelta`:
- `(%d) (?year|month|week|day|hour|minute|second)[s]?`
- calculate:
- `<dt-like> (?\+|\-|plus|minus) <timedelta>`
- `12-12-2019 + 2 weeks`
- `05:23 - 150 minutes`
- `<timedelta> (before|from) <dt>`
- `3 days from next Friday`
- `2 hours before 15:00`
* Day of the week
- `what day is <dt>`
* Return Time range
- parse relative to now:
- `(previous|last|this|next) (year|month|week|day|hour|minute|second|Monday|Tuesday|...|Sunday)`
* [Countries names in their own languages](https://www.worldatlas.com/articles/names-of-countries-in-their-own-languages.html), [list of countries in various languages](https://en.wikipedia.org/wiki/List_of_country_names_in_various_languages_(A%E2%80%93C))

View File

@ -584,8 +584,10 @@ def dateparser_parse_dt(s: str):
s = custom_dt_parse(s) s = custom_dt_parse(s)
s = regex_parsers(s) s = regex_parsers(s)
parsed = parse_dt(s) parsed = parse_dt(s)
logger.debug("Parse dt: {}".format(parsed))
if not parsed: if not parsed:
parsed = dutil_parse(s) parsed = dutil_parse(s)
logger.debug("dutil_parse: {}".format(parsed))
if not parsed: if not parsed:
return None return None
if parsed.tzinfo is None: if parsed.tzinfo is None:
@ -601,8 +603,12 @@ def get_utcnow(tzaware: bool = True):
def get_local_now(tzaware: bool = True): def get_local_now(tzaware: bool = True):
if tzaware: if tzaware:
return datetime.now().replace(tzinfo=tzinfo_from_offset(get_local_tz_offset())[0]) dt = datetime.now().replace(tzinfo=tzinfo_from_offset(get_local_tz_offset())[0])
return datetime.utcnow() logger.debug("Local now (tzaware): {}".format(dt))
return dt
dt = datetime.utcnow()
logger.debug("Local now (utc): {}".format(dt))
return dt
def split_offset(offset): def split_offset(offset):

View File

@ -56,8 +56,10 @@ def handler_time_now_utc():
def dt_normalize(start_dt, end_dt) -> (datetime, datetime): def dt_normalize(start_dt, end_dt) -> (datetime, datetime):
if type(start_dt) is str: if type(start_dt) is str:
start_dt = dateparser_parse_dt(start_dt) start_dt = dateparser_parse_dt(start_dt)
logger.debug("Start time: {}".format(start_dt))
if type(end_dt) is str: if type(end_dt) is str:
end_dt = dateparser_parse_dt(end_dt) end_dt = dateparser_parse_dt(end_dt)
logger.debug("End time: {}".format(end_dt))
return start_dt, end_dt return start_dt, end_dt

View File

@ -107,7 +107,6 @@ def render_solution(solution):
return render_template("td.html", **solution) return render_template("td.html", **solution)
def render_solutions(results): def render_solutions(results):
rv = [] rv = []
for solution in results['solutions']: for solution in results['solutions']: