Skip to content

Commit

Permalink
Maintenance: Stabilise relative date on leap year test
Browse files Browse the repository at this point in the history
  • Loading branch information
mantas committed Mar 7, 2024
1 parent 6091855 commit 6ba710e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion spec/support/time_helper.rb
Expand Up @@ -21,7 +21,7 @@ def browser_travel_to(time)

# Reimplementation of `setMonth(month[, date])` from the ECMAScript specification.
# https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setmonth
def frontend_relative_month(obj, month, date = nil)
def frontend_relative_month(obj, month, date = nil, year: nil)
# 1. Let t be ? thisTimeValue(this value).
t = obj

Expand Down Expand Up @@ -51,6 +51,9 @@ def frontend_relative_month(obj, month, date = nil)
new_year += 1
new_month -= 12
end

new_year += year if year

Time.zone.local(new_year, new_month, dt, t.hour, t.min, t.sec)

# Ignore the rest, as `Time#local` already handles it correctly:
Expand Down
5 changes: 4 additions & 1 deletion spec/system/ticket/create_spec.rb
Expand Up @@ -1095,8 +1095,11 @@ def authenticate
# Since front-end uses a JS-specific function to add a month value to the current date,
# calculating the value here with Ruby code may lead to unexpected values.
# Therefore, we use a reimplementation of the ECMAScript function instead.
if range == 'month'
case range
when 'month'
frontend_relative_month(Time.current, value)
when 'year'
frontend_relative_month(Time.current, 0, year: value)
else
value.send(range).from_now
end
Expand Down

0 comments on commit 6ba710e

Please sign in to comment.