diff --git a/spec/support/time_helper.rb b/spec/support/time_helper.rb index d44e44934b17..7a56be8cf6e4 100644 --- a/spec/support/time_helper.rb +++ b/spec/support/time_helper.rb @@ -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 @@ -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: diff --git a/spec/system/ticket/create_spec.rb b/spec/system/ticket/create_spec.rb index dd4526f18d09..2a3980fb8b1a 100644 --- a/spec/system/ticket/create_spec.rb +++ b/spec/system/ticket/create_spec.rb @@ -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