-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c28f472
commit 954425d
Showing
3 changed files
with
77 additions
and
15 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const SortChatDate = ( | ||
firstMessageData: string | undefined, | ||
secondMessageData: string | undefined | ||
) => { | ||
if (firstMessageData && secondMessageData) { | ||
const firstDateYear = parseInt(firstMessageData?.[0]); | ||
const secondDateYear = parseInt(secondMessageData?.[0]); | ||
const firstDateMonth = parseInt(firstMessageData?.[1]); | ||
const secondDateMonth = parseInt(secondMessageData?.[1]); | ||
const firstDateDay = parseInt(firstMessageData?.[2]); | ||
const secondDateDay = parseInt(secondMessageData?.[2]); | ||
const firstDateHour = parseInt(firstMessageData?.[3]); | ||
const secondDateHour = parseInt(secondMessageData?.[3]); | ||
const firstDateMinute = parseInt(firstMessageData?.[4]); | ||
const secondDateMinute = parseInt(secondMessageData?.[4]); | ||
const firstDateSecond = parseInt(firstMessageData?.[5]); | ||
const secondDateSecond = parseInt(secondMessageData?.[5]); | ||
|
||
if (firstDateYear === secondDateYear) { | ||
if (firstDateMonth === secondDateMonth) { | ||
if (firstDateDay === secondDateDay) { | ||
if (firstDateHour === secondDateHour) { | ||
if (firstDateSecond === secondDateSecond) { | ||
return secondDateSecond - firstDateSecond; | ||
} | ||
return secondDateMinute - firstDateMinute; | ||
} | ||
return secondDateHour - firstDateHour; | ||
} | ||
return secondDateDay - firstDateDay; | ||
} | ||
return secondDateMonth - firstDateMonth; | ||
} | ||
return secondDateYear - firstDateYear; | ||
} | ||
}; | ||
|
||
export default SortChatDate; |