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

Regression on datetime fields with sub-second precision? #96

Open
neverhoodboy opened this issue Feb 26, 2023 · 0 comments
Open

Regression on datetime fields with sub-second precision? #96

neverhoodboy opened this issue Feb 26, 2023 · 0 comments

Comments

@neverhoodboy
Copy link

neverhoodboy commented Feb 26, 2023

I'm on by_star version 4.0.1.

Suppose I have a datetime field with microsecond precision:

create_table :table_xs do |t|
  t.datetime "field_a", precision: 6
end

The following method call

TableX.by_day(Date.today, field: field_a) # Today is 2023-02-26.

will generate a query like this (suppose I'm at UTC+00:00 timezone):

SELECT `table_xs`.* FROM `table_xs` WHERE (field_a >= '2023-02-26 00:00:00' AND field_a <= '2023-02-26 23:59:59')

which is problematic because records with field_a between 2023-02-26 23:59:59.000000 and 2023-02-26 23:59:59.999999 will not be included in the query result. (Yes, the excluded range starts from 2023-02-26 23:59:59.000000, not 2023-02-26 23:59:59.000001.)

by_star version 3.0.0 handled sub-second precision datetime fields correctly. The same method call as above would generate the following query:

SELECT `table_xs`.* FROM `table_xs` WHERE (field_a >= '2023-02-26 00:00:00.000000' AND field_a <= '2023-02-26 23:59:59.999999')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant