Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format date helper #882

Merged
merged 5 commits into from
Mar 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions client/app/helpers/format-date.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
`import Ember from 'ember'`

formatDate = (date, options) ->
return date unless moment(date).isValid()
moment(date).format(options.hash.format || "LL")

FormatDateHelper = Ember.Handlebars.makeBoundHelper formatDate

`export { formatDate }`

`export default FormatDateHelper`
2 changes: 1 addition & 1 deletion client/app/pods/profile/affiliation-form/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="profile-affiliation">
<div class="profile-affiliation-name">{{a.name}}</div>
<div class="glyphicon glyphicon-remove-circle profile-remove-affiliation" {{action "removeAffiliation" a}}></div>
<div>{{a.startDate}} - {{a.displayEndDate}}</div>
<div>{{format-date a.startDate}} - {{format-date a.displayEndDate}}</div>
<div>{{a.email}}</div>
</div>
{{/each}}
Expand Down
19 changes: 19 additions & 0 deletions client/tests/unit/helpers/format-date-test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
`import { formatDate } from 'tahi/helpers/format-date'`

module 'FormatDateHelper'

test 'default formatting', ->
helper_options = {hash: {}}
date = new Date('February 06, 1990')
result = formatDate(date, helper_options)
equal(result, 'February 6, 1990', 'returns a human readable date')

test 'specify formatting', ->
helper_options = {hash: {format: 'l'}}
result = formatDate(new Date('February 06, 1990'), helper_options)
equal(result, '2/6/1990', 'returns date in a custom format')

test 'format only valid dates', ->
helper_options = {hash: {}}
result = formatDate('hello world', helper_options)
equal(result, 'hello world', 'returns original value sent')