Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tour: Incorrect calculation of days until Saturday #1667

Open
Nikilimanjaro opened this issue Nov 16, 2024 · 0 comments
Open

tour: Incorrect calculation of days until Saturday #1667

Nikilimanjaro opened this issue Nov 16, 2024 · 0 comments

Comments

@Nikilimanjaro
Copy link

Context: https://go.dev/tour/flowcontrol/10

Description: The code incorrectly calculates the number of days until Saturday by directly comparing time.Saturday with today + n. This causes errors when today + n exceeds 6 (the valid range for days of the week).

Steps to Reproduce:

  1. Run the provided code.
  2. The program may output incorrect results depending on the current day.

Expected Behavior: The program should correctly output:

  • "Today." if today is Saturday.
  • "Tomorrow." if tomorrow is Saturday.
  • "In two days." if Saturday is in two days.
  • "Too far away." if Saturday is more than two days away.

Actual Behavior: The code may produce incorrect outputs when today + n exceeds 6.

Solution: Replace the comparison logic with:

daysUntilSaturday := (time.Saturday - today + 7) % 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant