iut-cse/OOKata

A nice date format

Opened this issue · 0 comments

Overview

The social media website you are developing has got quite a lot of traffic recently. You are always trying to improve it. The improvement you are currently focused on is how dates look in the posts.

Like any other website, yours shows when a post was created. Your date formatting went through a few evolutions.

Assume that you are formatting 6 September 2013 at 11:35 AM.

  1. When the site was first launched, the dates were formatted simply like 6 September 2013 at 11:35 AM.
  2. After a while, people demanded that if the date was today, then only show the time. Like 11:35 AM.
  3. After that, the users thought yesterday at 11:35 AM for the dates of yesterday would be even better.
  4. Then the requirement was that, if the date is within seven days, show it like: last Friday at 11:35 AM.
  5. Then people realized that the time part is not really necessary for dates older than seven days.
  6. People were happy with what they had for some time, then they thought just 6 September will be great if the date is less than a year ago.
  7. Then people figured that they do not need a specific date for the posts which are older than 2 years. Just September 2013 would be good.
  8. And recently, the users are saying that they want to see dates older than 4 years lie 5 years ago.

Example

Assume that today is 6 September 2013, Friday.

  1. 6 September 2013 11:35 AM will be shown as at 11:35 AM
  2. 5 September 2013 11:35 AM will be shown as yesterday at 11:35 AM
  3. 4 September 2013 11:35 AM (Wednesday) will be shown as last Wednesday at 11:35 AM
  4. 12 August 2013 11:35 AM will be shown as 12 August
  5. 12 August 2012 will be shown as 12 August 2012
  6. 12 August 2010 will be shown as August 2010
  7. 12 August 2006 will be shown as 7 years ago

Task

Implement the date formatting step by step as per the change of requirement.
If you can, commit at least once after you implement each requirement.

Help

Most languages have some kind of date implementation in the box. Here is a list for some common languages

  1. C#: DateTime
  2. JavaScript/TypeScript: Date
  3. Java: Date

Feel free to add the reference to the date representations in other languages.


Reminders

  • React to the problem if you find it interesting and helpful. This will help others to easily identify good problems to solve.
  • Feel free to comment about the problem. Is the description unclear? Do you think it is too easy or too difficult than what is mentioned? Comment about it.
  • Discussion about the solution is OK. But do not paste a solution here. Give a link to the solution instead.
  • Do you have an interesting problem? Post it.