Code challenge: tell the time

I'm going to try something new and share with you a quick code challenge. It's actually more of a solution design challenge. The code part should be fairly trivial.

I'm going to share my solution next week. If you decide to solve this, post a Gist with your solution (and any relevant notes) and tweet the URL at me (@assaf), I'll link to it.

Imagine your computer's clock is not longer set correctly, and it tells the wrong time. You want to find out what the time is, good within plus/minus one second.

The HTTP protocol specifies that servers should return the Date header. Based on this header, you can tell what the time is according to some other computer*.

You have a file called hostnames.txt with a list of servers, it looks like this:

Write a simple script that uses this list of servers to tell the time. When executed, the script should print out the time in ISO 8601 format to the console. For example:

$ node time.js

Any version of Node/io.js, but the script should be self contained, no dependencies allowed.

* Yes, NTP servers are a better way to tell the time), but it won't be an interesting challenge using NTP, wouldn't it?

🔥 Looking for more? Subscribe to Weekend Reading.

Or grab the RSS feed