chore: update renderFormattedTime function params.

This commit is contained in:
Prateek Shourya 2024-01-02 14:27:18 +05:30
parent fadf106fcd
commit a2dd02abdb
2 changed files with 4 additions and 4 deletions

View File

@ -149,7 +149,7 @@ export const NotificationCard: React.FC<NotificationCardProps> = (props) => {
<p className="flex flex-shrink-0 items-center justify-end gap-x-1 text-custom-text-300"> <p className="flex flex-shrink-0 items-center justify-end gap-x-1 text-custom-text-300">
<Clock className="h-4 w-4" /> <Clock className="h-4 w-4" />
<span> <span>
Till {renderFormattedDate(notification.snoozed_till)}, {renderFormattedTime(notification.snoozed_till, '12hour')} Till {renderFormattedDate(notification.snoozed_till)}, {renderFormattedTime(notification.snoozed_till, '12-hour')}
</span> </span>
</p> </p>
) : ( ) : (

View File

@ -59,16 +59,16 @@ export const renderFormattedPayloadDate = (date: Date | string): string | null =
* @param {string | Date} date * @param {string | Date} date
* @param {boolean} timeFormat (optional) // default 24 hour * @param {boolean} timeFormat (optional) // default 24 hour
* @example renderFormattedTime("2024-01-01 13:00:00") // 13:00 * @example renderFormattedTime("2024-01-01 13:00:00") // 13:00
* @example renderFormattedTime("2024-01-01 13:00:00", "12hour") // 01:00 PM * @example renderFormattedTime("2024-01-01 13:00:00", "12-hour") // 01:00 PM
*/ */
export const renderFormattedTime = (date: string | Date, timeFormat: "12hour" | "24hour" = "24hour"): string => { export const renderFormattedTime = (date: string | Date, timeFormat: "12-hour" | "24-hour" = "24-hour"): string => {
if (!date || date === "") return ""; if (!date || date === "") return "";
// Parse the date to check if it is valid // Parse the date to check if it is valid
const parsedDate = new Date(date); const parsedDate = new Date(date);
// Check if the parsed date is valid // Check if the parsed date is valid
if (!isValid(parsedDate)) return ""; // Return empty string for invalid dates if (!isValid(parsedDate)) return ""; // Return empty string for invalid dates
// Format the date in 12 hour format if in12HourFormat is true // Format the date in 12 hour format if in12HourFormat is true
if (timeFormat === "12hour") { if (timeFormat === "12-hour") {
const formattedTime = format(parsedDate, "hh:mm a"); const formattedTime = format(parsedDate, "hh:mm a");
return formattedTime; return formattedTime;
} }