Skip to content

Conversation

@ryoppippi
Copy link
Owner

@ryoppippi ryoppippi commented Jul 24, 2025

Reverts #312

Summary by CodeRabbit

  • Bug Fixes

    • Improved date formatting to consistently use local time for all date strings, ensuring uniform display regardless of timezone indicators in the input.
  • Tests

    • Updated tests to verify consistent local date formatting and correct zero-padding for single-digit months and days.

@coderabbitai
Copy link

coderabbitai bot commented Jul 24, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This change removes the internal helper function formatDateInternal from the date formatting module and updates the public functions formatDate and formatDateCompact to always use local date getters, regardless of timezone indicators in the input string. Corresponding tests are simplified to reflect this new behavior.

Changes

File(s) Change Summary
src/data-loader.ts Removed formatDateInternal. Updated formatDate and formatDateCompact to use local date getters.
(Test files) Simplified tests: removed UTC-specific cases, now test for consistent local date output and formatting.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant DataLoader

    Caller->>DataLoader: formatDate(dateStr)
    DataLoader->>DataLoader: Create Date(dateStr)
    DataLoader->>DataLoader: Use local getters (getFullYear, getMonth, getDate)
    DataLoader-->>Caller: Return formatted local date string

    Caller->>DataLoader: formatDateCompact(dateStr)
    DataLoader->>DataLoader: Create Date(dateStr)
    DataLoader->>DataLoader: Use local getters (getFullYear, getMonth, getDate)
    DataLoader-->>Caller: Return compact local date string
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • Using UTC year/month/day in data-loader #312: The main PR reverses the approach introduced in the retrieved PR by removing the internal helper function that conditionally used UTC or local date getters and instead always uses local date getters directly in the public functions, making their changes directly related but opposite in implementation.

Poem

A date once danced with UTC,
But now it lives where you and I be.
Local time reigns, with padding just right,
No more timezone checks in the night.
Simpler tests, less code to see—
A bunny hops with date glee! 🐇🗓️

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4c9c629 and 3123d5e.

📒 Files selected for processing (1)
  • src/data-loader.ts (4 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch revert-312-311-date-off-by-one

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this 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.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jul 24, 2025

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
ccusage-guide 3123d5e Commit Preview URL

Branch Preview URL
Jul 24 2025, 04:34 PM

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jul 24, 2025

Open in StackBlitz

npm i https://pkg.pr.new/ryoppippi/ccusage@352

commit: 3123d5e

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @ryoppippi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request fully reverts a previous change (#312) that introduced UTC-based date formatting in the data-loader. The primary purpose is to restore the date formatting functions (formatDate and formatDateCompact) to use local year, month, and day components, ensuring consistency with how dates were handled prior to the original change. This likely addresses an issue or an unintended side effect caused by the UTC-aware formatting.

Highlights

  • Reverted Date Formatting Logic: The formatDate and formatDateCompact functions in src/data-loader.ts have been reverted to use local date components (e.g., getFullYear(), getMonth(), getDate()) instead of attempting to interpret and use UTC components based on the input string's timezone information. This restores the previous behavior of always formatting dates based on the local timezone.
  • Removed Helper Function: The formatDateInternal helper function, which encapsulated the logic for timezone-aware date formatting, has been removed as it is no longer needed after reverting the UTC handling.
  • Updated Unit Tests: Corresponding unit tests for formatDate and formatDateCompact have been updated to reflect the change. Tests asserting explicit UTC date interpretation have been removed, and remaining tests are simplified to confirm local date formatting for various inputs, including those with UTC indicators.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@ryoppippi ryoppippi merged commit c0bf528 into main Jul 24, 2025
9 of 11 checks passed
@ryoppippi ryoppippi deleted the revert-312-311-date-off-by-one branch July 24, 2025 16:33
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request reverts a previous change, altering date formatting to rely on the local timezone. While I see this is an intentional revert, it re-introduces critical issues. The date formatting functions are now dependent on the execution environment's timezone, which can lead to incorrect data in reports. Consequently, the unit tests have become brittle and will fail in different timezones, compromising the reliability of your test suite. I've added specific comments detailing these concerns.

Comment on lines 467 to +472
export function formatDate(dateStr: string): string {
return formatDateInternal(dateStr, false);
const date = new Date(dateStr);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

Using getFullYear(), getMonth(), and getDate() unconditionally introduces a correctness issue. These methods are based on the system's local timezone. When parsing a UTC timestamp string (e.g., one ending in 'Z'), this can result in an incorrect date.

For example, in a timezone like America/Los_Angeles (UTC-8), new Date('2024-01-01T00:00:00Z') will be interpreted as 2023-12-31 16:00:00, and this function will incorrectly return '2023-12-31'.

The previous implementation correctly handled this by checking for timezone information in the date string and using UTC-based getters (getUTCFullYear, etc.) when present. This ensured consistent and correct behavior regardless of the environment's timezone.

This change could lead to data being grouped under the wrong date, affecting reports. I recommend reconsidering this revert.

Comment on lines +1248 to 1252
it('formats UTC timestamp to local date', () => {
// Test with UTC timestamps - results depend on local timezone
expect(formatDate('2024-01-01T00:00:00Z')).toBe('2024-01-01');
expect(formatDate('2024-12-31T23:59:59Z')).toBe('2024-12-31');
expect(formatDate('2024-01-01T12:00:00.000Z')).toBe('2024-01-01');
});
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

These tests have become brittle and non-deterministic. They will pass or fail depending on the timezone of the environment where they are run.

For example, expect(formatDate('2024-01-01T00:00:00Z')).toBe('2024-01-01'); will fail in any timezone west of UTC, because new Date('2024-01-01T00:00:00Z').getFullYear() will return 2023.

Unit tests should be independent of the execution environment to ensure they are reliable and produce consistent results for all developers and in CI/CD pipelines. The previous tests were more robust in this regard.

Comment on lines +1268 to 1270
it('formats UTC timestamp to local date with line break', () => {
expect(formatDateCompact('2024-01-01T00:00:00Z')).toBe('2024\n01-01');
expect(formatDateCompact('2024-12-31T23:59:59Z')).toBe('2024\n12-31');
expect(formatDateCompact('2024-01-01T12:00:00.000Z')).toBe('2024\n01-01');
});
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

Similar to the formatDate tests, these tests for formatDateCompact are now dependent on the local timezone of the machine running them, making them unreliable.

For instance, expect(formatDateCompact('2024-01-01T00:00:00Z')).toBe('2024\n01-01'); will fail in timezones where this UTC timestamp corresponds to the previous day locally.

Tests must be deterministic. Please consider making these tests timezone-agnostic to ensure they are reliable across different environments.

Comment on lines 480 to 486
export function formatDateCompact(dateStr: string): string {
return formatDateInternal(dateStr, true);
const date = new Date(dateStr);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
return `${year}\n${month}-${day}`;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This function has the same timezone-related correctness issue as formatDate.

Additionally, by removing the shared formatDateInternal function, the implementation is now almost identical to formatDate, leading to code duplication. The only difference is the separator used in the return string ('\n' vs '-').

This duplication makes the code harder to maintain. If the date formatting logic needs to be changed in the future, it will have to be updated in two places, increasing the risk of inconsistencies.

It would be better to extract the common logic into a shared helper function to improve maintainability.

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