feat(utils): add date utilities#4
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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.
|
|
||
| export function getRelativeDate(date: Date): string { | ||
| const now = new Date(); | ||
| const diffMs = now.getTime() - date.getTime(); |
There was a problem hiding this comment.
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>
| } | ||
|
|
||
| export function isThisWeek(date: Date): boolean { | ||
| const now = new Date(); |
There was a problem hiding this comment.
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>
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.
Written for commit 4e70505. Summary will update on new commits.