don't hate me, old git is fuck up
This commit is contained in:
13
src/utils/getDate.tsx
Normal file
13
src/utils/getDate.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
export const daysAgo = (numOfDays, date = new Date()) => {
|
||||
const daysAgo = new Date(date.getTime());
|
||||
daysAgo.setDate(date.getDate() - numOfDays);
|
||||
|
||||
return daysAgo;
|
||||
};
|
||||
|
||||
export const hoursAgo = (numOfHours, date = new Date()) => {
|
||||
const hoursAgo = new Date(date.getTime());
|
||||
hoursAgo.setHours(date.getHours() - numOfHours);
|
||||
|
||||
return hoursAgo;
|
||||
};
|
||||
12
src/utils/truncate.tsx
Normal file
12
src/utils/truncate.tsx
Normal file
@@ -0,0 +1,12 @@
|
||||
export const truncate = (fullStr: string, strLen: number, separator: string | unknown[]) => {
|
||||
if (fullStr.length <= strLen) return fullStr;
|
||||
|
||||
separator = separator || '...';
|
||||
|
||||
const sepLen = separator.length,
|
||||
charsToShow = strLen - sepLen,
|
||||
frontChars = Math.ceil(charsToShow / 2),
|
||||
backChars = Math.floor(charsToShow / 2);
|
||||
|
||||
return fullStr.substr(0, frontChars) + separator + fullStr.substr(fullStr.length - backChars);
|
||||
};
|
||||
Reference in New Issue
Block a user