Anchor of year sometimes marks correct answer as incorrect #1

Closed
opened 2020-01-27 13:48:47 +01:00 by FWDekker · 2 comments
Owner

The year anchor weekday input sometimes marks the correct answer as incorrect. Forcing the random number generator to reproduce dates for which this happens does not seem to reproduce the bug. This bug does not occur with the other input fields.

The year anchor weekday input sometimes marks the correct answer as incorrect. Forcing the random number generator to reproduce dates for which this happens does not seem to reproduce the bug. This bug does not occur with the other input fields.
FWDekker self-assigned this 2020-01-27 13:48:47 +01:00
FWDekker added the
bug
label 2020-01-27 13:48:47 +01:00
Author
Owner

The bug just reoccurred. Below is the entirety of the console log since the page was loaded until the date on which the bug occurred.
Running new DoomsdayDate(new Date("1140-03-31")).getYearAnchorString() in the console returns "Saturday" even though the correct answer would be "Thursday".

# Reset
New date: 7683-11-17
Century#: 76
Century:  Tuesday
Year:     Sunday
Day:      Wednesday
# Validate century
Input:    wed
Expanded: Wednesday
Expected: Tuesday
# Validate century
Input:    tue
Expanded: Tuesday
Expected: Tuesday
# Validate year
Input:    sun
Expanded: Sunday
Expected: Sunday
# Validate day
Input:    wed
Expanded: Wednesday
Expected: Wednesday


# Reset
New date: 7083-05-18
Century#: 70
Century:  Friday
Year:     Wednesday
Day:      Friday
# Validate century
Input:    fri
Expanded: Friday
Expected: Friday
# Validate year
Input:    wed
Expanded: Wednesday
Expected: Wednesday
# Validate day
Input:    fri
Expanded: Friday
Expected: Friday


# Reset
New date: 0677-01-19
Century#: 6
Century:  Friday
Year:     Wednesday
Day:      Friday
# Validate century
Input:    fri
Expanded: Friday
Expected: Friday
# Validate year
Input:    wed
Expanded: Wednesday
Expected: Wednesday
# Validate day
Input:    fri
Expanded: Friday
Expected: Friday


# Reset
New date: 1140-03-31
Century#: 11
Century:  Wednesday
Year:     Saturday
Day:      Sunday
# Validate century
Input:    wed
Expanded: Wednesday
Expected: Wednesday
# Validate year
Input:    thu
Expanded: Thursday
Expected: Saturday
# Validate day
Input:    sun
Expanded: Sunday
Expected: Sunday
The bug just reoccurred. Below is the entirety of the console log since the page was loaded until the date on which the bug occurred. Running `new DoomsdayDate(new Date("1140-03-31")).getYearAnchorString()` in the console returns `"Saturday"` even though the correct answer would be `"Thursday"`. ``` # Reset New date: 7683-11-17 Century#: 76 Century: Tuesday Year: Sunday Day: Wednesday # Validate century Input: wed Expanded: Wednesday Expected: Tuesday # Validate century Input: tue Expanded: Tuesday Expected: Tuesday # Validate year Input: sun Expanded: Sunday Expected: Sunday # Validate day Input: wed Expanded: Wednesday Expected: Wednesday # Reset New date: 7083-05-18 Century#: 70 Century: Friday Year: Wednesday Day: Friday # Validate century Input: fri Expanded: Friday Expected: Friday # Validate year Input: wed Expanded: Wednesday Expected: Wednesday # Validate day Input: fri Expanded: Friday Expected: Friday # Reset New date: 0677-01-19 Century#: 6 Century: Friday Year: Wednesday Day: Friday # Validate century Input: fri Expanded: Friday Expected: Friday # Validate year Input: wed Expanded: Wednesday Expected: Wednesday # Validate day Input: fri Expanded: Friday Expected: Friday # Reset New date: 1140-03-31 Century#: 11 Century: Wednesday Year: Saturday Day: Sunday # Validate century Input: wed Expanded: Wednesday Expected: Wednesday # Validate year Input: thu Expanded: Thursday Expected: Saturday # Validate day Input: sun Expanded: Sunday Expected: Sunday ```
Author
Owner

It appears that the original issue description was incorrect, because the bug is reproducible for dates with which this occurs. The bug occurs in the #getYearAnchorString method when the day of the week for which the doomsday should be calculated is 31. The Date#setMonth method will set the month to April, but because April doesn't have 31 days the date is set to the first of May instead. When the day is then set to the 4th, the resulting date is the 4th of May instead of the 4th of April.

Switching around the order in which the day and month are set should resolve the issue.

To help in resolving future bugs, the debug output in the console will be retained.

It appears that the original issue description was incorrect, because the bug _is_ reproducible for dates with which this occurs. The bug occurs in the `#getYearAnchorString` method when the day of the week for which the doomsday should be calculated is `31`. The `Date#setMonth` method will set the month to April, but because April doesn't have 31 days the date is set to the first of May instead. When the day is then set to the 4th, the resulting date is the 4th of May instead of the 4th of April. Switching around the order in which the day and month are set should resolve the issue. To help in resolving future bugs, the debug output in the console will be retained.
Sign in to join this conversation.
No description provided.