Skip to content

Instantly share code, notes, and snippets.

@fabriciotav
Created April 4, 2014 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabriciotav/9975815 to your computer and use it in GitHub Desktop.
Save fabriciotav/9975815 to your computer and use it in GitHub Desktop.
Using D3 and Handlebars to deal with date formatting in Ember
Ember.Handlebars.registerBoundHelper('date', function(date, specifier) {
if (arguments.length === 2) specifier = '%Y-%m-%d';
return Object.prototype.toString.call(date) === '[object Date]' ? d3.time.format(specifier)(date) : specifier;
});
<!-- Usage example -->
{{date dateValue '%d/%m/%Y'}} <!-- 04/04/2014 -->
{{date dateValue}} <!-- 2014-04-04 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment