Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for reference times #5

Closed
danp opened this issue Feb 28, 2022 · 4 comments
Closed

Support for reference times #5

danp opened this issue Feb 28, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@danp
Copy link

danp commented Feb 28, 2022

Thanks for this plugin!

As the example says:

dateutil_parse_fuzzy("This is due 10 september") returns 2020-09-10T00:00:00 (but will start returning the 2021 version of that if the year is 2021).

Maybe dateutil doesn't actually support this but it would be really nice to be able to give a reference time to dateutil_parse_fuzzy and probably other functions. For example, suppose I had a table like:

create table times (t datetime);
insert into times values (datetime('now')), (datetime('now', '-1 year')), (datetime('now', '-3 years'));

It would be nice to be able to do something like:

select t, dateutil_parse_fuzzy("This is due 10 september", t) from times

And have dateutil_parse_fuzzy work with t as its reference point.

@simonw simonw added the enhancement New feature or request label Mar 1, 2022
@simonw
Copy link
Owner

simonw commented Mar 1, 2022

The parse() function it uses does have a default=datetime option, which I've not tried myself: https://dateutil.readthedocs.io/en/stable/parser.html#dateutil.parser.parse

  • default -- The default datetime object, if this is a datetime object and not None, elements specified in timestr replace elements in the default object.

@simonw
Copy link
Owner

simonw commented Mar 1, 2022

OK, here's an example query (based on yours) I can use for this:

with times as (
  select
    datetime('now') as t
  union
  select
    datetime('now', '-1 year')
  union
  select
    datetime('now', '-3 years')
)
select t, dateutil_parse_fuzzy("This is due 10 september", t) from times

@simonw simonw closed this as completed in 8356683 Mar 1, 2022
simonw added a commit that referenced this issue Mar 1, 2022
simonw added a commit to simonw/latest-datasette-with-all-plugins that referenced this issue Mar 1, 2022
@danp
Copy link
Author

danp commented Mar 1, 2022

Amazing, thank you! That will be very handy for some scraping of hand-managed sites I'm doing with https://github.com/danp/scraperlite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants