Comparing version 0.9.3 to 0.9.5
{ | ||
"name": "easy-date", | ||
"main": "easy-date.js", | ||
"version": "0.9.3", | ||
"version": "0.9.5", | ||
"homepage": "https://github.com/melvinsembrano/easy-date", | ||
@@ -14,3 +14,6 @@ "authors": [ | ||
"Date", | ||
"Javascript Date" | ||
"Javascript Date", | ||
"format", | ||
"date format", | ||
"javascript date format" | ||
], | ||
@@ -17,0 +20,0 @@ "license": "MIT", |
210
easy-date.js
@@ -10,3 +10,3 @@ | ||
(function() { | ||
var EasyDate, days, hours, months, years; | ||
var EasyDate, days, formatDate, hours, months, years; | ||
@@ -30,12 +30,12 @@ EasyDate = function(value, type) { | ||
EasyDate.prototype.fromNow = function() { | ||
EasyDate.prototype.fromNow = function(mask) { | ||
switch (this.type) { | ||
case "day": | ||
return this._daysFromNow(); | ||
return this._daysFromNow(mask); | ||
case "month": | ||
return this._monthsFromNow(); | ||
return this._monthsFromNow(mask); | ||
case "year": | ||
return this._yearsFromNow(); | ||
return this._yearsFromNow(mask); | ||
case "hour": | ||
return this._hoursFromNow(); | ||
return this._hoursFromNow(mask); | ||
default: | ||
@@ -46,12 +46,12 @@ return console.warn("EasyDate: " + this.type + "().fromNow() not yet implemented."); | ||
EasyDate.prototype.ago = function() { | ||
EasyDate.prototype.ago = function(mask) { | ||
switch (this.type) { | ||
case "day": | ||
return this._daysAgo(); | ||
return this._daysAgo(mask); | ||
case "month": | ||
return this._monthsAgo(); | ||
return this._monthsAgo(mask); | ||
case "year": | ||
return this._yearsAgo(); | ||
return this._yearsAgo(mask); | ||
case "hour": | ||
return this._hoursAgo(); | ||
return this._hoursAgo(mask); | ||
default: | ||
@@ -62,72 +62,80 @@ return console.warn("EasyDate: " + this.type + "().ago() not yet implemented."); | ||
EasyDate.prototype.since = function(date) { | ||
EasyDate.prototype.since = function(date, mask) { | ||
this.now = new Date(date.valueOf()); | ||
return this.fromNow(); | ||
return this.fromNow(mask); | ||
}; | ||
EasyDate.prototype.until = function(date) { | ||
EasyDate.prototype.until = function(date, mask) { | ||
this.now = new Date(date.valueOf()); | ||
return this.ago(); | ||
return this.ago(mask); | ||
}; | ||
EasyDate.prototype.before = function(date) { | ||
return this.until(date); | ||
EasyDate.prototype.before = function(date, mask) { | ||
return this.until(date, mask); | ||
}; | ||
EasyDate.prototype._daysFromNow = function() { | ||
EasyDate.prototype._daysFromNow = function(mask) { | ||
var now; | ||
now = this.now || new Date(); | ||
now.setDate(now.getDate() + this.value); | ||
return now; | ||
return formatDate(now, mask); | ||
}; | ||
EasyDate.prototype._daysAgo = function() { | ||
EasyDate.prototype._daysAgo = function(mask) { | ||
var now; | ||
now = this.now || new Date(); | ||
now.setDate(now.getDate() - this.value); | ||
return now; | ||
return formatDate(now, mask); | ||
}; | ||
EasyDate.prototype._monthsFromNow = function() { | ||
EasyDate.prototype._monthsFromNow = function(mask) { | ||
var now; | ||
now = this.now || new Date(); | ||
now.setMonth(now.getMonth() + this.value); | ||
return now; | ||
return formatDate(now, mask); | ||
}; | ||
EasyDate.prototype._monthsAgo = function() { | ||
EasyDate.prototype._monthsAgo = function(mask) { | ||
var now; | ||
now = this.now || new Date(); | ||
now.setMonth(now.getMonth() - this.value); | ||
return now; | ||
return formatDate(now, mask); | ||
}; | ||
EasyDate.prototype._yearsFromNow = function() { | ||
EasyDate.prototype._yearsFromNow = function(mask) { | ||
var now; | ||
now = this.now || new Date(); | ||
now.setFullYear(now.getFullYear() + this.value); | ||
return now; | ||
return formatDate(now, mask); | ||
}; | ||
EasyDate.prototype._yearsAgo = function() { | ||
EasyDate.prototype._yearsAgo = function(mask) { | ||
var now; | ||
now = this.now || new Date(); | ||
now.setFullYear(now.getFullYear() - this.value); | ||
return now; | ||
return formatDate(now, mask); | ||
}; | ||
EasyDate.prototype._hoursFromNow = function() { | ||
EasyDate.prototype._hoursFromNow = function(mask) { | ||
var now; | ||
now = this.now || new Date(); | ||
now.setHours(now.getHours() + this.value); | ||
return now; | ||
return formatDate(now, mask); | ||
}; | ||
EasyDate.prototype._hoursAgo = function() { | ||
EasyDate.prototype._hoursAgo = function(mask) { | ||
var now; | ||
now = this.now || new Date(); | ||
now.setHours(now.getHours() - this.value); | ||
return now; | ||
return formatDate(now, mask); | ||
}; | ||
formatDate = function(date, mask) { | ||
if (mask === void 0) { | ||
return date; | ||
} else { | ||
return date.format(mask); | ||
} | ||
}; | ||
days = function() { | ||
@@ -165,14 +173,138 @@ return new EasyDate(this, 0); | ||
Date.today = function() { | ||
return new this(); | ||
Date.today = function(mask) { | ||
return formatDate(new this(), mask); | ||
}; | ||
Date.yesterday = function() { | ||
return 1..day().ago(); | ||
Date.yesterday = function(mask) { | ||
return 1..day().ago(mask); | ||
}; | ||
Date.tommorrow = function() { | ||
return 1..day().fromNow(); | ||
Date.tommorrow = function(mask) { | ||
return 1..day().fromNow(mask); | ||
}; | ||
}).call(this); | ||
/* | ||
* Date Format 1.2.3 | ||
* (c) 2007-2009 Steven Levithan <stevenlevithan.com> | ||
* MIT license | ||
# | ||
* Includes enhancements by Scott Trenda <scott.trenda.net> | ||
* and Kris Kowal <cixar.com/~kris.kowal/> | ||
# | ||
* Accepts a date, a mask, or a date and a mask. | ||
* Returns a formatted version of the given date. | ||
* The date defaults to the current date/time. | ||
* The mask defaults to dateFormat.masks.default. | ||
*/ | ||
(function() { | ||
var dateFormat; | ||
dateFormat = (function() { | ||
var pad, timezone, timezoneClip, token; | ||
token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g; | ||
timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g; | ||
timezoneClip = /[^-+\dA-Z]/g; | ||
pad = function(val, len) { | ||
val = String(val); | ||
len = len || 2; | ||
while (val.length < len) { | ||
val = '0' + val; | ||
} | ||
return val; | ||
}; | ||
return function(date, mask, utc) { | ||
var D, H, L, M, _, d, dF, flags, m, o, s, y; | ||
dF = dateFormat; | ||
if (arguments.length === 1 && Object.prototype.toString.call(date) === '[object String]' && !/\d/.test(date)) { | ||
mask = date; | ||
date = void 0; | ||
} | ||
date = date ? new Date(date) : new Date; | ||
if (isNaN(date)) { | ||
throw SyntaxError('invalid date'); | ||
} | ||
mask = String(dF.masks[mask] || mask || dF.masks['default']); | ||
if (mask.slice(0, 4) === 'UTC:') { | ||
mask = mask.slice(4); | ||
utc = true; | ||
} | ||
_ = utc ? 'getUTC' : 'get'; | ||
d = date[_ + 'Date'](); | ||
D = date[_ + 'Day'](); | ||
m = date[_ + 'Month'](); | ||
y = date[_ + 'FullYear'](); | ||
H = date[_ + 'Hours'](); | ||
M = date[_ + 'Minutes'](); | ||
s = date[_ + 'Seconds'](); | ||
L = date[_ + 'Milliseconds'](); | ||
o = utc ? 0 : date.getTimezoneOffset(); | ||
flags = { | ||
d: d, | ||
dd: pad(d), | ||
ddd: dF.i18n.dayNames[D], | ||
dddd: dF.i18n.dayNames[D + 7], | ||
m: m + 1, | ||
mm: pad(m + 1), | ||
mmm: dF.i18n.monthNames[m], | ||
mmmm: dF.i18n.monthNames[m + 12], | ||
yy: String(y).slice(2), | ||
yyyy: y, | ||
h: H % 12 || 12, | ||
hh: pad(H % 12 || 12), | ||
H: H, | ||
HH: pad(H), | ||
M: M, | ||
MM: pad(M), | ||
s: s, | ||
ss: pad(s), | ||
l: pad(L, 3), | ||
L: pad(L > 99 ? Math.round(L / 10) : L), | ||
t: H < 12 ? 'a' : 'p', | ||
tt: H < 12 ? 'am' : 'pm', | ||
T: H < 12 ? 'A' : 'P', | ||
TT: H < 12 ? 'AM' : 'PM', | ||
Z: utc ? 'UTC' : (String(date).match(timezone) || ['']).pop().replace(timezoneClip, ''), | ||
o: (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4), | ||
S: ['th', 'st', 'nd', 'rd'][d % 10 > 3 ? 0 : (d % 100 - (d % 10) !== 10) * d % 10] | ||
}; | ||
return mask.replace(token, function($0) { | ||
if ($0 in flags) { | ||
return flags[$0]; | ||
} else { | ||
return $0.slice(1, $0.length - 1); | ||
} | ||
}); | ||
}; | ||
})(); | ||
dateFormat.masks = { | ||
'default': 'ddd mmm dd yyyy HH:MM:ss', | ||
shortDate: 'm/d/yy', | ||
mediumDate: 'mmm d, yyyy', | ||
longDate: 'mmmm d, yyyy', | ||
fullDate: 'dddd, mmmm d, yyyy', | ||
shortTime: 'h:MM TT', | ||
mediumTime: 'h:MM:ss TT', | ||
longTime: 'h:MM:ss TT Z', | ||
isoDate: 'yyyy-mm-dd', | ||
isoTime: 'HH:MM:ss', | ||
isoDateTime: 'yyyy-mm-dd\'T\'HH:MM:ss', | ||
isoUtcDateTime: 'UTC:yyyy-mm-dd\'T\'HH:MM:ss\'Z\'' | ||
}; | ||
dateFormat.i18n = { | ||
dayNames: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], | ||
monthNames: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] | ||
}; | ||
if (Date.prototype.format === void 0) { | ||
Date.prototype.format = function(mask, utc) { | ||
return dateFormat(this, mask, utc); | ||
}; | ||
} | ||
}).call(this); |
/*! | ||
easy-date 0.9.3 | ||
easy-date 0.9.5 | ||
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.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); | ||
(function(){var a,b,c,d,e,f;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(a){switch(this.type){case"day":return this._daysFromNow(a);case"month":return this._monthsFromNow(a);case"year":return this._yearsFromNow(a);case"hour":return this._hoursFromNow(a);default:return console.warn("EasyDate: "+this.type+"().fromNow() not yet implemented.")}},a.prototype.ago=function(a){switch(this.type){case"day":return this._daysAgo(a);case"month":return this._monthsAgo(a);case"year":return this._yearsAgo(a);case"hour":return this._hoursAgo(a);default:return console.warn("EasyDate: "+this.type+"().ago() not yet implemented.")}},a.prototype.since=function(a,b){return this.now=new Date(a.valueOf()),this.fromNow(b)},a.prototype.until=function(a,b){return this.now=new Date(a.valueOf()),this.ago(b)},a.prototype.before=function(a,b){return this.until(a,b)},a.prototype._daysFromNow=function(a){var b;return b=this.now||new Date,b.setDate(b.getDate()+this.value),c(b,a)},a.prototype._daysAgo=function(a){var b;return b=this.now||new Date,b.setDate(b.getDate()-this.value),c(b,a)},a.prototype._monthsFromNow=function(a){var b;return b=this.now||new Date,b.setMonth(b.getMonth()+this.value),c(b,a)},a.prototype._monthsAgo=function(a){var b;return b=this.now||new Date,b.setMonth(b.getMonth()-this.value),c(b,a)},a.prototype._yearsFromNow=function(a){var b;return b=this.now||new Date,b.setFullYear(b.getFullYear()+this.value),c(b,a)},a.prototype._yearsAgo=function(a){var b;return b=this.now||new Date,b.setFullYear(b.getFullYear()-this.value),c(b,a)},a.prototype._hoursFromNow=function(a){var b;return b=this.now||new Date,b.setHours(b.getHours()+this.value),c(b,a)},a.prototype._hoursAgo=function(a){var b;return b=this.now||new Date,b.setHours(b.getHours()-this.value),c(b,a)},c=function(a,b){return void 0===b?a:a.format(b)},b=function(){return new a(this,0)},e=function(){return new a(this,2)},f=function(){return new a(this,3)},d=function(){return new a(this,4)},Number.prototype.day=b,Number.prototype.days=b,Number.prototype.month=e,Number.prototype.months=e,Number.prototype.years=f,Number.prototype.year=f,Number.prototype.hours=d,Number.prototype.hour=d,Date.today=function(a){return c(new this,a)},Date.yesterday=function(a){return 1..day().ago(a)},Date.tommorrow=function(a){return 1..day().fromNow(a)}}).call(this),function(){var a;a=function(){var b,c,d,e;return e=/d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,c=/\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,d=/[^-+\dA-Z]/g,b=function(a,b){for(a=String(a),b=b||2;a.length<b;)a="0"+a;return a},function(f,g,h){var i,j,k,l,m,n,o,p,q,r,s,t;if(o=a,1!==arguments.length||"[object String]"!==Object.prototype.toString.call(f)||/\d/.test(f)||(g=f,f=void 0),f=f?new Date(f):new Date,isNaN(f))throw SyntaxError("invalid date");return g=String(o.masks[g]||g||o.masks["default"]),"UTC:"===g.slice(0,4)&&(g=g.slice(4),h=!0),m=h?"getUTC":"get",n=f[m+"Date"](),i=f[m+"Day"](),q=f[m+"Month"](),t=f[m+"FullYear"](),j=f[m+"Hours"](),l=f[m+"Minutes"](),s=f[m+"Seconds"](),k=f[m+"Milliseconds"](),r=h?0:f.getTimezoneOffset(),p={d:n,dd:b(n),ddd:o.i18n.dayNames[i],dddd:o.i18n.dayNames[i+7],m:q+1,mm:b(q+1),mmm:o.i18n.monthNames[q],mmmm:o.i18n.monthNames[q+12],yy:String(t).slice(2),yyyy:t,h:j%12||12,hh:b(j%12||12),H:j,HH:b(j),M:l,MM:b(l),s:s,ss:b(s),l:b(k,3),L:b(k>99?Math.round(k/10):k),t:12>j?"a":"p",tt:12>j?"am":"pm",T:12>j?"A":"P",TT:12>j?"AM":"PM",Z:h?"UTC":(String(f).match(c)||[""]).pop().replace(d,""),o:(r>0?"-":"+")+b(100*Math.floor(Math.abs(r)/60)+Math.abs(r)%60,4),S:["th","st","nd","rd"][n%10>3?0:(n%100-n%10!==10)*n%10]},g.replace(e,function(a){return a in p?p[a]:a.slice(1,a.length-1)})}}(),a.masks={"default":"ddd mmm dd yyyy HH:MM:ss",shortDate:"m/d/yy",mediumDate:"mmm d, yyyy",longDate:"mmmm d, yyyy",fullDate:"dddd, mmmm d, yyyy",shortTime:"h:MM TT",mediumTime:"h:MM:ss TT",longTime:"h:MM:ss TT Z",isoDate:"yyyy-mm-dd",isoTime:"HH:MM:ss",isoDateTime:"yyyy-mm-dd'T'HH:MM:ss",isoUtcDateTime:"UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"},a.i18n={dayNames:["Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],monthNames:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","January","February","March","April","May","June","July","August","September","October","November","December"]},void 0===Date.prototype.format&&(Date.prototype.format=function(b,c){return a(this,b,c)})}.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.3", | ||
"version": "0.9.5", | ||
"keywords": [ | ||
@@ -13,3 +13,6 @@ "EasyDate", | ||
"Rails like javascript date", | ||
"ruby date" | ||
"ruby date", | ||
"Format", | ||
"Javascript date format", | ||
"date format" | ||
], | ||
@@ -16,0 +19,0 @@ "repository": { |
@@ -48,2 +48,18 @@ [![Build Status](https://travis-ci.org/melvinsembrano/easy-date.svg?branch=master)](https://travis-ci.org/melvinsembrano/easy-date) | ||
#### Formatting | ||
The date.format library written by Steven Levithan (http://blog.stevenlevithan.com/archives/date-time-format) is now integrated for a very nice date formatting. | ||
``` | ||
5..days().fromNow().format("d mmmm yyyy"); | ||
// is same as | ||
5..days().fromNow("d mmmm yyyy"); | ||
// other functions | ||
Date.today("yyyy-mm-dd"); | ||
Date.yesterday("dddd"); | ||
3..days().since(Date.yesterday(), "mmm dd, yyyy"); | ||
``` | ||
[Check the complete formatting here](FORMATTING.md) | ||
#### Contributing to easy-date | ||
@@ -50,0 +66,0 @@ |
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
50405
21
740
77