gtalarico / pyairtable

Python Api Client for Airtable
https://pyairtable.readthedocs.io
MIT License
765 stars 138 forks source link

to_airtable_value() might not be correct for date and datetime values #304

Closed NicoHood closed 6 months ago

NicoHood commented 1 year ago

Hi, I want to compare if a datetime field is set to a very specific time.

{Start (Integration)}=2023-09-08T00:00:00.000+02:00Z

However that does not work, we need to use this instead:

{Start}=DATETIME_PARSE('2023-09-08T00:00:00.000+02:00Z')

When constructing a formula in code, I used the to_airtable_value function. However that does not seems to be enough, as we also need the datetime parsing.

EQUAL(formulas.FIELD('Start'), formulas.to_airtable_value(fixed_date))

So I used this:

def DATETIME_PARSE(value: datetime|date) -> str:
    return "DATETIME_PARSE({})".format(formulas.STR_VALUE(formulas.to_airtable_value(value)))

Now my question is: should we include this by default? Do we need to fix that function, as a leftalone iso string would never be accepted anyways? I guess this could be a bug, but I dont know if there are other usecases where is is a desired behavior.

mesozoic commented 12 months ago

Good catch! IMHO the match function should figure this out for you.

I think the formulas module generally needs a rethink, since there are hundreds of Airtable formula functions and the module doesn't offer a sustainable way of supporting all of them.

mesozoic commented 8 months ago

See #329 for a proposed fix.