graphile-contrib / postgraphile-plugin-connection-filter

Filtering on PostGraphile connections
MIT License
286 stars 32 forks source link

lessThanOrEqualTo work the same as lessThan #184

Closed galvakojis closed 1 year ago

galvakojis commented 2 years ago

For me lessThanOrEqualTo works incorrect, same behavior as lessThan. example in the pictures: image image

is a a bug or my approach are wrong?

zacherkkila commented 1 year ago

2022-09-30 is actually 2022-09-30T00:00:00 in postgres, so midnight on that day. 2022-09-30:08:31:15 is greater than 2022-09-30T00:00:00

What you are actually looking for is lessThan 2022-10-01 to include all of 9-30.

Less than or equal to is pretty useless with dates unless you are passing in an exact timestamp of existing data that you want to include or rounding your saved dates to midnight for some reason

galvakojis commented 1 year ago

thanks, yep it took sometime to understand that this was because of timezone

disarticulate commented 3 months ago

I ran into this issue. I just defined a postgraphile function such as:

CREATE FUNCTION levels_by_date(
    "from" date,
    "to" date
) RETURNS setof levels AS $$
    SELECT *
    FROM levels
    WHERE record_date::date
        BETWEEN "from"::date
            AND "to"::date
    ORDER BY record_date DESC
$$ LANGUAGE sql STABLE;

This gets me the necessary inclusive function. I don't believe I have any timezone issues though, but reading the issue here, this seems preferrable. I could probably include a timezone intent if I had some user who was elsewhere trying to offset themselves. #datesarehard