Comparing version 0.9.2 to 0.9.3
{ | ||
"name": "easy-date", | ||
"main": "easy-date.js", | ||
"version": "0.9.2", | ||
"version": "0.9.3", | ||
"homepage": "https://github.com/melvinsembrano/easy-date", | ||
@@ -6,0 +6,0 @@ "authors": [ |
@@ -0,1 +1,9 @@ | ||
/* | ||
* EasyDate | ||
* is a Javascript extension for easy dates manipulations which is heavily inspired by Rails ActiveSupport::Duration class. | ||
* Copyright (c) 2015 Melvin Sembrano (melvinsembrano@gmail.com) | ||
* License: MIT | ||
*/ | ||
(function() { | ||
@@ -61,2 +69,6 @@ var EasyDate, days, hours, months, years; | ||
EasyDate.prototype.before = function(date) { | ||
return this.until(date); | ||
}; | ||
EasyDate.prototype._daysFromNow = function() { | ||
@@ -150,2 +162,14 @@ var now; | ||
Date.today = function() { | ||
return new this(); | ||
}; | ||
Date.yesterday = function() { | ||
return 1..day().ago(); | ||
}; | ||
Date.tommorrow = function() { | ||
return 1..day().fromNow(); | ||
}; | ||
}).call(this); |
/*! | ||
easy-date 0.9.2 | ||
easy-date 0.9.3 | ||
Description: EasyDate is a Javascript extension for easy dates manipulations which is heavily inspired by Rails ActiveSupport::Duration class. | ||
Author: Melvin Sembrano <melvinsembrano@gmail.com> (https://github.com/melvinsembrano/easy-date) | ||
*/ | ||
(function(){var a,b,c,d,e;a=function(a,b){var c;c={0:"day",1:"week",2:"month",3:"year",4:"hour"},this.value=parseInt(a),this.type=c[b]},a.prototype.toString=function(){return this.value+" "+this.type+(this.value>1?"s":"")},a.prototype.fromNow=function(){switch(this.type){case"day":return this._daysFromNow();case"month":return this._monthsFromNow();case"year":return this._yearsFromNow();case"hour":return this._hoursFromNow();default:return console.warn("EasyDate: "+this.type+"().fromNow() not yet implemented.")}},a.prototype.ago=function(){switch(this.type){case"day":return this._daysAgo();case"month":return this._monthsAgo();case"year":return this._yearsAgo();case"hour":return this._hoursAgo();default:return console.warn("EasyDate: "+this.type+"().ago() not yet implemented.")}},a.prototype.since=function(a){return this.now=new Date(a.valueOf()),this.fromNow()},a.prototype.until=function(a){return this.now=new Date(a.valueOf()),this.ago()},a.prototype._daysFromNow=function(){var a;return a=this.now||new Date,a.setDate(a.getDate()+this.value),a},a.prototype._daysAgo=function(){var a;return a=this.now||new Date,a.setDate(a.getDate()-this.value),a},a.prototype._monthsFromNow=function(){var a;return a=this.now||new Date,a.setMonth(a.getMonth()+this.value),a},a.prototype._monthsAgo=function(){var a;return a=this.now||new Date,a.setMonth(a.getMonth()-this.value),a},a.prototype._yearsFromNow=function(){var a;return a=this.now||new Date,a.setFullYear(a.getFullYear()+this.value),a},a.prototype._yearsAgo=function(){var a;return a=this.now||new Date,a.setFullYear(a.getFullYear()-this.value),a},a.prototype._hoursFromNow=function(){var a;return a=this.now||new Date,a.setHours(a.getHours()+this.value),a},a.prototype._hoursAgo=function(){var a;return a=this.now||new Date,a.setHours(a.getHours()-this.value),a},b=function(){return new a(this,0)},d=function(){return new a(this,2)},e=function(){return new a(this,3)},c=function(){return new a(this,4)},Number.prototype.day=b,Number.prototype.days=b,Number.prototype.month=d,Number.prototype.months=d,Number.prototype.years=e,Number.prototype.year=e,Number.prototype.hours=c,Number.prototype.hour=c}).call(this); | ||
(function(){var a,b,c,d,e;a=function(a,b){var c;c={0:"day",1:"week",2:"month",3:"year",4:"hour"},this.value=parseInt(a),this.type=c[b]},a.prototype.toString=function(){return this.value+" "+this.type+(this.value>1?"s":"")},a.prototype.fromNow=function(){switch(this.type){case"day":return this._daysFromNow();case"month":return this._monthsFromNow();case"year":return this._yearsFromNow();case"hour":return this._hoursFromNow();default:return console.warn("EasyDate: "+this.type+"().fromNow() not yet implemented.")}},a.prototype.ago=function(){switch(this.type){case"day":return this._daysAgo();case"month":return this._monthsAgo();case"year":return this._yearsAgo();case"hour":return this._hoursAgo();default:return console.warn("EasyDate: "+this.type+"().ago() not yet implemented.")}},a.prototype.since=function(a){return this.now=new Date(a.valueOf()),this.fromNow()},a.prototype.until=function(a){return this.now=new Date(a.valueOf()),this.ago()},a.prototype.before=function(a){return this.until(a)},a.prototype._daysFromNow=function(){var a;return a=this.now||new Date,a.setDate(a.getDate()+this.value),a},a.prototype._daysAgo=function(){var a;return a=this.now||new Date,a.setDate(a.getDate()-this.value),a},a.prototype._monthsFromNow=function(){var a;return a=this.now||new Date,a.setMonth(a.getMonth()+this.value),a},a.prototype._monthsAgo=function(){var a;return a=this.now||new Date,a.setMonth(a.getMonth()-this.value),a},a.prototype._yearsFromNow=function(){var a;return a=this.now||new Date,a.setFullYear(a.getFullYear()+this.value),a},a.prototype._yearsAgo=function(){var a;return a=this.now||new Date,a.setFullYear(a.getFullYear()-this.value),a},a.prototype._hoursFromNow=function(){var a;return a=this.now||new Date,a.setHours(a.getHours()+this.value),a},a.prototype._hoursAgo=function(){var a;return a=this.now||new Date,a.setHours(a.getHours()-this.value),a},b=function(){return new a(this,0)},d=function(){return new a(this,2)},e=function(){return new a(this,3)},c=function(){return new a(this,4)},Number.prototype.day=b,Number.prototype.days=b,Number.prototype.month=d,Number.prototype.months=d,Number.prototype.years=e,Number.prototype.year=e,Number.prototype.hours=c,Number.prototype.hour=c,Date.today=function(){return new this},Date.yesterday=function(){return 1..day().ago()},Date.tommorrow=function(){return 1..day().fromNow()}}).call(this); |
@@ -5,3 +5,3 @@ { | ||
"description": "EasyDate is a Javascript extension for easy dates manipulations which is heavily inspired by Rails ActiveSupport::Duration class.", | ||
"version": "0.9.2", | ||
"version": "0.9.3", | ||
"keywords": [ | ||
@@ -8,0 +8,0 @@ "EasyDate", |
[![Build Status](https://travis-ci.org/melvinsembrano/easy-date.svg?branch=master)](https://travis-ci.org/melvinsembrano/easy-date) | ||
# EasyDate | ||
EasyDate is a Javascript extension for easy dates manipulations which is | ||
EasyDate is a Javascript extension for easy dates manipulations which was | ||
heavily inspired by Rails ActiveSupport::Duration class. | ||
### Installation | ||
**Node.js** `npm install easy-date --save-dev` | ||
**Node.js** `npm install easy-date` | ||
@@ -31,3 +31,3 @@ **Bower** `bower install easy-date` | ||
var date1 = 3..days().fromNow(); | ||
var date2 = 10..months().ago(); | ||
var date2 = (10).months().ago(); | ||
@@ -37,3 +37,3 @@ var yesterday = 1..day().ago(); | ||
var num = 5; | ||
num.years().until(today); //==> is equal to 5..years().ago() | ||
num.years().before(today); //==> is equal to 5..years().ago() | ||
num.years().since(today); //==> is equal to 5..years().fromNow() | ||
@@ -43,3 +43,11 @@ | ||
it will also add some basic date helpers | ||
``` | ||
Date.today() //=> new Date() | ||
Date.yesterday() //=> 1..day().ago() | ||
Date.tommorrow() //=> 1..day().fromNow() | ||
``` | ||
#### Contributing to easy-date | ||
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet. | ||
@@ -52,4 +60,5 @@ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it. | ||
* Please try not to mess with the Gruntfile, package.json, travis.yml, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it. | ||
* Checkout Gruntfile.coffee, there are few grunt tasks that are very helpful during development. | ||
##### Copyright | ||
Copyright (c) 2015 Melvin Sembrano. See [LICENSE](LICENSE) for further details |
@@ -98,2 +98,7 @@ describe('EasyDate', function() { | ||
it('#before', function() { | ||
var now = new Date(2015, 3, 10); | ||
var newDate = now.getDate() - 3; | ||
expect(3..days().before(now).getDate()).toBe(newDate); | ||
}); | ||
}); | ||
@@ -133,2 +138,7 @@ | ||
}); | ||
it('#before', function() { | ||
var now = new Date(2015, 9, 10); | ||
expect(3..months().before(now).getMonth()).toBe(6); | ||
}); | ||
}); | ||
@@ -167,2 +177,7 @@ | ||
}); | ||
it('#before', function() { | ||
var now = new Date(2015, 9, 10); | ||
expect(3..years().before(now).getFullYear()).toBe(2012); | ||
}); | ||
}); | ||
@@ -203,4 +218,9 @@ | ||
}); | ||
it('#before', function() { | ||
var now = new Date(2015, 9, 10, 12); | ||
expect(3..hours().before(now).getHours()).toBe(9); | ||
}); | ||
}); | ||
}); | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26410
16
416
61