I also inlined all the let, before, and subject pieces of the spec/requests/absences_spec.rb in its own commit. This would be a good one to review one commit at a time.
https://gitlab.com/food-rescue-alliance/tomato/-/issues/210
A user can only automatically create an absence when the absence starts at least 7 days out. 6 days will result in a "too soon" error. However, we sent time stamps with the user's system offset (as they appear in
UTC) when scheduling an absence.
This is a problem because if the user is in a different, earlier timezone, selecting an absence starting 7 days from now is actually a little behind.
For example, if the volunteer has their time zone set to Los Angeles, but is currently in New York, they will submit an absence that looks like this:
{
"ends_at": "2025年08月19日T04:00:00.000Z",
"starts_at": "2025年08月19日T04:00:00.000Z"
}
The server used to take that time stamp and compare it to Absence::ABSENCE_LEAD_TIME.from_now.beginning_of_day which is parsed as the volunteer's time zone:
Absence::ABSENCE_LEAD_TIME.from_now.beginning_of_day
# 2025年8月19日 00:00:00.000000000 PDT -07:00
When the two are compared, starts_at is later than the cutoff time.
To fix this, we first convert the starts_at to a date. This is how the database stores the data already, and it also ensures that a few hours difference won't matter.
This does not solve the problem if the user is in a time zone that is currently a different date than their set zone. We're not solving that right now.
_I also inlined all the `let`, `before`, and `subject` pieces of the `spec/requests/absences_spec.rb` in its own commit. This would be a good one to review one commit at a time._
https://gitlab.com/food-rescue-alliance/tomato/-/issues/210
A user can only automatically create an absence when the absence starts at least 7 days out. 6 days will result in a "too soon" error. However, we sent time stamps with the user's system offset (as they appear in
UTC) when scheduling an absence.
This is a problem because if the user is in a different, earlier timezone, selecting an absence starting 7 days from now is actually a little behind.
For example, if the volunteer has their time zone set to Los Angeles, but is currently in New York, they will submit an absence that looks like this:
```json
{
"ends_at": "2025年08月19日T04:00:00.000Z",
"starts_at": "2025年08月19日T04:00:00.000Z"
}
```
The server used to take that time stamp and compare it to `Absence::ABSENCE_LEAD_TIME.from_now.beginning_of_day` which is parsed as the volunteer's time zone:
```ruby
Absence::ABSENCE_LEAD_TIME.from_now.beginning_of_day
# 2025年8月19日 00:00:00.000000000 PDT -07:00
```
When the two are compared, `starts_at` is later than the cutoff time.
To fix this, we first convert the `starts_at` to a date. This is how the database stores the data already, and it also ensures that a few hours difference won't matter.
This does not solve the problem if the user is in a time zone that is currently a different _date_ than their set zone. We're not solving that right now.