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

Fix timetable current time range identification #205

Conversation

desmondlsl
Copy link
Contributor

@desmondlsl desmondlsl commented Oct 5, 2024

Before:
At 2024-10-05T07:11+08:00, timetable was not highlighting. https://t.me/hkbusapp/33406
image

At Sat non-public holiday 07:19 (local time zone):
image

const date = new Date();
const ts = `${date.getHours()}${date.getMinutes()}`;
if (details) {
return start <= ts && ts <= details[0];
}

const date = new Date("2024-01-01T07:00:00+08:00");
`${date.getHours()}${date.getMinutes()}`;
// -> 70

The above example string 70 is compared against start and details[0], where they are strings in the format of the 4-digit 24-hour time, e.g. 0600, 1710

After:

At Sat non-public holiday 07:19 (local time zone):
image

const date = new Date("2024-01-01T07:00:00+08:00");
`${date.getHours().toString().padStart(2, "0")}${date.getMinutes().toString().padStart(2, "0")}`;
// -> 0700

Besides, code changes in isHoliday is just for consistency and readability

Summary by CodeRabbit

  • Bug Fixes
    • Improved time formatting for current timeslot comparisons, ensuring consistency and accuracy.
    • Enhanced date formatting for holiday checks, providing clearer and more consistent date strings.

Copy link

coderabbitai bot commented Oct 5, 2024

Walkthrough

The changes in this pull request focus on enhancing the formatting of time and date strings within the TimeTable.tsx and timetable.ts files. Specifically, the isCurrentTimeslot function was updated to ensure that the current time is consistently formatted with zero-padding for hours and minutes. Similarly, the isHoliday function was modified to ensure that month and date values are also zero-padded, improving the clarity and consistency of date representations used in holiday checks.

Changes

File Path Change Summary
src/components/route-eta/timetableDrawer/TimeTable.tsx Modified isCurrentTimeslot function to use zero-padding for current time formatting.
src/timetable.ts Updated isHoliday function to use zero-padding for month and date formatting.

Possibly related PRs

Poem

In the drawer where time does play,
Hours and minutes find their way.
With zeroes snug, they dance and gleam,
A holiday's joy, a punctual dream!
So hop along, with time so bright,
Each moment counted, all feels right! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
src/timetable.ts (1)

Line range hint 1-30: Summary and next steps

While the changes made to the isHoliday function in this file improve code quality, they don't address the main issue described in the PR objectives. The PR description mentions fixing a problem with time formatting related to highlighting the current time in the timetable, but these changes are not present in this file.

To move forward with this PR:

  1. Please verify if the correct files have been included in this PR. The changes mentioned in the PR description (related to formatting time as a 4-digit string) are not present in this file.
  2. If additional files should be part of this PR, please add them and update the PR accordingly.
  3. If the PR description is outdated or incorrect, please update it to accurately reflect the changes made in this file.

Once these steps are completed, we can proceed with a more targeted review of the changes addressing the timetable highlighting issue.

src/components/route-eta/timetableDrawer/TimeTable.tsx (1)

Boundary Condition Issue at 07:00

The current implementation excludes 07:00 from the valid timeslot due to the strict greater than comparison. To ensure 07:00 is included, please update the condition to use >= "0700".

🔗 Analysis chain

Line range hint 179-189: Verify fix effectiveness across different scenarios

While the time formatting issue has been addressed, it's important to ensure that this fix resolves all cases of the reported timetable highlighting problem. Please consider the following:

  1. Test with various times throughout the day, especially around midnight and noon.
  2. Verify behavior during daylight saving time transitions, if applicable.
  3. Check if the fix works correctly across different time zones.

To assist with verification, you can run the following script to test various scenarios:

This script simulates the behavior of isCurrentTimeslot for various times. Please review the output to ensure it matches the expected behavior.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Test isCurrentTimeslot function with various time inputs

# Function to simulate isCurrentTimeslot behavior
test_is_current_timeslot() {
    local hour=$1
    local minute=$2
    local formatted_time=$(printf "%02d%02d" $hour $minute)
    echo "Testing time: $formatted_time"
    if [[ "$formatted_time" > "0700" && "$formatted_time" < "2300" ]]; then
        echo "Current timeslot: true"
    else
        echo "Current timeslot: false"
    fi
    echo "---"
}

# Test cases
test_is_current_timeslot 0 0   # Midnight
test_is_current_timeslot 6 59  # Just before 7 AM
test_is_current_timeslot 7 0   # 7 AM
test_is_current_timeslot 12 0  # Noon
test_is_current_timeslot 22 59 # Just before 11 PM
test_is_current_timeslot 23 0  # 11 PM
test_is_current_timeslot 23 1  # Just after 11 PM

Length of output: 1864

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f781f7b and 7e89184.

📒 Files selected for processing (2)
  • src/components/route-eta/timetableDrawer/TimeTable.tsx (1 hunks)
  • src/timetable.ts (1 hunks)
🔇 Additional comments (1)
src/components/route-eta/timetableDrawer/TimeTable.tsx (1)

184-184: Excellent fix for time formatting!

This change correctly addresses the issue mentioned in the PR objectives. By using padStart(2, "0") for both hours and minutes, we ensure that the time is always formatted as a 4-digit string in 24-hour format. This resolves the problem where single-digit hours or minutes could lead to incorrect comparisons.

Benefits of this change:

  1. Consistent 4-digit time formatting (e.g., "0930" for 9:30 AM).
  2. Correct handling of single-digit hours and minutes.
  3. Improved accuracy in time range comparisons.

@chunlaw chunlaw merged commit 463bf11 into hkbus:master Oct 5, 2024
2 checks passed
@desmondlsl desmondlsl deleted the fix-timetable-current-time-range-identification branch October 5, 2024 06:00
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

Successfully merging this pull request may close these issues.

2 participants