-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Duration to Sampling Period UI Table (#1414)
- formatTimeDifference function
- Loading branch information
1 parent
1ab1e64
commit 5203f31
Showing
3 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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,53 @@ | ||
import { combineDateTime, formatTimeDifference } from './datetime'; | ||
|
||
describe('combineDateTime', () => { | ||
it('combines date and time into an ISO string', () => { | ||
const result = combineDateTime('2024-01-01', '12:30:00'); | ||
expect(result).toEqual('2024-01-01T12:30:00.000Z'); | ||
}); | ||
|
||
it('combines date without time into an ISO string', () => { | ||
const result = combineDateTime('2024-01-01'); | ||
expect(result).toEqual('2024-01-01T00:00:00.000Z'); | ||
}); | ||
|
||
it('returns ISO string for a different date and time', () => { | ||
const result = combineDateTime('2023-12-31', '23:59:59'); | ||
expect(result).toEqual('2023-12-31T23:59:59.000Z'); | ||
}); | ||
|
||
it('handles invalid date formats gracefully', () => { | ||
const date = combineDateTime('badDate', '12:00'); | ||
expect(date).toEqual('Invalid Date'); | ||
|
||
const time = combineDateTime('2024-01-01', 'badtime'); | ||
expect(time).toEqual('Invalid Date'); | ||
}); | ||
}); | ||
|
||
describe('formatTimeDifference', () => { | ||
it('formats the time difference correctly between two dates and times', () => { | ||
const result = formatTimeDifference('2024-01-01', '12:00', '2024-01-02', '13:30'); | ||
expect(result).toEqual('1 day and 1 hour'); | ||
}); | ||
|
||
it('handles time difference with only dates', () => { | ||
const result = formatTimeDifference('2024-01-01', null, '2024-01-03', null); | ||
expect(result).toEqual('2 days'); | ||
}); | ||
|
||
it('formats the time difference correctly with no time component', () => { | ||
const result = formatTimeDifference('2024-01-01', null, '2024-01-01', '01:00'); | ||
expect(result).toEqual('1 hour'); | ||
}); | ||
|
||
it('returns null when there is no time difference', () => { | ||
const result = formatTimeDifference('2024-01-01', null, '2024-01-01', null); | ||
expect(result).toBeNull(); | ||
}); | ||
|
||
it('handles cases with invalid inputs', () => { | ||
const result = formatTimeDifference('invalid-date', null, '2024-01-01', null); | ||
expect(result).toBeNull(); | ||
}); | ||
}); |
This file contains 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