It's Just A Function

Relative Time Formatter Assignment

In How long has it been I talked a bit about representing relative time in software. So, here's an assignment that can be as simple or as complex as you want to make it: write a function that returns a relative 'time ago' natural language string - either between two dates, or between another date and now.

Considerations

As with most programming problems, there is no single correct answer. You can use the basic idea as a starting point, and expand in whatever direction you like.

Here are a few decisions you might need to make, in no particular order:

Maximizing Your Learning, and Getting Help

Not sure where to start? Here are some tips to maximize your learning, while still getting some help, in the age of AI.

Extra Bonus Assignment

If you want to raise your challenge level considerably, you could also consider a relative time parser. For example, given a string like three days and seven hours ago, return an absolute date.

Sharing Some Examples

Later, I'll share some examples I've found. I'll start with examples from the JavaScript ecosystem, but I'll look for a few from other languages as well.


#assignments #dates #functions