1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/frontend/src/component/common/util.js

33 lines
725 B
JavaScript
Raw Normal View History

const dateTimeOptions = {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
};
2018-02-08 12:57:36 +01:00
export const formatFullDateTimeWithLocale = (v, locale, tz) => {
if (tz) {
dateTimeOptions.timeZone = tz;
}
return new Date(v).toLocaleString(locale, dateTimeOptions);
};
export const trim = value => {
if (value && value.trim) {
return value.trim();
} else {
return value;
}
};
2020-05-20 16:32:29 +02:00
export function updateWeight(variants, totalWeight) {
const size = variants.length;
const percentage = parseInt((1 / size) * totalWeight);
variants.forEach(v => {
v.weight = percentage;
});
return variants;
}