Skip to content

Comments

issue#1034: Enhance date formatting in Home component to support date ranges#1047

Merged
arkid15r merged 12 commits intoOWASP:mainfrom
idityaGE:issue/1034
Mar 9, 2025
Merged

issue#1034: Enhance date formatting in Home component to support date ranges#1047
arkid15r merged 12 commits intoOWASP:mainfrom
idityaGE:issue/1034

Conversation

@idityaGE
Copy link
Contributor

@idityaGE idityaGE commented Mar 7, 2025

Related Issue

Closes #1034

Summary

This PR improves event date formatting by introducing a new function, formatDateRange, which:

  • Condenses date ranges within the same month/year (e.g., Sep 1, 2025 - Sep 4, 2025Sep 1 - 4, 2025).
  • Ensures date formatting is concise by handling same-month, cross-month, and cross-year cases correctly.
  • Updates the Home.tsx component and its corresponding tests in Home.test.ts.

Screenshots

Before After
image image

🛠️ Changes Made

Code Enhancements

  • Added formatDateRange function:
    • Handles different date cases (same month, different months, different years).
  • Updated Home.tsx:
    • Now dynamically selects formatDate or formatDateRange based on event duration.
  • Updated Home.test.ts:
    • Ensures correct event date formatting in tests.

Test Result

image

@idityaGE idityaGE requested review from arkid15r and kasya as code owners March 7, 2025 17:03
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 7, 2025

Summary by CodeRabbit

  • New Features

    • The Upcoming Events section now presents event dates as a clean, consolidated range (e.g., "Feb 27 — 28, 2025") for improved clarity.
  • Refactor

    • Enhanced the overall date formatting approach to ensure consistent and user-friendly display of event schedules.

Walkthrough

This pull request updates the date formatting logic for upcoming events in the Home component and its associated tests. A new utility function, formatDateRange, has been introduced to handle the formatting of date ranges when events span multiple days. The Home component now utilizes this function for events with distinct start and end dates, while retaining the original formatDate function for single-day events. Corresponding tests have been modified to reflect these changes, ensuring accurate validation of date visibility and formatting.

Changes

File(s) Change Summary
frontend/__tests__/.../Home.test.tsx
frontend/__tests__/.../Home.spec.ts
Updated tests to check for static date strings and consolidated assertions for event date visibility in the Home component's tests.
frontend/src/.../Home.tsx Modified date formatting logic to use formatDateRange for different start and end dates; retains formatDate for single dates.
frontend/src/utils/dateFormatter.ts Added the formatDateRange function to convert inputs to Date objects, validate them, and format date ranges based on various conditions.
frontend/__tests__/.../dateFormatter.test.ts Introduced a new test suite for formatDate and formatDateRange, covering various scenarios, formatting rules, and error handling for invalid dates.

Suggested reviewers

  • kasya
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 generate docstrings to generate docstrings 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.

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
Contributor

@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

🧹 Nitpick comments (2)
frontend/src/utils/dateFormatter.ts (2)

18-40: Consider handling additional edge cases in formatDateRange.

The implementation of formatDateRange handles the basic scenarios well but doesn't address some edge cases:

  1. What if endDate is before startDate?
  2. What if the dates are the same? (Currently would format as "Month Day - Day, Year" which is redundant)

Consider adding these additional checks:

export const formatDateRange = (startDate: number | string, endDate: number | string) => {
  const start = typeof startDate === 'number' ? new Date(startDate * 1000) : new Date(startDate)
  const end = typeof endDate === 'number' ? new Date(endDate * 1000) : new Date(endDate)

  if (isNaN(start.getTime()) || isNaN(end.getTime())) {
    throw new Error('Invalid date')
  }

+  // If dates are identical or end is before start, just format as a single date
+  if (start.getTime() === end.getTime() || end < start) {
+    return formatDate(startDate)
+  }

  // Check if dates are in the same month and year
  const sameMonth = start.getMonth() === end.getMonth() && start.getFullYear() === end.getFullYear()
  const sameYear = start.getFullYear() === end.getFullYear()

  if (sameMonth) {
    // Format as "Month Day - Day, Year" (e.g., "Sep 1 - 4, 2025")
    return `${start.toLocaleDateString('en-US', { month: 'short' })} ${start.getDate()} - ${end.getDate()}, ${start.getFullYear()}`
  } else if (sameYear) {
    // Different months but same year (e.g., "Sep 29 - Oct 2, 2025")
    return `${start.toLocaleDateString('en-US', { month: 'short' })} ${start.getDate()} - ${end.toLocaleDateString('en-US', { month: 'short' })} ${end.getDate()}, ${start.getFullYear()}`
  } else {
    // Different years (e.g., "Dec 30, 2025 - Jan 3, 2026")
    return `${start.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' })} - ${end.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' })}`
  }
}

30-39: Consider extracting formatting options to reduce duplication.

The formatting options are repeated in multiple places. Consider extracting them into variables to make the code more maintainable.

export const formatDateRange = (startDate: number | string, endDate: number | string) => {
  const start = typeof startDate === 'number' ? new Date(startDate * 1000) : new Date(startDate)
  const end = typeof endDate === 'number' ? new Date(endDate * 1000) : new Date(endDate)

  if (isNaN(start.getTime()) || isNaN(end.getTime())) {
    throw new Error('Invalid date')
  }

  // Check if dates are in the same month and year
  const sameMonth = start.getMonth() === end.getMonth() && start.getFullYear() === end.getFullYear()
  const sameYear = start.getFullYear() === end.getFullYear()

+  const shortMonthFormat = { month: 'short' };
+  const fullDateFormat = { month: 'short', day: 'numeric', year: 'numeric' };

  if (sameMonth) {
    // Format as "Month Day - Day, Year" (e.g., "Sep 1 - 4, 2025")
-    return `${start.toLocaleDateString('en-US', { month: 'short' })} ${start.getDate()} - ${end.getDate()}, ${start.getFullYear()}`
+    return `${start.toLocaleDateString('en-US', shortMonthFormat)} ${start.getDate()} - ${end.getDate()}, ${start.getFullYear()}`
  } else if (sameYear) {
    // Different months but same year (e.g., "Sep 29 - Oct 2, 2025")
-    return `${start.toLocaleDateString('en-US', { month: 'short' })} ${start.getDate()} - ${end.toLocaleDateString('en-US', { month: 'short' })} ${end.getDate()}, ${start.getFullYear()}`
+    return `${start.toLocaleDateString('en-US', shortMonthFormat)} ${start.getDate()} - ${end.toLocaleDateString('en-US', shortMonthFormat)} ${end.getDate()}, ${start.getFullYear()}`
  } else {
    // Different years (e.g., "Dec 30, 2025 - Jan 3, 2026")
-    return `${start.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' })} - ${end.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' })}`
+    return `${start.toLocaleDateString('en-US', fullDateFormat)} - ${end.toLocaleDateString('en-US', fullDateFormat)}`
  }
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 501c899 and 5642359.

📒 Files selected for processing (3)
  • frontend/__tests__/unit/pages/Home.test.tsx (2 hunks)
  • frontend/src/pages/Home.tsx (2 hunks)
  • frontend/src/utils/dateFormatter.ts (1 hunks)
🔇 Additional comments (5)
frontend/src/pages/Home.tsx (2)

21-21: Import of formatDateRange is correctly added.

The import statement has been updated to include the new formatDateRange function alongside the existing formatDate function.


150-152: Improved date range formatting logic.

The conditional logic has been enhanced to use the new formatDateRange function when an event spans multiple days, providing a more concise and user-friendly display for date ranges.

frontend/__tests__/unit/pages/Home.test.tsx (2)

7-7: Import of formatDateRange is correctly added to test file.

The import statement has been updated to include the new formatDateRange function alongside the existing formatDate function.


164-167: Test logic properly updated to match implementation.

The test now correctly verifies the date formatting behavior based on whether the event has different start and end dates, ensuring the component's new date formatting functionality is properly tested.

frontend/src/utils/dateFormatter.ts (1)

22-24: Error handling is consistent with formatDate.

The validation for invalid dates follows the same pattern as in the formatDate function, which is good for consistency.

@idityaGE idityaGE mentioned this pull request Mar 7, 2025
2 tasks
Copy link
Collaborator

@kasya kasya left a comment

Choose a reason for hiding this comment

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

@idityaGE please update your PR after running make check-all locally

Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

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

Thanks for addressing this, however I'm concerned about you working on issues assigned to other people. This is the last one that is going to be accepted as not assigned to you.

Please look into these when you get a chance:

Copy link
Contributor

@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

🧹 Nitpick comments (1)
frontend/src/utils/dateFormatter.ts (1)

39-52: Suggestion: Refactor to reduce code duplication.

The date formatting logic could be extracted into helper functions to reduce duplication and improve maintainability.

+ // Helper function to format date parts
+ const formatDateParts = (date: Date, options: Intl.DateTimeFormatOptions) => {
+   return date.toLocaleDateString('en-US', options);
+ }

  // Check if dates are in the same month and year
  const sameMonth = start.getMonth() === end.getMonth() && start.getFullYear() === end.getFullYear()
  const sameYear = start.getFullYear() === end.getFullYear()

  if (sameMonth) {
    // Format as "Month Day - Day, Year" (e.g., "Sep 1 - 4, 2025")
-   return `${start.toLocaleDateString('en-US', { month: 'short' })} ${start.getDate()} - ${end.getDate()}, ${start.getFullYear()}`
+   return `${formatDateParts(start, { month: 'short' })} ${start.getDate()} - ${end.getDate()}, ${start.getFullYear()}`
  } else if (sameYear) {
    // Different months but same year (e.g., "Sep 29 - Oct 2, 2025")
-   return `${start.toLocaleDateString('en-US', { month: 'short' })} ${start.getDate()} - ${end.toLocaleDateString('en-US', { month: 'short' })} ${end.getDate()}, ${start.getFullYear()}`
+   return `${formatDateParts(start, { month: 'short' })} ${start.getDate()} - ${formatDateParts(end, { month: 'short' })} ${end.getDate()}, ${start.getFullYear()}`
  } else {
    // Different years (e.g., "Dec 30, 2025 - Jan 3, 2026")
-   return `${start.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' })} - ${end.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' })}`
+   return `${formatDateParts(start, { month: 'short', day: 'numeric', year: 'numeric' })} - ${formatDateParts(end, { month: 'short', day: 'numeric', year: 'numeric' })}`
  }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5642359 and 7067205.

📒 Files selected for processing (4)
  • frontend/__tests__/e2e/pages/Home.spec.ts (1 hunks)
  • frontend/__tests__/unit/pages/Home.test.tsx (1 hunks)
  • frontend/__tests__/unit/utils/dateFormatter.test.ts (1 hunks)
  • frontend/src/utils/dateFormatter.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/tests/unit/pages/Home.test.tsx
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: CodeQL (python)
  • GitHub Check: Run backend tests
  • GitHub Check: Run frontend unit tests
  • GitHub Check: CodeQL (javascript-typescript)
  • GitHub Check: Run frontend e2e tests
🔇 Additional comments (3)
frontend/__tests__/e2e/pages/Home.spec.ts (1)

74-74: Updated test expectation matches the new date range formatting.

The test has been appropriately updated to check for the consolidated date range format "Feb 27 - 28, 2025" instead of separate date strings, which aligns with the new date formatting approach implemented in the Home component.

frontend/__tests__/unit/utils/dateFormatter.test.ts (1)

1-85: Comprehensive test coverage for date formatting functions.

The test suite provides thorough coverage for both formatDate and formatDateRange functions, testing various scenarios including:

  • Different date formats (ISO strings, Unix timestamps)
  • Error handling for invalid dates
  • Date ranges in the same month, different months, and different years
  • Edge cases like month/year boundaries and single-day ranges

This addresses the previous reviewer's request for unit tests and ensures the new functionality is properly validated.

frontend/src/utils/dateFormatter.ts (1)

18-53: Well-implemented date range formatting function.

The formatDateRange function effectively handles different date range scenarios with appropriate conditional logic:

  1. Same day → returns a single date format
  2. Same month → "Month Day - Day, Year" format
  3. Same year, different months → "Month Day - Month Day, Year" format
  4. Different years → "Month Day, Year - Month Day, Year" format

The function also properly handles both ISO date strings and Unix timestamps with appropriate error checking.

@idityaGE
Copy link
Contributor Author

idityaGE commented Mar 8, 2025

@idityaGE please update your PR after running make check-all locally

image

@idityaGE
Copy link
Contributor Author

idityaGE commented Mar 8, 2025

Thanks for addressing this, however I'm concerned about you working on issues assigned to other people. This is the last one that is going to be accepted as not assigned to you.

Please look into these when you get a chance:

I apologize for this mistake. I didn’t know about the assignment rule when I made the pull request but realized it after asking in last night’s huddle. I’ll be more careful next time. Thanks for letting me know!

@idityaGE idityaGE requested review from arkid15r and kasya March 8, 2025 06:33
Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

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

Looks good, please check these:

Copy link
Contributor

@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: 1

🧹 Nitpick comments (3)
frontend/src/utils/dateFormatter.ts (3)

22-27: Consider refactoring duplicated date parsing logic.

This date parsing logic duplicates code from the formatDate function. Consider extracting this into a private helper function to follow the DRY principle.

+const parseDate = (input: number | string): Date => {
+  return typeof input === 'number'
+    ? new Date(input * 1000) // Unix timestamp in seconds
+    : new Date(input) // ISO date string
+}

 export const formatDate = (input: number | string) => {
-  const date =
-    typeof input === 'number'
-      ? new Date(input * 1000) // Unix timestamp in seconds
-      : new Date(input) // ISO date string
+  const date = parseDate(input)

   // Rest of the function...
 }

 export const formatDateRange = (
   startDate: number | string,
   endDate: number | string
 ) => {
-  const start = typeof startDate === 'number'
-    ? new Date(startDate * 1000)
-    : new Date(startDate)
-  const end = typeof endDate === 'number'
-    ? new Date(endDate * 1000)
-    : new Date(endDate)
+  const start = parseDate(startDate)
+  const end = parseDate(endDate)

   // Rest of the function...
 }

29-31: Error message could be more specific.

The current error message doesn't indicate which date is invalid (start date, end date, or both).

 if (isNaN(start.getTime()) || isNaN(end.getTime())) {
-  throw new Error('Invalid date')
+  if (isNaN(start.getTime()) && isNaN(end.getTime())) {
+    throw new Error('Both start and end dates are invalid')
+  } else if (isNaN(start.getTime())) {
+    throw new Error('Invalid start date')
+  } else {
+    throw new Error('Invalid end date')
+  }
 }

47-53: Combine string concatenation into a single template literal.

Using multiple string concatenations can be less readable. Consider using a single template literal for improved readability.

 if (sameMonth) {
   // Format as "Month Day - Day, Year" (e.g., "Sep 1 - 4, 2025")
   return (
-    `${start.toLocaleDateString('en-US', { month: 'short' })} ` +
-    `${start.getDate()} - ${end.getDate()}, ${start.getFullYear()}`
+    `${start.toLocaleDateString('en-US', { month: 'short' })} ${start.getDate()} - ${end.getDate()}, ${start.getFullYear()}`
   )
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7067205 and 26ed17e.

📒 Files selected for processing (1)
  • frontend/src/utils/dateFormatter.ts (1 hunks)
🔇 Additional comments (5)
frontend/src/utils/dateFormatter.ts (5)

18-21: Function signature is well-defined and consistent with formatDate.

The new formatDateRange function maintains the same parameter type flexibility as the existing formatDate function, accepting both Unix timestamps (number) and date strings.


33-40: Good implementation for handling same-day events.

The approach of reusing formatDate for same-day events is efficient and correctly implements the specified behavior. This effectively addresses the previous review comment "It seems you can reuse formatDate here".


61-61: LGTM! Clean implementation of same-year formatting.

The code correctly formats dates from different months in the same year, using readable variable names and a concise template literal.


64-64: Excellent reuse of the existing formatDate function.

For different years, reusing the existing formatDate function is the right approach - it maintains consistency and follows the DRY principle.


18-66: Verify that unit tests cover all edge cases.

As mentioned in a previous review comment, please ensure that your unit tests in frontend/__tests__/unit/utils/dateFormatter.test.ts cover all edge cases including:

  • Invalid dates
  • Same day events
  • Same month events
  • Same year but different month events
  • Different year events
  • Leap year dates
  • Edge of month/year transitions

Copy link
Contributor

@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

♻️ Duplicate comments (1)
frontend/src/utils/dateFormatter.ts (1)

41-43: 🛠️ Refactor suggestion

Support internationalization by adding a locale parameter

The function hardcodes 'en-US' locale for date formatting. For better internationalization support, consider accepting a locale parameter that defaults to 'en-US' but can be overridden.

-export const formatDateRange = (startDate: number | string, endDate: number | string) => {
+export const formatDateRange = (
+  startDate: number | string, 
+  endDate: number | string, 
+  locale: string = 'en-US'
+) => {
   // ...existing code...
   
   if (sameMonth) {
     // Format as "Month Day - Day, Year" (e.g., "Sep 1 - 4, 2025")
     return (
-      `${start.toLocaleDateString('en-US', { month: 'short' })} ` +
+      `${start.toLocaleDateString(locale, { month: 'short' })} ` +
       `${start.getDate()} - ${end.getDate()}, ${start.getFullYear()}`
     )
   } else if (sameYear) {
     // Different months but same year (e.g., "Sep 29 - Oct 2, 2025")
-    const startMonth = start.toLocaleDateString('en-US', { month: 'short' })
-    const endMonth = end.toLocaleDateString('en-US', { month: 'short' })
+    const startMonth = start.toLocaleDateString(locale, { month: 'short' })
+    const endMonth = end.toLocaleDateString(locale, { month: 'short' })
     // ...
   } else {
     // Different years (e.g., "Dec 30, 2025 - Jan 3, 2026")
-    return `${formatDate(startDate)} - ${formatDate(endDate)}`
+    return `${formatDate(startDate, locale)} - ${formatDate(endDate, locale)}`
   }

Also update the formatDate function to accept a locale parameter:

-export const formatDate = (input: number | string) => {
+export const formatDate = (input: number | string, locale: string = 'en-US') => {
   // ...existing code...
   
-  return date.toLocaleDateString('en-US', {
+  return date.toLocaleDateString(locale, {
     year: 'numeric',
     month: 'short',
     day: 'numeric',
   })
🧹 Nitpick comments (2)
frontend/src/utils/dateFormatter.ts (2)

18-20: Consider extracting the date parsing logic to a helper function

There's duplicated date parsing logic between formatDate and formatDateRange. Extracting this logic into a helper function would make the code more maintainable and reduce duplication.

+// Helper function to parse different date input formats 
+const parseDate = (input: number | string): Date => {
+  return typeof input === 'number' 
+    ? new Date(input * 1000) // Unix timestamp in seconds
+    : new Date(input) // ISO date string
+}

 export const formatDate = (input: number | string) => {
-  const date =
-    typeof input === 'number'
-      ? new Date(input * 1000) // Unix timestamp in seconds
-      : new Date(input) // ISO date string
+  const date = parseDate(input)

   if (isNaN(date.getTime())) {
     throw new Error('Invalid date')
   }
   // ... rest of function unchanged

 export const formatDateRange = (startDate: number | string, endDate: number | string) => {
-  const start = typeof startDate === 'number' ? new Date(startDate * 1000) : new Date(startDate)
-  const end = typeof endDate === 'number' ? new Date(endDate * 1000) : new Date(endDate)
+  const start = parseDate(startDate)
+  const end = parseDate(endDate)

22-24: Add validation for invalid date range order

The function validates that both dates are valid but doesn't check if the end date is after the start date. Consider adding validation to handle cases where the end date precedes the start date.

 if (isNaN(start.getTime()) || isNaN(end.getTime())) {
   throw new Error('Invalid date')
 }
+
+// Ensure end date is not before start date
+if (end.getTime() < start.getTime()) {
+  throw new Error('End date cannot be before start date')
+}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 26ed17e and a4bd934.

📒 Files selected for processing (1)
  • frontend/src/utils/dateFormatter.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: CodeQL (python)
  • GitHub Check: CodeQL (javascript-typescript)
  • GitHub Check: Run frontend e2e tests
  • GitHub Check: Run frontend unit tests
🔇 Additional comments (3)
frontend/src/utils/dateFormatter.ts (3)

35-37: Good use of variables for clarity

The code defines clear variable names (sameMonth and sameYear) which improves readability and makes the conditional logic easier to understand.


32-33: Good code reuse with formatDate

Excellent decision to reuse the existing formatDate function when the dates are the same. This follows the DRY principle and ensures consistent formatting.


55-56: Good reuse of formatDate for different years case

Well implemented handling of different years by leveraging the existing formatDate function. This ensures consistency in the formatting of individual dates within the range.

@idityaGE idityaGE requested a review from arkid15r March 8, 2025 19:43
kasya
kasya previously approved these changes Mar 9, 2025
Copy link
Collaborator

@kasya kasya left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

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

Nicely done, LGTM 👍

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 9, 2025

Copy link
Contributor

@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

🧹 Nitpick comments (1)
frontend/src/utils/dateFormatter.ts (1)

41-42: Consider consistent formatting for date ranges.

You're using em dashes (—) as separators between dates. While typographically correct, ensure this is consistent with the rest of the application's date range formatting. If other parts of the UI use hyphens (-) instead, you might want to standardize.

Also applies to: 52-52, 55-55

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a4bd934 and 518af5f.

📒 Files selected for processing (5)
  • frontend/__tests__/e2e/pages/Home.spec.ts (1 hunks)
  • frontend/__tests__/unit/pages/Home.test.tsx (1 hunks)
  • frontend/__tests__/unit/utils/dateFormatter.test.ts (1 hunks)
  • frontend/src/pages/Home.tsx (2 hunks)
  • frontend/src/utils/dateFormatter.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • frontend/tests/unit/pages/Home.test.tsx
  • frontend/tests/e2e/pages/Home.spec.ts
  • frontend/src/pages/Home.tsx
  • frontend/tests/unit/utils/dateFormatter.test.ts
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: CodeQL (python)
  • GitHub Check: Run frontend unit tests
  • GitHub Check: CodeQL (javascript-typescript)
  • GitHub Check: Run backend tests
  • GitHub Check: Run frontend e2e tests
🔇 Additional comments (2)
frontend/src/utils/dateFormatter.ts (2)

18-57: Well-structured implementation with good edge case handling.

The formatDateRange function effectively handles various date range scenarios, reusing the existing formatDate function where appropriate. The code is clean, easy to follow, and includes helpful comments.


41-42: Enhance internationalization support for date formatting.

The function currently hardcodes the 'en-US' locale. For better internationalization support, consider accepting a locale parameter that defaults to 'en-US' but can be overridden.

What are best practices for internationalization in JavaScript date formatting?

Also applies to: 46-48, 55-55

@arkid15r arkid15r added this pull request to the merge queue Mar 9, 2025
Merged via the queue into OWASP:main with commit 1294ba4 Mar 9, 2025
18 checks passed
shdwcodr pushed a commit to shdwcodr/Nest that referenced this pull request Jun 5, 2025
… ranges (OWASP#1047)

* issue#1034: Enhance date formatting in Home component to support date ranges

* Enhance date formatting functions and add unit tests for date utilities

* Update Upcoming Events date formatting in tests to reflect range display

* Refactor date range formatting for improved readability and maintainability

* Refactor formatDateRange function for improved readability

* Update code

---------

Co-authored-by: Arkadii Yakovets <2201626+arkid15r@users.noreply.github.com>
Co-authored-by: Kate Golovanova <kate@kgthreads.com>
Co-authored-by: Arkadii Yakovets <arkadii.yakovets@owasp.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve event dates representation

3 participants