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

Format date helper #882

merged 5 commits into from
Mar 11, 2015

Conversation

theharq
Copy link

@theharq theharq commented Mar 10, 2015

Use moment js to easily format dates, by default will use the "LL" format if is not specified

{{format-date invitation.createdAt}}
March 9, 2015

{{format-date invitation.createdAt format="L"}}
03/09/2015

theharq added 2 commits March 9, 2015 19:31
Use moment js to easily format dates, by default will use the "LL"
format if no format is specified

{{format-date invitation.createdAt}}

March 9, 2015

{{format-date invitation.createdAt format="L"}}

03/09/2015
@theharq
Copy link
Author

theharq commented Mar 10, 2015

I wanna mention that this handlebars helper was created with the ember generator.. I had trouble making the actual syntax to work with the tests

To test this handlebars snippets I could create an object view and compile it, because the helper expects 2 parameters, the value and options but I decided to keep it simple and send the second parameter as an object, this issue https://github.com/rwjblue/ember-qunit/issues/5 mentions the addition of moduleForSnippet we could wait for it and keep the bound helpers simple

@mikem
Copy link

mikem commented Mar 10, 2015

@theharq any chance you could find a place in our code where we format a date and use this helper, so we have a use case in core?

@theharq
Copy link
Author

theharq commented Mar 10, 2015

hi @mikem, well after looking the code I did not find a place where you guys are formatting a date at least in the ember templates, the reason I created this helper is because I thought that could be useful to have a consistency in the format we display dates ( a human readable or international format, sometimes I have a hard time when I see american date format hehe ), but I think, maybe we could move the calculation to the client side (is a good practice) for example here:
https://github.com/Tahi-project/tahi/blob/master/app/serializers/activity_feed_serializer.rb#L18

We gain some flexibility of momentjs also, I could update the default format of the helper to use the one use in the serializer:

created_at.strftime('%B %e, %Y %l:%M %p')

is equivalent in moment to:

moment().format('LLL');  // March 10, 2015 9:44 AM

let me know what do you think, if its too specific to be in the tahi core I could leave it in "my" engine ;)

@mikem
Copy link

mikem commented Mar 10, 2015

@theharq there's a date on the profile. Visit https://localhost:5000/profile and add an affiliation. You can format those dates using moment.js.

I think it's useful to have this in core, that's why I'm trying to find a use for it :-)

@theharq
Copy link
Author

theharq commented Mar 10, 2015

yup it will work, ex:
now we have
<div>{{a.startDate}} - {{a.displayEndDate}}</div>
and renders
A.T. Still University of Health Sciences
2015-02-01 - 2015-02-28
test@example.com

but if change the dates to and leave the default format ( I can use any format that momentjs support)

`

{{format-date a.startDate}} - {{format-date a.displayEndDate}}
``

I get

A.T. Still University of Health Sciences
February 1, 2015 - February 28, 2015
test@example.com

which I consider more human friendly, so the answer is yes, we could use this helper in parts of the tahi core

@mikem
Copy link

mikem commented Mar 10, 2015

@theharq great! Please update this PR to use format-date on the profile page.

theharq added 2 commits March 10, 2015 11:27
Add a guard clause that returns the original value if is not valid
@theharq
Copy link
Author

theharq commented Mar 10, 2015

I've updated the helper to ignore invalid formats, because the returns in the profile is sometimes "Current" so the helper just ignore this invalid strings to parse

let me know any other improvement ;)

mikem added a commit that referenced this pull request Mar 11, 2015
@mikem mikem merged commit 7a7ee90 into Aperta-project:master Mar 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants