mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-08 08:39:03 +02:00
2ef5db2938
[web] Clean up localized currency format test (`local-ccy-format-v2`) GitOrigin-RevId: 30d671479522b87ee9205994508b745d2b0ae4c3
39 lines
994 B
JavaScript
39 lines
994 B
JavaScript
const dateformat = require('dateformat')
|
|
const { formatCurrency } = require('../../util/currency')
|
|
|
|
/**
|
|
* @param {number} priceInCents - price in the smallest currency unit (e.g. dollar cents, CLP units, ...)
|
|
* @param {CurrencyCode?} currency - currency code (default to USD)
|
|
* @param {string} [locale] - locale string
|
|
* @returns {string} - formatted price
|
|
*/
|
|
function formatPriceLocalized(priceInCents, currency = 'USD', locale) {
|
|
const isNoCentsCurrency = ['CLP', 'JPY', 'KRW', 'VND'].includes(currency)
|
|
|
|
const priceInCurrencyUnit = isNoCentsCurrency
|
|
? priceInCents
|
|
: priceInCents / 100
|
|
|
|
return formatCurrency(priceInCurrencyUnit, currency, locale)
|
|
}
|
|
|
|
function formatDateTime(date) {
|
|
if (!date) {
|
|
return null
|
|
}
|
|
return dateformat(date, 'mmmm dS, yyyy h:MM TT Z', true)
|
|
}
|
|
|
|
function formatDate(date) {
|
|
if (!date) {
|
|
return null
|
|
}
|
|
return dateformat(date, 'mmmm dS, yyyy', true)
|
|
}
|
|
|
|
module.exports = {
|
|
formatPriceLocalized,
|
|
formatDateTime,
|
|
formatDate,
|
|
}
|