From: Tim Wood Date: Fri, 25 Mar 2011 16:04:09 +0000 (-0700) Subject: Updating to version 0.3.1 X-Git-Tag: 0.3.1^0 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b7b9bc2662cafcaeac987073b39de940bf2ead4c;p=thirdparty%2Fmoment.git Updating to version 0.3.1 Updating readme and minified version --- diff --git a/README.markdown b/README.markdown index ffa45dac0..96bc726d7 100644 --- a/README.markdown +++ b/README.markdown @@ -12,32 +12,38 @@ In addition to the date creation and manipulation functions, there are a few fun _.date(new Date(2010, 1, 14, 15, 25, 50, 125)).format("dddd, MMMM Do YYYY, h:mm:ss a"); // "Sunday, February 14th 2010, 3:25:50 pm" _.date(new Date(2010, 1, 14, 15, 25, 50, 125)).fromNow(); // "20 days ago" -#### Filesize - -minified 3.73k - -gzipped 1.6k +### Filesize + + + + + + + + + +
minifiedgzipped
3.73k1.6k
_.date() ======== -The library works by creating a date wrapper object using _.date(). +The library works by creating a `_Date` date wrapper object using _.date(). To create that wrapper, you can pass any of the following data types in. -Date ----- -`new Date(2010, 1, 14, 15, 25, 50, 125)` +### Date + + _.date(new Date(2010, 1, 14, 15, 25, 50, 125)) Any valid `Date` object. For more information on `Date` objects, see [the JavaScript Date documentation at MDN](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date) -Array ------- -`[2010, 1, 14, 15, 25, 50, 125]` +### Array + + _.date([2010, 1, 14, 15, 25, 50, 125]) The array should mirror the parameters passed into [Date.UTC()](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/UTC). @@ -47,43 +53,47 @@ Any value past the year is optional, and will default to the lowest possible num -String ------- -`"Dec 25, 1995"` +### String + + _.date("Dec 25, 1995") A string that can be parsed by [Date.parse()](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/parse). -Number ------- -`1300291340510` +### Number + + _.date(1300291340510) An integer value representing the number of milliseconds since 1 January 1970 00:00:00 UTC. -undefined ---------- -`undefined` +### undefined + + _.date() If no value is passed to a 'dateInput' parameter, it will default to the current time using `new Date()`. - _.date() === new Date() + _.date() === _.date(new Date()) -_.now(asTimestamp) -================== +_.now() +======= + + _.now(asTimestamp) Returns the current date. -Pass `true` to return a UNIX timestamp, otherwise it will return an `_.date()` object. +Pass `true` to return a UNIX timestamp, otherwise it is just a shortcut to `_.date(new Date())`. -_.isLeapYear(number) -==================== +_.isLeapYear() +============== + + _.isLeapYear(number) Returns `true` if the year is a leap year, `false` if it is not @@ -97,13 +107,15 @@ Examples : -_.date() Functions -================== +_Date Functions +=============== + +_Date.add() +----------- -_.date().add(object) --------------------- + _.date().add(object) Adds time per the object passed in. @@ -135,8 +147,10 @@ Example: -_.date().subtract(object) -------------------------- +_Date.subtract() +---------------- + + _.date().subtract(object) Functions the same as `_.date().add()`, only using subtraction instead of addition. @@ -147,8 +161,10 @@ Example: -_.date().format(string) ------------------------ +_Date.format() +-------------- + + _Date.format(string) Returns a human readable string based on the format string that was passed in. @@ -317,8 +333,10 @@ The formats are created by creating a string of replacable characters. -_.date().from(date, withoutSuffix:boolean, asMilliseconds:boolean) ------------------------------------------------------------------- +_Date.from() +------------ + + _Date.from(date, withoutSuffix:boolean, asMilliseconds:boolean) Returns a string as relative time ('minutes ago', '5 months ago', etc). @@ -341,14 +359,16 @@ The base strings for this function can be customized with `_.date().customize()` -_.date().fromNow(withoutSuffix:boolean, asMilliseconds:boolean) ---------------------------------------------------------------- +_Date.fromNow() +--------------- + + _Date.fromNow(withoutSuffix:boolean, asMilliseconds:boolean) -A shortcut for _.date().from(_.now(), withoutSuffix:boolean, asMilliseconds:boolean) +A shortcut for `_.date().from(_.now(), withoutSuffix:boolean, asMilliseconds:boolean)` -_.date().isLeapYear() ---------------------- +_Date.isLeapYear() +------------------ Returns `true` if the year is a leap year, `false` if it is not diff --git a/lib/underscore.date.js b/lib/underscore.date.js index a45908627..a4b8bb603 100644 --- a/lib/underscore.date.js +++ b/lib/underscore.date.js @@ -3,7 +3,7 @@ // (c) 2011 Tim Wood // Underscore.date is freely distributable under the terms of the MIT license. // -// Version 0.3.0 +// Version 0.3.1 /*global _:false */ diff --git a/lib/underscore.date.min.js b/lib/underscore.date.min.js index 929566dd8..0bfd1e4cd 100644 --- a/lib/underscore.date.min.js +++ b/lib/underscore.date.min.js @@ -3,6 +3,6 @@ // (c) 2011 Tim Wood // Underscore.date is freely distributable under the terms of the MIT license. // -// Version 0.3.0 +// Version 0.3.1 -(function(a,b,c){function q(a,b){return j[a].replace(/%d/i,b||1)}function p(d){return d===c?e.now():b.isDate(d)?d:b.isArray(d)&&d.length>2?n(d):new a(d)}function o(d){return d===c?e.now(!0):isNaN(d)?b.isDate(d)?d.getTime():b.isArray(d)&&d.length>2?n(d).getTime():(new a(d)).getTime():d}function n(b){return new a(b[0],b[1]||0,b[2]||1,b[3]||0,b[4]||0,b[5]||0,b[6]||0)}function m(b,c,d){var e=(b.ms||b[6]||0)+(b.s||b[5]||0)*1e3+(b.m||b[4]||0)*6e4+(b.h||b[3]||0)*36e5+(b.d||b[2]||0)*864e5+(b.w||0)*6048e5,f=(b.M||b[1]||0)+(b.y||b[0]||0)*12,g;e&&c.setMilliseconds(c.getMilliseconds()+e*d),f&&(g=c.getDate(),c.setDate(1),c.setMonth(c.getMonth()+f*d),c.setDate(Math.min((new a(c.getFullYear(),c.getMonth()+1,0)).getDate(),g)));return c}function l(a,b){var c=a+"";while(c.length11?"pm":"am";case"A":return o>11?"PM":"AM";case"H":return o;case"HH":return l(o,2);case"h":return o%12||12;case"hh":return l(o%12||12,2);case"m":return q;case"mm":return l(q,2);case"s":return r;case"ss":return l(r,2);default:return b.replace("\\","")}}var d=p(b),e=d.getMonth(),j=d.getDate(),m=d.getFullYear(),n=d.getDay(),o=d.getHours(),q=d.getMinutes(),r=d.getSeconds(),s=/(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|dddd?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?)/g;return c.replace(s,t)},fromNow:function(a,b){var c=e.msApart(a,b),d=c<0?j.past:j.future;return d.replace(/%s/i,e.relativeTime(c))},isLeapYear:function(a){var b=!isNaN(a)&&a<1e4?a:p(a).getFullYear();return b%4===0&&b%100!==0||b%400===0},msApart:function(a,b){return o(a)-o(b)},now:function(b){return b?(new a).getTime():new a},relativeTime:function(a){var b=Math.abs(o(a))/1e3,c=b/60,d=c/60,e=d/24,f=e/365;return b<45&&q("s",b|0)||b<90&&q("m")||c<45&&q("mm",c|0)||c<90&&q("h")||d<24&&q("hh",d|0)||d<48&&q("d")||e<30&&q("dd",e|0)||e<60&&q("M")||e<350&&q("MM",e/30|0)||f<2&&q("y")||q("yy",f|0)},subtractTime:function(a,b){return m(b,p(a),-1)}},b&&b.mixin&&b.mixin(e)})(Date,_) +(function(a,b,c){function t(a){var b=Math.abs(a)/1e3,c=b/60,d=c/60,e=d/24,f=e/365;return b<45&&q("s",b|0)||b<90&&q("m")||c<45&&q("mm",c|0)||c<90&&q("h")||d<24&&q("hh",d|0)||d<48&&q("d")||e<25&&q("dd",e|0)||e<45&&q("M")||e<350&&q("MM",(e+15)/30|0)||f<2&&q("y")||q("yy",f|0)}function s(a,b){return o(a)-o(b)}function r(a){this.date=p(a);return this}function q(a,b){return j[a].replace(/%d/i,b||1)}function p(d){return d===c?new a:d instanceof r?d.date:b.isDate(d)?d:b.isArray(d)&&d.length>2?n(d):new a(d)}function o(d){return d===c?(new a).getTime():isNaN(d)?d instanceof r?d.date.getTime():b.isDate(d)?d.getTime():b.isArray(d)&&d.length>2?n(d).getTime():(new a(d)).getTime():d}function n(b){return new a(b[0],b[1]||0,b[2]||1,b[3]||0,b[4]||0,b[5]||0,b[6]||0)}function m(b,c,d){var e=b.date,f=(c.ms||0)+(c.s||0)*1e3+(c.m||0)*6e4+(c.h||0)*36e5+(c.d||0)*864e5+(c.w||0)*6048e5,g=(c.M||0)+(c.y||0)*12,h;f&&e.setMilliseconds(e.getMilliseconds()+f*d),g&&(h=e.getDate(),e.setDate(1),e.setMonth(e.getMonth()+g*d),e.setDate(Math.min((new a(e.getFullYear(),e.getMonth()+1,0)).getDate(),h)));return b}function l(a,b){var c=a+"";while(c.length11?"pm":"am";case"A":return n>11?"PM":"AM";case"H":return n;case"HH":return l(n,2);case"h":return n%12||12;case"hh":return l(n%12||12,2);case"m":return o;case"mm":return l(o,2);case"s":return p;case"ss":return l(p,2);default:return b.replace("\\","")}}var c=this.date,d=c.getMonth(),e=c.getDate(),j=c.getFullYear(),m=c.getDay(),n=c.getHours(),o=c.getMinutes(),p=c.getSeconds(),q=/(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|dddd?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?)/g;return b.replace(q,r)},r.prototype.add=function(a){return m(this,a,1)},r.prototype.subtract=function(a){return m(this,a,-1)},r.prototype.customize=function(a){var c=a.weekdays,d=a.weekdaysShort,e=a.months,l=a.monthsShort,m=a.relativeTime,n=a.ordinal;c&&b.isArray(c)&&c.length===7&&(h=c),d&&b.isArray(d)&&d.length===7&&(i=d),e&&b.isArray(e)&&e.length===12&&(f=e),l&&b.isArray(l)&&l.length===12&&(g=l),m&&b.extend(j,m),n&&b.isFunction(n)&&(k=n)},r.prototype.from=function(a,b,c){var d=s(this.date,a),e=d<0?j.past:j.future;return c?d:b?t(d):e.replace(/%s/i,t(d))},r.prototype.fromNow=function(a,c){return this.from(b.now(),a,c)},r.prototype.isLeapYear=function(){return b.isLeapYear(this.date.getFullYear())},e={date:function(a){return new r(a)},now:function(b){return b?(new a).getTime():e.date()},isLeapYear:function(a){return a%4===0&&a%100!==0||a%400===0}},b&&b.mixin&&b.mixin(e)})(Date,_)