-
-
Notifications
You must be signed in to change notification settings - Fork 533
issue#1034: Enhance date formatting in Home component to support date ranges #1047
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5642359
issue#1034: Enhance date formatting in Home component to support date…
idityaGE 5612492
Merge branch 'main' into issue/1034
idityaGE daab33c
Merge branch 'main' into issue/1034
idityaGE 164ef76
Merge branch 'main' into issue/1034
arkid15r e908057
Enhance date formatting functions and add unit tests for date utilities
idityaGE 7067205
Update Upcoming Events date formatting in tests to reflect range display
idityaGE 9b9a202
Merge branch 'OWASP:main' into issue/1034
idityaGE 26ed17e
Refactor date range formatting for improved readability and maintaina…
idityaGE a4bd934
Refactor formatDateRange function for improved readability
idityaGE 1100bad
Merge branch 'main' into issue/1034
idityaGE feb968f
Merge branch 'main' into issue/1034
kasya 518af5f
Update code
arkid15r File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import { formatDate, formatDateRange } from 'utils/dateFormatter' | ||
|
|
||
| describe('formatDate function', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks() | ||
| }) | ||
|
|
||
| test('formats ISO date string correctly', () => { | ||
| expect(formatDate('2023-09-01')).toBe('Sep 1, 2023') | ||
| }) | ||
|
|
||
| test('formats Unix timestamp correctly', () => { | ||
| // 1630454400 is Sep 1, 2021 in Unix timestamp (seconds) | ||
| expect(formatDate(1630454400)).toBe('Sep 1, 2021') | ||
| }) | ||
|
|
||
| test('throws error for invalid date', () => { | ||
| expect(() => formatDate('invalid-date')).toThrow('Invalid date') | ||
| }) | ||
|
|
||
| test('handles different date formats', () => { | ||
| expect(formatDate('2023/09/01')).toBe('Sep 1, 2023') | ||
| expect(formatDate('09/01/2023')).toBe('Sep 1, 2023') | ||
| }) | ||
|
|
||
| test('formats dates with leading zeros correctly', () => { | ||
| expect(formatDate('2023-01-05')).toBe('Jan 5, 2023') | ||
| }) | ||
|
|
||
| test('handles different months', () => { | ||
| expect(formatDate('2023-12-25')).toBe('Dec 25, 2023') | ||
| expect(formatDate('2023-07-04')).toBe('Jul 4, 2023') | ||
| }) | ||
| }) | ||
|
|
||
| describe('formatDateRange function', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks() | ||
| }) | ||
|
|
||
| test('formats date range in same month correctly', () => { | ||
| expect(formatDateRange('2023-09-01', '2023-09-04')).toBe('Sep 1 — 4, 2023') | ||
| }) | ||
|
|
||
| test('formats date range in different months but same year correctly', () => { | ||
| expect(formatDateRange('2023-09-29', '2023-10-02')).toBe('Sep 29 — Oct 2, 2023') | ||
| }) | ||
|
|
||
| test('formats date range in different years correctly', () => { | ||
| expect(formatDateRange('2023-12-30', '2024-01-03')).toBe('Dec 30, 2023 — Jan 3, 2024') | ||
| }) | ||
|
|
||
| test('formats Unix timestamp date ranges correctly', () => { | ||
| // Sept 1-4, 2021 | ||
| const startTimestamp = 1630454400 // Sep 1, 2021 | ||
| const endTimestamp = 1630713600 // Sep 4, 2021 | ||
| expect(formatDateRange(startTimestamp, endTimestamp)).toBe('Sep 1 — 4, 2021') | ||
| }) | ||
|
|
||
| test('throws error when start date is invalid', () => { | ||
| expect(() => formatDateRange('invalid-date', '2023-09-04')).toThrow('Invalid date') | ||
| }) | ||
|
|
||
| test('throws error when end date is invalid', () => { | ||
| expect(() => formatDateRange('2023-09-01', 'invalid-date')).toThrow('Invalid date') | ||
| }) | ||
|
|
||
| test('handles month boundaries correctly', () => { | ||
| expect(formatDateRange('2023-09-30', '2023-10-02')).toBe('Sep 30 — Oct 2, 2023') | ||
| }) | ||
|
|
||
| test('handles year boundaries correctly', () => { | ||
| expect(formatDateRange('2023-12-29', '2024-01-02')).toBe('Dec 29, 2023 — Jan 2, 2024') | ||
| }) | ||
|
|
||
| test('handles single-day ranges correctly', () => { | ||
| expect(formatDateRange('2023-09-01', '2023-09-01')).toBe('Sep 1, 2023') | ||
| }) | ||
|
|
||
| test('handles mixed input types correctly', () => { | ||
| // Sep 1, 2021 as Unix timestamp and ISO string | ||
| expect(formatDateRange(1630454400, '2021-09-04')).toBe('Sep 1 — 4, 2021') | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.