-
Notifications
You must be signed in to change notification settings - Fork 53
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
9b208cf
commit 07f87ec
Showing
4 changed files
with
4,633 additions
and
7,318 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,34 +1,41 @@ | ||
import { format } from "date-fns"; | ||
import { FormatBody } from './formatbody'; | ||
import moment from 'moment'; | ||
|
||
/** | ||
* @description parse and extract the timestamp from the body of the notification and remove the text from the body | ||
* @param notificationBody the text which would represent the body of the notification | ||
* @returns | ||
*/ | ||
export function extractTimeStamp(notificationBody: string): { | ||
notificationBody: string; | ||
timeStamp: string; | ||
originalBody: string; | ||
} { | ||
const parsedBody = { | ||
notificationBody: FormatBody(notificationBody), | ||
timeStamp: "", | ||
originalBody: notificationBody, | ||
}; | ||
const matches = notificationBody.match(/\[timestamp:(.*?)\]/); | ||
if (matches) { | ||
parsedBody.timeStamp = matches[1]; | ||
const textWithoutTimeStamp = notificationBody.replace( | ||
/ *\[timestamp:[^)]*\] */g, | ||
"" | ||
); | ||
parsedBody.notificationBody = FormatBody(textWithoutTimeStamp); | ||
parsedBody.originalBody = textWithoutTimeStamp; | ||
} | ||
return parsedBody; | ||
export function extractTimeStamp(notificationBody: string): { | ||
notificationBody: string; | ||
timeStamp: string; | ||
originalBody: string; | ||
} { | ||
const parsedBody = { | ||
notificationBody: FormatBody(notificationBody), | ||
timeStamp: '', | ||
originalBody: notificationBody, | ||
}; | ||
const matches = notificationBody.match(/\[timestamp:(.*?)\]/); | ||
if (matches) { | ||
parsedBody.timeStamp = matches[1]; | ||
const textWithoutTimeStamp = notificationBody.replace(/ *\[timestamp:[^)]*\] */g, ''); | ||
parsedBody.notificationBody = FormatBody(textWithoutTimeStamp); | ||
parsedBody.originalBody = textWithoutTimeStamp; | ||
} | ||
|
||
export function convertTimeStamp(timeStamp: string) { | ||
return format(new Date(Number(timeStamp) * 1000), 'dd MMM yyyy | hh:mm a') | ||
} | ||
return parsedBody; | ||
} | ||
|
||
export function convertTimeStamp(timeStamp: string) { | ||
const date = moment.unix(Number(timeStamp)); | ||
|
||
if (moment().isSame(date, 'day')) { | ||
return `Today | ${date.format('hh:mm A')}`; | ||
} else if (moment().subtract(1, 'days').isSame(date, 'day')) { | ||
return `Yesterday | ${date.format('hh:mm A')}`; | ||
} else if (moment().add(1, 'days').isSame(date, 'day')) { | ||
return `Tomorrow | ${date.format('hh:mm A')}`; | ||
} else { | ||
return date.format('DD MMM YYYY | hh:mm A'); | ||
} | ||
} |
Oops, something went wrong.