I am writing an automation test using two methods for daylight savings time purposes. These methods are defined as follows:
- Adjust the inputted DATETIME (via
Time.Parse
) to round to the nearest DST change - Check to see that the method's DATETIME changed either one hour back or forward, whether the
Time.Parse
.include?("March")
OR.include("November")
To reiterate, this method's purpose is to take the date from the previous method I wrote (that adjusts the current date and rounds it up to the next DST date), determine whether the return value is March or November, and VERIFIES that the time went forward or backward. The first method has been completed and is as follows:
def dst_datechange(date)
date = Time.now
case date
when (date > Time.Parse('March 11, 2018 2:00am')) && (date <
Time.parse('November 4, 2018 2:00am'))
date = Time.parse('November 4, 2018 2:00am')
when (date > Time.Parse('November 4 2018, 2:00am')) && (date <
Time.parse('March 10, 2:00am'))
date = Time.parse('March 10, 2019 2:00am')
when (date > Time.Parse('March 10, 2019 2:00am')) && (date <
Time.parse('November 3, 2019 2:00am'))
date = Time.parse('November 3, 2019 2:00am')
when (date > Time.Parse('November 3, 2019 2:00am')) && (date <
Time.parse('March 8, 2020 2:00am'))
date = Time.parse('March 8, 2020 2:00am')
when (date > Time.Parse('March 8, 2020 2:00am')) && (date <
Time.parse('November 1, 2020 2:00am'))
date = Time.parse ('November 1, 2020 2:00am')
else
raise "The date #{date} does not match any dst date parameter"
end
date
end
Now, my question is, how do I take the returned DATETIME value from that case statement, put it in an if statement to determine whether it includes a NOVEMBER or MARCH month, and then if it is march, then check to see if the time goes forward one hour or if its November, then check to see if the time goes back one hour.