by_star icon indicating copy to clipboard operation
by_star copied to clipboard

Methods like by_week and by_month don't work on fields of Date type?

Open neverhoodboy opened this issue 1 year ago • 0 comments

I'm on by_star version 4.0.1.

Suppose I'm at UTC-08:00 timezone and I have a config/application.rb like this:

class Application < Rails::Application
  config.time_zone = "Pacific Time (US & Canada)"
end

The following method call

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

will generate a query like this:

SELECT `model_xs`.* FROM `model_xs` WHERE (field_a >= '2023-02-01 08:00:00' AND field_a <= '2023-03-01 07:59:59')

which is problematic because we cannot compare local date to UTC timestamp. Records with 2023-02-01 on field_a will not be included in the query result and records with 2023-03-01 on field_a will be.

I also came across this closed issue: https://github.com/radar/by_star/issues/49 According to this issue, the problem should be solved already. I'm not sure if I misunderstood the problem here.

neverhoodboy avatar Feb 26 '23 09:02 neverhoodboy