Hey, there
I completed Timestamp mini project
single test case is failed and I don’t know why
but it worked when I tested in browser
this is my code
app.get('/api',(req,res)=>{
const date = new Date()
res.json({
'unix': date.getTime(),
'utc': date.toUTCString()
})
})
app.get("/api/:date", (req, res) => {
const { date } = req.params
const inputDate = new Date(date)
if(inputDate.toUTCString() === 'Invalid Date'){
const stampToDate = new Date(Number(date))
if(stampToDate.toUTCString() === 'Invalid Date' ){
res.json({ error : "Invalid Date" })
}else{
res.json({
unix:date,
utc:stampToDate.toUTCString()
})
}
}else{
const unixTimeStamp = Math.floor(inputDate.getTime())
res.json({
unix:unixTimeStamp,
utc:inputDate.toUTCString()
})
}
})
and this is failed test case
A request to
/api/1451001600000
should return
{ unix: 1451001600000, utc: "Fri, 25 Dec 2015 00:00:00 GMT" }
Your project link(s)
solution: boilerplate-project-timestamp - Replit
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0
Challenge: Back End Development and APIs Projects - Timestamp Microservice
Link to the challenge: