chore: update renderFormattedTime function.

* remove unwanted code.
This commit is contained in:
Prateek Shourya 2024-01-02 12:49:26 +05:30
parent 5b88df9d1e
commit 74390d65af
4 changed files with 13 additions and 9 deletions

View File

@ -44,7 +44,7 @@ export const CyclesListItem: FC<TCyclesListItem> = (props) => {
const [updateModal, setUpdateModal] = useState(false);
const [deleteModal, setDeleteModal] = useState(false);
// computed
const cycleStatus = cycle.status?.toLocaleLowerCase() as TCycleGroups;
const cycleStatus = cycle.status.toLocaleLowerCase() as TCycleGroups;
const isCompleted = cycleStatus === "completed";
const endDate = new Date(cycle.end_date ?? "");
const startDate = new Date(cycle.start_date ?? "");

View File

@ -273,7 +273,7 @@ export const CycleDetailsSidebar: React.FC<Props> = observer((props) => {
[workspaceSlug, projectId, cycleId, issueFilters, updateFilters]
);
const cycleStatus = cycleDetails?.status.toLocaleLowerCase();
const cycleStatus = cycleDetails.status.toLocaleLowerCase();
const isCompleted = cycleStatus === "completed";
const isStartValid = new Date(`${cycleDetails?.start_date}`) <= new Date();

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">
<Clock className="h-4 w-4" />
<span>
Till {renderFormattedDate(notification.snoozed_till)}, {renderFormattedTime(notification.snoozed_till, true)}
Till {renderFormattedDate(notification.snoozed_till)}, {renderFormattedTime(notification.snoozed_till, '12hour')}
</span>
</p>
) : (

View File

@ -57,18 +57,18 @@ export const renderFormattedPayloadDate = (date: Date | string): string | null =
* @returns {string} formatted date in the format of hh:mm a or HH:mm
* @description Returns date in 12 hour format if in12HourFormat is true else 24 hour format
* @param {string | Date} date
* @param {boolean} in12HourFormat
* @example renderFormattedTime("2024-01-01", true) // 12:00 AM
* @example renderFormattedTime("2024-01-01") // 00:00
* @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", "12hour") // 01:00 PM
*/
export const renderFormattedTime = (date: string | Date, in12HourFormat?: boolean): string => {
export const renderFormattedTime = (date: string | Date, timeFormat: "12hour" | "24hour" = "24hour"): string => {
if (!date || date === "") return "";
// Parse the date to check if it is valid
const parsedDate = new Date(date);
// Check if the parsed date is valid
if (!isValid(parsedDate)) return ""; // Return empty string for invalid dates
// Format the date in 12 hour format if in12HourFormat is true
if (in12HourFormat) {
if (timeFormat === "12hour") {
const formattedTime = format(parsedDate, "hh:mm a");
return formattedTime;
}
@ -86,7 +86,11 @@ export const renderFormattedTime = (date: string | Date, in12HourFormat?: boolea
* @param {boolean} inclusive
* @example checkIfStringIsDate("2021-01-01", "2021-01-08") // 8
*/
export const findTotalDaysInRange = (startDate: Date | string, endDate: Date | string, inclusive: boolean = true): number => {
export const findTotalDaysInRange = (
startDate: Date | string,
endDate: Date | string,
inclusive: boolean = true
): number => {
if (!startDate || !endDate) return 0;
// Parse the dates to check if they are valid
const parsedStartDate = new Date(startDate);