The code builds a daily summary of bookings for a specified time zone. After a recent change, part of the intervals started falling into the wrong local days, and for some records the stored duration changes as a result. A review of the regression by diff is needed to find the causes.
BookingDaySplit#split method accepts an array of bookings and a time zone string in offset format, for example "+03:00" or "-05:00".:id, :starts_at, :ends_at.:starts_at and :ends_at values are Time objects in UTC.:id — the identifier of the original booking;:local_date — the local day date in YYYY-MM-DD format;:minutes — the number of minutes in this part of the booking.split.Use this scenario:
require "time"
require_relative "booking_day_split"
splitter = BookingDaySplit.new
bookings = [
{
id: "bk-1",
starts_at: Time.iso8601("2024-03-01T20:30:00Z"),
ends_at: Time.iso8601("2024-03-01T22:30:00Z")
},
{
id: "bk-2",
starts_at: Time.iso8601("2024-03-01T21:30:00Z"),
ends_at: Time.iso8601("2024-03-02T01:00:00Z")
}
]
p splitter.split(bookings, "+03:00")
p bookings
bk-1, both hours should belong entirely to the local date 2024-03-01 or 2024-03-02 strictly according to the given offset, without shifting the boundary to adjacent days.bk-2, splitting by local midnight should produce two parts with a correct sum of minutes.split, the contents of bookings must remain unchanged, including the original :starts_at, :ends_at values and the absence of new helper fields.3.3require "time" is used for time parsingTime#getlocalUse line comments to explain the problem, its impact, the fix and how to test it.