Haven't passed test #5: Your project can handle dates that can be successfully parsed by new Date(date_string) - fCC Timestamp Microservice Project

I haven’t passed test #5 from the Timestamp Microservice project of the Back End Development and APIs certification: "Your project can handle dates that can be successfully parsed by new Date(date_string)".

I’ve tried deploying it to Heroku and pasting that app as the solution link as well as the app I created on Replit.

This my code so far:

// server.js
// where your node app starts

// init project
var express = require('express');
var app = express();

// enable CORS (https://en.wikipedia.org/wiki/Cross-origin_resource_sharing)
// so that your API is remotely testable by FCC 
var cors = require('cors');
app.use(cors({optionsSuccessStatus: 200}));  // some legacy browsers choke on 204

// http://expressjs.com/en/starter/static-files.html

// http://expressjs.com/en/starter/basic-routing.html
app.get("/", function (req, res) {
  res.sendFile(__dirname + '/views/index.html');

// your first API endpoint... 
app.get("/api/hello", function (req, res) {
  res.json({greeting: 'hello API'});

// listen for requests :)
var listener = app.listen(process.env.PORT, function () {
  console.log('Your app is listening on port ' + listener.address().port);

let resObject = {}

app.get('/api/:input', (req, res) => {
  let input = req.params.input
  /* Date String */
  resObject['unix'] = new Date(input).getTime()
  resObject['utc'] = new Date(input).toUTCString()
  /* Timestamp */
  input = parseInt(input)

  resObject['unix'] = new Date(input).getTime()
  resObject['utc'] = new Date(input).toUTCString()

if(!resObject['utc'] || !resObject['unix']){
  res.json({error: 'Invalid Date'})


app.get('/api', (req, res) => {
  resObject['unix'] = new Date().getTime()
  resObject['utc'] = new Date().toUTCString()

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36

Challenge: Timestamp Microservice

Link to the challenge:

I believe that replit will run it on a server for you - I don’t think you need heroku.

Do you have a link to your replit project? Or the heroku server? It would be easier to test it that way, to see what the tests are seeing.

1 Like

Sure. Here’s my Replit project link:

1 Like

You can get the replit server by pressing this:

You can use that link in the project submission.

So, your test is failing:

Your project can handle dates that can be successfully parsed by new Date(date_string)

When I open up the browser dev tools and look at the network traffic, I see that this is the call they are using to test that test:

Request URL: https://mytimestampms--rjkawoya.repl.co/api/05%20October%202011
Request Method: GET
Status Code: 200 

The call is succeeding and this is what is being returned:

{"unix":5,"utc":"Thu, 01 Jan 1970 00:00:00 GMT"}

The date submitted was 05%20October%202011. If we replace those escape codes of %20 with a space, we see that it is: 05 October 2011. Compare that to what you are returning. You are giving an unix timecode of 5. Remember that that is the number of milliseconds from Jan 1, 1970. I think you math is off.

Does that help?

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.