From d5432774cc6563b11419c859a35db1029116d91b Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sat, 11 Dec 2021 20:46:22 +0000 Subject: [PATCH] :zap: Adds helper functions for converting date, and currency --- src/utils/MiscHelpers.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/utils/MiscHelpers.js b/src/utils/MiscHelpers.js index da9a683f..3591b7cd 100644 --- a/src/utils/MiscHelpers.js +++ b/src/utils/MiscHelpers.js @@ -46,3 +46,36 @@ export const applyItemId = (inputSections) => { }); return sections; }; + +export const convertTimestampToDate = (timestamp) => { + const localFormat = navigator.language; + const dateFormat = { + weekday: 'short', day: 'numeric', month: 'short', year: 'numeric', + }; + const date = new Date(timestamp).toLocaleDateString(localFormat, dateFormat); + return `${date}`; +}; + +/* Given a currency code, return the corresponding unicode symbol */ +export const findCurrencySymbol = (currencyCode) => { + const code = currencyCode.toUpperCase().trim(); + const currencies = { + USD: '$', // US Dollar + EUR: '€', // Euro + CRC: '₡', // Costa Rican Colón + GBP: '£', // British Pound Sterling + ILS: '₪', // Israeli New Sheqel + INR: '₹', // Indian Rupee + JPY: '¥', // Japanese Yen + KRW: '₩', // South Korean Won + NGN: '₦', // Nigerian Naira + PHP: '₱', // Philippine Peso + PLN: 'zł', // Polish Zloty + PYG: '₲', // Paraguayan Guarani + THB: '฿', // Thai Baht + UAH: '₴', // Ukrainian Hryvnia + VND: '₫', // Vietnamese Dong + }; + if (currencies[code]) return currencies[code]; + return code; +};