fixed testimonial slider issue, now using date-fns for dateFormat, update sortFunctions

This commit is contained in:
somrat sorkar
2023-05-09 16:27:56 +06:00
parent 3f2572b7d2
commit a555fd28f5
6 changed files with 22 additions and 26 deletions
+3 -14
View File
@@ -1,18 +1,7 @@
const dateFormat = (datetime: string | Date) => {
const dateTime = new Date(datetime);
import { formatInTimeZone } from "date-fns-tz";
const date = dateTime.toLocaleDateString([], {
year: "numeric",
month: "long",
day: "numeric",
});
const time = dateTime.toLocaleTimeString([], {
hour: "2-digit",
minute: "2-digit",
});
return date;
const dateFormat = (date:Date | string, format:string = "dd MMM, yyyy") => {
return formatInTimeZone(date, "America/New_York", format);
};
export default dateFormat;
+2 -2
View File
@@ -2,8 +2,8 @@
export const sortByDate = (array: any[]) => {
const sortedArray = array.sort(
(a:any, b:any) =>
new Date(b.data.date && b.data.date) -
new Date(a.data.date && a.data.date)
new Date(b.data.date && b.data.date).valueOf() -
new Date(a.data.date && a.data.date).valueOf()
);
return sortedArray;
};