getDateFormat
getDateFormat unit test cases
This commit is contained in:
parent
1c48dc856a
commit
fcbbf298d5
2 changed files with 4 additions and 2 deletions
|
|
@ -96,7 +96,7 @@ export function shortTimeString(date) {
|
||||||
// Use a ternary operator to check if the input is a valid date object
|
// Use a ternary operator to check if the input is a valid date object
|
||||||
return date instanceof Date
|
return date instanceof Date
|
||||||
? // Use the built-in method toLocaleTimeString() to get the short time string in the current locale
|
? // Use the built-in method toLocaleTimeString() to get the short time string in the current locale
|
||||||
date.toLocaleTimeString(undefined, { hour: "numeric", minute: "numeric", hour12: true })
|
date.toLocaleTimeString("en-us", { hour: "numeric", minute: "numeric", hour12: true })
|
||||||
: // Return undefined if the input is not a valid date object
|
: // Return undefined if the input is not a valid date object
|
||||||
undefined;
|
undefined;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,9 @@ describe("date-helper.js", () => {
|
||||||
|
|
||||||
it("getDateFormat should return date in the given format.", () => {
|
it("getDateFormat should return date in the given format.", () => {
|
||||||
// Arrange / Act
|
// Arrange / Act
|
||||||
const date = new Date("2023-10-01");
|
const dateString = "2023-10-01";
|
||||||
|
const dateParts = dateString.split("-");
|
||||||
|
const date = new Date(dateParts[0], parseInt(dateParts[1]) - 1, dateParts[2]);
|
||||||
const format = "yyyy-MM-dd";
|
const format = "yyyy-MM-dd";
|
||||||
const formattedDate = getDateFormat(date, format);
|
const formattedDate = getDateFormat(date, format);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue