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
.
- When the site was first launched, the dates were formatted simply like
6 September 2013 at 11:35 AM
. - After a while, people demanded that if the date was today, then only show the time. Like
11:35 AM
. - After that, the users thought
yesterday at 11:35 AM
for the dates of yesterday would be even better. - Then the requirement was that, if the date is within seven days, show it like:
last Friday at 11:35 AM
. - Then people realized that the time part is not really necessary for dates older than seven days.
- 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. - 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. - 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
.
6 September 2013 11:35 AM
will be shown asat 11:35 AM
5 September 2013 11:35 AM
will be shown asyesterday at 11:35 AM
4 September 2013 11:35 AM
(Wednesday) will be shown aslast Wednesday at 11:35 AM
12 August 2013 11:35 AM
will be shown as12 August
12 August 2012
will be shown as12 August 2012
12 August 2010
will be shown asAugust 2010
12 August 2006
will be shown as7 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
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.