-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: copy helper functions from admin and space into @plane/utils (#…
…6256) * chore: copy helper functions from space to @plane/utils Co-Authored-By: [email protected] <[email protected]> * refactor: move enums from utils/auth.ts to @plane/constants/auth.ts Co-Authored-By: [email protected] <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]>
- Loading branch information
1 parent
043f4ea
commit 9f5def3
Showing
11 changed files
with
651 additions
and
3 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
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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import { clsx, type ClassValue } from "clsx"; | ||
import { twMerge } from "tailwind-merge"; | ||
|
||
// Support email can be configured by the application | ||
export const getSupportEmail = (defaultEmail: string = ""): string => defaultEmail; | ||
|
||
export const cn = (...inputs: ClassValue[]) => twMerge(clsx(inputs)); |
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,46 @@ | ||
import { format, isValid } from "date-fns"; | ||
|
||
/** | ||
* This method returns a date from string of type yyyy-mm-dd | ||
* This method is recommended to use instead of new Date() as this does not introduce any timezone offsets | ||
* @param date | ||
* @returns date or undefined | ||
*/ | ||
export const getDate = (date: string | Date | undefined | null): Date | undefined => { | ||
try { | ||
if (!date || date === "") return; | ||
|
||
if (typeof date !== "string" && !(date instanceof String)) return date; | ||
|
||
const [yearString, monthString, dayString] = date.substring(0, 10).split("-"); | ||
const year = parseInt(yearString); | ||
const month = parseInt(monthString); | ||
const day = parseInt(dayString); | ||
// Using Number.isInteger instead of lodash's isNumber for better specificity and no external dependency | ||
if (!Number.isInteger(year) || !Number.isInteger(month) || !Number.isInteger(day)) return; | ||
|
||
return new Date(year, month - 1, day); | ||
} catch (e) { | ||
return undefined; | ||
} | ||
}; | ||
|
||
/** | ||
* @returns {string | null} formatted date in the format of MMM dd, yyyy | ||
* @description Returns date in the formatted format | ||
* @param {Date | string} date | ||
* @example renderFormattedDate("2024-01-01") // Jan 01, 2024 | ||
*/ | ||
export const renderFormattedDate = (date: string | Date | undefined | null): string | null => { | ||
// Parse the date to check if it is valid | ||
const parsedDate = getDate(date); | ||
// return if undefined | ||
if (!parsedDate) return null; | ||
// Check if the parsed date is valid before formatting | ||
if (!isValid(parsedDate)) return null; // Return null for invalid dates | ||
// Format the date in format (MMM dd, yyyy) | ||
const formattedDate = format(parsedDate, "MMM dd, yyyy"); | ||
return formattedDate; | ||
}; | ||
|
||
// Note: timeAgo function was incomplete in the original file, so it has been omitted |
Oops, something went wrong.