Last active
September 26, 2017 15:26
-
-
Save peizguo/30dd1d6bc99afca9f7c62f8e954667d3 to your computer and use it in GitHub Desktop.
Revisions
-
Peizong Guo revised this gist
Sep 26, 2017 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -42,6 +42,9 @@ weeks: function() { return this * (7).days(); }, months: function() { return this * (30).days(); }, years: function() { return this * (365).days(); }, @@ -59,6 +62,7 @@ ['hour', 'hours'], ['day', 'days'], ['week', 'weeks'], ['month', 'months'], ['year', 'years'] ]); -
Peizong Guo created this gist
Sep 25, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,65 @@ (function(global) { "use strict"; let log = global.console && global.console.log || function(){}; function extend(target, source) { for(var prop in source) { if(source.hasOwnProperty(prop)) { if(typeof(target[prop]) !== "undefined") { target["_origin_" + prop] = target[prop]; log("Renamed target." + prop); } target[prop] = source[prop]; log("Assigned target." + prop + " from source." + prop); } } } function alias(target, methods) { methods.forEach(function(pair) { let existing = pair[1], newName = pair[0]; if(typeof(target[existing]) !== 'undefined') { target[newName] = target[existing]; } }); } extend(Number.prototype, { seconds: function() { return this * 1000; }, minutes: function() { return this * (60).seconds(); }, hours: function() { return this * (60).minutes(); }, days: function() { return this * (24).hours(); }, weeks: function() { return this * (7).days(); }, years: function() { return this * (365).days(); }, ago: function() { return new Date(new Date() - this); }, fromNow: function() { return new Date(new Date() + this); } }); alias(Number.prototype, [ ['second', 'seconds'], ['minute', 'minutes'], ['hour', 'hours'], ['day', 'days'], ['week', 'weeks'], ['year', 'years'] ]); })(this);