Commits

David Chambers committed a4dac96

accept Unix timestamps in place of Date objects

Comments (0)

Files changed (4)

 
 ### `$.localize(date, format)`
 
-Return `date` in the specified `format`.
+Return `date` in the specified `format`. For convenience, `date` may be a Unix
+timestamp rather than a `Date` object.
 
 ### `$.localize(date)`
 
-Return `date` in the format specified by `$.localize.format`.
+Return `date` in the format specified by `$.localize.format`. For convenience,
+`date` may be a Unix timestamp rather than a `Date` object.
 
 ### `$.localize(format)`
 
 
 ## Changelog {@id=changelog}
 
+### 0.8.1
+
+  * `jQuery.localize` may now be passed a Unix timestamp in place of a `Date`
+    object.
+
 ### 0.8.0
 
   * Translated source to CoffeeScript, considerably improving its readability.

jquery.localize.coffee

           "#{if offset < 0 then '-' else '+'}#{pad m / 60 >> 0}:#{pad m % 60}"
 
 $localize = (date, format) ->
+  if typeof date is 'number'
+    date = new Date date
   unless date instanceof Date
     format = date
     date = new Date

jquery.localize.js

 
   $localize = function(date, format) {
     var chr, dir, out, prev, _i, _len, _ref;
+    if (typeof date === 'number') {
+      date = new Date(date);
+    }
     if (!(date instanceof Date)) {
       format = date;
       date = new Date;
 
   // $.localize(date, format)
   assert.equal($.localize(new Date('26 April 1984'), 'yy'), '84');
+  assert.equal($.localize(+new Date('26 April 1984'), 'yy'), '84');
 
   // $.localize(date)
   $.localize.format = 'yyyy-mm-dd';
   assert.equal($.localize(new Date('26 April 1984')), '1984-04-26');
+  assert.equal($.localize(+new Date('26 April 1984')), '1984-04-26');
 
   // $.localize(format)
   assert.match($.localize('d/m/yyyy'), /^[123]?\d\/1?\d\/20\d\d$/);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.