[fix] Incorrect formatted date

- #61
- problem: December being formatted as 01ecember
This commit is contained in:
Faris Ansari 2018-05-19 21:40:03 +05:30
parent 8f4214a926
commit cd93fbf655

View File

@ -81,13 +81,21 @@ export default {
};
let str = format_string;
const formatted_values = [];
Object.keys(format_map)
.sort((a, b) => b.length - a.length) // big string first
.forEach(key => {
str = str.replace(key, format_map[key]);
if (str.includes(key)) {
str = str.replace(key, `$${formatted_values.length}`);
formatted_values.push(format_map[key]);
}
});
formatted_values.forEach((value, i) => {
str = str.replace(`$${i}`, value);
});
return str;
},