♻️ Refactors date time method

This commit is contained in:
Alicia Sykes
2021-12-19 20:02:44 +00:00
parent f46d1df72a
commit 58cb439086
4 changed files with 20 additions and 7 deletions

View File

@@ -48,7 +48,8 @@ export const applyItemId = (inputSections) => {
return sections;
};
export const convertTimestampToDate = (timestamp) => {
/* Given a timestamp, returns formatted date, in local format */
export const timestampToDate = (timestamp) => {
const localFormat = navigator.language;
const dateFormat = {
weekday: 'short', day: 'numeric', month: 'short', year: '2-digit',
@@ -57,6 +58,18 @@ export const convertTimestampToDate = (timestamp) => {
return `${date}`;
};
/* Given a timestamp, returns formatted time in local format */
export const timestampToTime = (timestamp) => {
const localFormat = navigator.language;
const timeFormat = { hour: 'numeric', minute: 'numeric', second: 'numeric' };
const time = Intl.DateTimeFormat(localFormat, timeFormat).format(new Date(timestamp));
return time;
};
export const timestampToDateTime = (timestamp) => {
return `${timestampToDate(timestamp)} at ${timestampToTime(timestamp)}`;
};
/* Given a currency code, return the corresponding unicode symbol */
export const findCurrencySymbol = (currencyCode) => {
const code = currencyCode.toUpperCase().trim();