Are the ExerciseTracker tests working properly? I can't pass the "date property" test and neither can the official FCC solution

Hi, I am failing this test in the Exercise Tracker:

The date property of any object in the log array that is returned from GET /api/users/:id/logs should be a string… Use the dateString format of the Date API.

Here’s what I’ve tried:

  • I used the dateString() function to convert my dates to string, before outputting it in JSON. It is stored as Date in Mongo, so I call this dateString() function
  • I ensured my output looks the exact same as the FCC solutions
  • I console logged inputs/outputs to ensure no edge cases are breaking

My code is below, but what confuses me is that the official FCC solution, when submitted as a solution, doesn’t pass the test either. Are other people able to pass it? Thank you.

//Require packages

const express = require('express')
const app = express()
const cors = require('cors')
var bodyParser = require('body-parser');
const mongoose = require('mongoose'); 

//Connnect to mongo
const mongoURI = process.env['DATABASE'];
mongoose.connect(mongoURI, { useNewUrlParser: true, useUnifiedTopology: true });
var User = require('./models/userModel.js');
var Exercise = require('./models/exercise.js');


    extended: true

app.get('/', (req, res) => {
  res.sendFile(__dirname + '/views/index.html')
});'/api/users', (req, res) => {
  console.log("route: users post: " + req.body.username);
  var username = req.body.username; 
  var obj = new User( {username: username} );, obj){
         return console.error(err)} else{
             res.json({ username: username, _id: obj._id });
});'/api/users/:id/exercises', (req, res) => {
  console.log("route: post exercises. testing id: "+ + ".  inputted date: " +;
  var id =;
  var description = req.body.description;
  var duration = req.body.duration;
  var dateInput =;

  var date;
  var regex = /([0-9]{4})-([0-9]{2})-([0-9]{2})/;  

  if(dateInput == "" || dateInput == undefined){
      date = new Date();
  } else if(dateInput.match(regex)){
      let result = dateInput.match(regex);
    //Month-1 since months are 0-indexed
      date = new Date(result[1],result[2]-1,result[3]);
  } else{
    //For any other cases, like string, just send it to Mongo and let it trigger validation error
    date =;

  var obj = new Exercise({ id: id, description: description, duration: duration, date: date });

  var username; 
  User.findById(id, (err, obj) =>{
    if(err) return console.error(err);
    if(!obj) res.json({error: "Can't find user"});
    username = obj.username;
  });, obj){
         return res.send( + ": " + err.message)} else{
             res.json({ _id: id, username: username, date: date.toDateString(), duration: parseInt(duration), description: description });


app.get('/api/users', (req, res) => {
  console.log("route: users get all");
  User.find({}, function (err, obj) {
    res.json( obj );

app.get('/api/users/:id/logs', (req, res) => {
  console.log("route: user logs. user id: " +;
  //620698d725f23b55671eb7a6  is my test user ID
  var id =;
  var username;
  var temp = [];

  var userQuery = User.findById(id);
  var exerciseQuery = Exercise.find({ id:id }).select('description duration date -_id')

    exerciseQuery = exerciseQuery.limit(req.query.limit);

    var dateInput = req.query.from;
    var regex = /([0-9]{4})-([0-9]{2})-([0-9]{2})/;  

      let result = dateInput.match(regex);  
      var fromDate = new Date(result[1],result[2]-1,result[3]);
      exerciseQuery = exerciseQuery.where('date').gte(fromDate);
    } else{
      res.json({error: "Date not valid! Try again."});

    var dateInput =;
    var regex = /([0-9]{4})-([0-9]{2})-([0-9]{2})/;  

      let result = dateInput.match(regex);  
      var toDate = new Date(result[1],result[2]-1,result[3]);
      exerciseQuery = exerciseQuery.where('date').lte(toDate);
    } else{
      res.json({error: "Date not valid! Try again."});

  .then(results => {
    const[user, exercises] = results;
    exercises.forEach(item => {
      temp.push({description: item.description, duration: item.duration, date:})
     res.json( { _id: id, username: user.username, count: exercises.length, log: temp } );
  .catch( err => {
    res.json({error: "Something didn't work correctly!"});

const listener = app.listen(process.env.PORT || 3000, () => {
  console.log('Your app is listening on port ' + listener.address().port)

Check the forums for the many mentions of the time zone offset problem with this challenge and retry the tests when your local date and the UTC date are the same.

1 Like

I’ll give that a shot, thank you friend.

I found a post @jeremy.a.gray made last year (link) and it was correct about time zone offset being the issue. All I had to do was submit my project earlier in the day (while my local time zone and UTC time zone matches up) and it passed without a problem. Hope his post helps anyone in the future experiencing the same issue.

Thank you to Jeremy!

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