Skip to content

feat(utils): add date utilities#4

Merged
maitamdev merged 1 commit into
mainfrom
feat/date-utils
Mar 4, 2026
Merged

feat(utils): add date utilities#4
maitamdev merged 1 commit into
mainfrom
feat/date-utils

Conversation

@maitamdev
Copy link
Copy Markdown
Owner

@maitamdev maitamdev commented Mar 4, 2026

Date helper functions for the platform.


Summary by cubic

Added a lightweight dateUtils module with helper functions for common UI needs: today/this-week checks, relative “time ago” strings, a time-based greeting, and days-until calculations.

  • New Features
    • isToday(date): checks if a date is today.
    • isThisWeek(date): checks if a date is in the current week.
    • getGreeting(): returns “Good morning/afternoon/evening” based on local time.
    • getDaysUntil(target): days until a target date.
    • getRelativeDate(date): human-friendly time (“Just now”, Xm/h/d ago, or date).

Written for commit 4e70505. Summary will update on new commits.

@maitamdev maitamdev merged commit 8028a97 into main Mar 4, 2026
1 of 3 checks passed
@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dhv-guiding-light Building Building Preview, Comment Mar 4, 2026 7:01pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 4, 2026

Warning

Rate limit exceeded

@maitamdev has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 29 minutes and 10 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0d3949da-e5a0-4011-8858-a8bd01706b05

📥 Commits

Reviewing files that changed from the base of the PR and between 2e7bb5a and 4e70505.

📒 Files selected for processing (1)
  • src/utils/dateUtils.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/date-utils

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/utils/dateUtils.ts">

<violation number="1" location="src/utils/dateUtils.ts:11">
P2: `getDaysUntil` uses raw timestamps with `Math.ceil`, which makes “days until” depend on time-of-day (e.g., later today returns 1). Normalize both dates to midnight before comparing to avoid off-by-one results.</violation>

<violation number="2" location="src/utils/dateUtils.ts:35">
P2: `getRelativeDate` treats future dates as “Just now” because negative diffs fall into the `< 1 minute` branch. Handle future timestamps explicitly to avoid misleading output.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread src/utils/dateUtils.ts

export function getRelativeDate(date: Date): string {
const now = new Date();
const diffMs = now.getTime() - date.getTime();
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot Mar 4, 2026

Choose a reason for hiding this comment

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

P2: getRelativeDate treats future dates as “Just now” because negative diffs fall into the < 1 minute branch. Handle future timestamps explicitly to avoid misleading output.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/utils/dateUtils.ts, line 35:

<comment>`getRelativeDate` treats future dates as “Just now” because negative diffs fall into the `< 1 minute` branch. Handle future timestamps explicitly to avoid misleading output.</comment>

<file context>
@@ -0,0 +1,44 @@
+
+export function getRelativeDate(date: Date): string {
+  const now = new Date();
+  const diffMs = now.getTime() - date.getTime();
+  const diffMins = Math.floor(diffMs / 60000);
+  const diffHours = Math.floor(diffMs / 3600000);
</file context>
Fix with Cubic

Comment thread src/utils/dateUtils.ts
}

export function isThisWeek(date: Date): boolean {
const now = new Date();
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot Mar 4, 2026

Choose a reason for hiding this comment

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

P2: getDaysUntil uses raw timestamps with Math.ceil, which makes “days until” depend on time-of-day (e.g., later today returns 1). Normalize both dates to midnight before comparing to avoid off-by-one results.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/utils/dateUtils.ts, line 11:

<comment>`getDaysUntil` uses raw timestamps with `Math.ceil`, which makes “days until” depend on time-of-day (e.g., later today returns 1). Normalize both dates to midnight before comparing to avoid off-by-one results.</comment>

<file context>
@@ -0,0 +1,44 @@
+}
+
+export function isThisWeek(date: Date): boolean {
+  const now = new Date();
+  const startOfWeek = new Date(now);
+  startOfWeek.setDate(now.getDate() - now.getDay());
</file context>
Fix with Cubic

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.

1 participant