Answer the question
In order to leave comments, you need to log in
Format date without library. Just a couple of features per project. What architectural solution to choose?
In the project, the date must be displayed in two formats:
- From now - 4 min ago
- MMM, YYYY - Jan, 2014
Example:
Handlebars.registerHelper "date_format", (date, options) ->
moment(date).format('MMM, YYYY')
Handlebars.registerHelper "from_now", (date, options) ->
moment(date).fromNow()
<i class="icon-clock"></i>
{{from_now date_posted}}
...
<li><span>Start Date:</span> {{date_format start_date}}</li>
Answer the question
In order to leave comments, you need to log in
Answer the following questions for yourself:
1. How many dates will be added to the project in the near future (let's say 6 months).
2. Which of the options I will write faster.
3. Will it be difficult to refactor if I write simple now, and then I need a more complex system.
In your case, this is a trifle, and not some major architectural decision. Of course, you shouldn’t lose sight of the little things either, but in such cases the most correct option is to do it because it’s faster and there is less code, then if you need to refactor.
And yes, the first question is the most important here. Because we design not to be beautiful, but to change the code later without any problems. You always need to think about what changes can happen.
THOSE. In your case the answer is probably 2.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question