Skip to content

Support for HTML5 time element; option for lowercase dates #3

Merged
merged 2 commits into from Dec 21, 2011

2 participants

@samatjain

Support HTML5's time element (a preferred way to markup dates, which includes W3CTDF dates in the "datetime" attribute).

Also, add option to jQuery plugin to lowercase generated dates.

Unit tests included for both.

Sorry for adding 2 features in the same branch!

@zachleat zachleat and 1 other commented on an outdated diff Dec 10, 2011
src/humane.js
return this.each(function()
{
var $t = jQuery(this),
- date = humaneDate($t.attr('title'));
+ date = $t.attr('datetime') || $t.attr('title');
+
+ if(typeof date === 'undefined')
+ return;
+
+ date = humaneDate(date);
@zachleat
Owner
zachleat added a note Dec 10, 2011

Might be better as date = humanDate(date) || '';

Then we can eliminate the typeof comparison below.

@samatjain
samatjain added a note Dec 12, 2011

Agreed 100%.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@zachleat zachleat commented on an outdated diff Dec 10, 2011
src/humane.js
return this.each(function()
{
var $t = jQuery(this),
- date = humaneDate($t.attr('title'));
+ date = $t.attr('datetime') || $t.attr('title');
+
+ if(typeof date === 'undefined')
@zachleat
Owner
zachleat added a note Dec 10, 2011

If(!date) should work here, no? typeof feels too restrictive. If the attributes exist but are empty strings, this will continue on its merry way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
samatjain added some commits Dec 15, 2011
@samatjain samatjain Support for HTML5 time element
Look for HTML5 time element's "datetime" attribute first, then "title"
attribute. Includes unit test.
99a45fa
@samatjain samatjain Lowercase output option
Add option (at jQuery plugin level) to lowercase dates (default remains
title case). Includes unit test.
9d23445
@samatjain

Re-did both commits w/ your suggestions. Let me know if you've further suggestions.

@zachleat zachleat merged commit 2babe8b into zachleat:master Dec 21, 2011
@zachleat
Owner

Looks great, thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.