APIs and Microservices Projects - Timestamp Microservice test5 and test6 problem

Tell us what’s happening:
I’ve seen All posibilities with the code and crosschecked pretty much every parameter the tests are not getting passed even though the output is correct can anyone pls tell me how to pass that test and how to submit the test… i’ve tried the suggestions in the forum.!

These tests are not getting Passed –
test 5 -> It should handle an empty date parameter, and return the current time in unix format
test 6 -> It should handle an empty date parameter, and return the current time in UTC format

Your code so far

“use strict”;

var express = require(“express”);
var app = express();

var cors = require(“cors”);


app.use("/public", express.static(process.cwd() + “/public”));

app.route("/").get(function(req, res) {
res.sendFile(process.cwd() + “/views/index.html”);

app.get("/api/timestamp/", (req, res) => {
res.json({ unix: Date.now(), utc: Date.now() });

app.get("/api/timestamp/:date_string", (req, res) => {
let dateString = req.params.date_string;

//A 4 digit number is a valid ISO-8601 for the beginning of that year
//5 digits or more must be a unix time, until we reach a year 10,000 problem
if (/\d{5,}/.test(dateString)) {
let dateInt = parseInt(dateString);
//Date regards numbers as unix timestamps, strings are processed differently
res.json({ unix: dateString, utc: new Date(dateInt).toUTCString() });

let dateObject = new Date(dateString);

if (dateObject.toString() === “Invalid Date”) {
res.json({ error: “Invaid Date” });
} else {
res.json({ unix: dateObject.valueOf(), utc: dateObject.toUTCString() });

// 404 Not Found Middleware
app.use(function(req, res, next) {
.send(“Not Found”);

app.listen(process.env.PORT || 3000, function() {
console.log(“Node.js listening …”);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36.

Challenge: undefined

Link to the challenge:

Solved it !!!

app.get("/api/timestamp", (req, res) => {
  res.json({ unix: Date.now(), utc: Date.now() });

Just Change the TimeZone the API takes time from your Computer So … :slight_smile:
i’ve used islamabad , pakistan timezone

1 Like

I am getting stuck on this same spot !! How did you change the time zone the API is using?