I'm trying to do a really simple formatter, to replace some values in a string I pass in the function. I would like to replace for example 'DD' with the day of week. But when I do it, the return I get is the same string I pass as variable. So my issue is that I don't really know why when I do console log of today(), I get the same string:
today().then(data => console.log(data))
I get the same string that I input, "DD, dd de MM de YY."
const today = () => Promise.resolve(
getDate("DD, dd de MM de YY.").then(data => data)
)
Here is the code which should return my modified text:
const getDate = (text) => {
return new Promise( (resolve, reject) => {
let date = new Date()
text.replace('DD', translateWeekDay[date.getDay()])
text.replace('dd', date.getDate().toString())
text.replace('MM', translateMonth[date.getMonth()])
text.replace('YY', date.getFullYear().toString())
resolve(text)
})
.catch(err => console.log(err))
}
The thing is I have used a lot promises, so I'm structuring everything like that. Am I missing something essential??
Edit: I used promises because I thought it was something to do with async stuff. I now have seen my dum mistake!