Timestamp project | "An empty date parameter should return the current time in a JSON object with a utc/unix key" test doesn't work correctly
See original GitHub issueHello. In the timestamp project, the results of all tests are successful, except for the data value tests: “An empty date parameter should return the current time in a JSON object with a unix key An empty date parameter should return the current time in a JSON object with a utc key”
I did some research and the logic in your test is as follows:
(getUserInput) =>
$.get(getUserInput('url') + '/api').then(
(data) => {
var now = Date.now();
assert.approximately(data.unix, now, 20000);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
When the difference between the current time specified in the test and the time in the response is large, the test fails, ie if the difference is greater than 20,000, the result fails (as it usually does). To check, I added +20000 to the current time I set in the code and the test was successful.
Affected page
Your code
// empty date parameter
app.get("/api", (req, res)=>{
let date = new Date();
let UTC = date.toUTCString();
let UNIX = date.getTime();
res.json({ unix: UNIX, utc: UTC });
})
Expected behavior
the test must be successful
Screenshots
my result:
System
- Device: Laptop
- OS: Windows 10
- Browser: edge
- Version: 99.0.1150.30
Additional context
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Please help - APIs and Microservices Projects - JavaScript
An empty date parameter should return the current time in a JSON object with a 'utc' key. Your code so far app.get("/api/timestamp", (req,...
Read more >gmdate - Manual - PHP
gmdate(string $format , ?int $timestamp = null ): string. Identical to the date() function except that the time returned is Greenwich Mean Time...
Read more >Gemini REST API Reference
a JSON array. Each element contains a payload that will be described. Timestamps. The timestamp data type describes a date and time as...
Read more >Pulse One API Client Specification - Product Documentation
The information in this document is current as of the date on the title ... correctly, a JSON body containing a User Entity...
Read more >Handling Time Zone in JavaScript - TOAST UI - Medium
Implementing time zone features beyond simple formatting of time and calculating time data with complex operations (e.g. calendar) was a truly daunting task....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @ebdurrehm I forked your repl (https://replit.com/@ojeytonwilliams/boilerplate-project-timestamp-1#server.js) and converted it to use
and it passes all the tests. If I instead increased it from
+ 20000
to+ 25000
it fails fairly reliably. This is to be expected, sinceassert.approximately(actual, expected, delta)
should fail whenactual - expected > 20000
.If you haven’t already, it might be worthwhile to discuss this on the forum.
In case anybody else ends up here, I couldn’t get this to pass either, ended up here too, and used @ojeytonwilliams answer but removed the +20000 and it passed after submitting it a few times. I’ve had trouble with lots of the freeCodeCamp + replit tests not passing unless submitted multiple times, so always try a few times (in my experience). Thanks for the help, and the free education.
(code for reference)