Created
June 10, 2015 12:38
-
-
Save cakuki/d58ec01964821a6367fd to your computer and use it in GitHub Desktop.
Angular.js ObjectId to Date filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Extracts creation timestamp from ObjectId. | |
* | |
* Usage for default id mongoose objects in html: | |
* {{ object._id | idToDate | date:'medium' }} | |
*/ | |
angular.module('idToDate').filter('idToDate', [function() { | |
return function idToDate (objectId) { | |
return new Date(parseInt(objectId.slice(0, 8), 16) * 1000); | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment