]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Updating to version 0.3.1 0.3.1
authorTim Wood <washwithcare@gmail.com>
Fri, 25 Mar 2011 16:04:09 +0000 (09:04 -0700)
committerTim Wood <washwithcare@gmail.com>
Fri, 25 Mar 2011 16:04:09 +0000 (09:04 -0700)
Updating readme and minified version

README.markdown
lib/underscore.date.js
lib/underscore.date.min.js

index ffa45dac07e9534227f53ddbc6042e4d46bee9c1..96bc726d7aa51c91eb759188f78bf3f39f45d2ec 100644 (file)
@@ -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
+<table>
+    <tr>
+        <th>minified</th>
+        <th>gzipped</th>
+    </tr>
+    <tr>
+       <td>3.73k</td>
+       <td>1.6k</td>
+    </tr>
+</table>
 
 _.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
 
index a45908627c319d4191deafd19c8ea8b2dc675f08..a4b8bb6037482a408c3a51f61ddce6e99605fb1b 100644 (file)
@@ -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 */
 
index 929566dd8691e6fc0b54bc69223ccd3a00736d2d..0bfd1e4cd577bf0deedb28d335c6c889313a6fe0 100644 (file)
@@ -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.length<b)c="0"+c;return c}var d=this,e,f=["January","February","March","April","May","June","July","August","September","October","November","December"],g=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],h=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],i=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],j={future:"in %s",past:"%s ago",s:"less than a minute",m:"about a minute",mm:"%d minutes",h:"about an hour",hh:"about %d hours",d:"a day",dd:"%d days",M:"about a month",MM:"%d months",y:"about a year",yy:"%d years"},k=function(a){var b=a%10;return(a%100/10|0)===1?"th":b===1?"st":b===2?"nd":b===3?"rd":"th"};e={addTime:function(a,b){return m(b,p(a),1)},customizeDate: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)},date:function(a){return p(a)},formatDate:function(b,c){function t(b){var c,d;switch(b){case"M":return e+1;case"Mo":return e+1+k(e+1);case"MM":return l(e+1,2);case"MMM":return g[e];case"MMMM":return f[e];case"D":return j;case"Do":return j+k(j);case"DD":return l(j,2);case"DDD":c=new a(m,e,j),d=new a(m,0,1);return(c-d)/864e5+1.5|0;case"DDDo":c=t("DDD");return c+k(c);case"DDDD":return l(t("DDD"),3);case"d":return n;case"do":return n+k(n);case"ddd":return i[n];case"dddd":return h[n];case"w":c=new a(m,e,j-n+5),d=new a(c.getFullYear(),0,4);return(c-d)/864e5/7+1.5|0;case"wo":c=t("w");return c+k(c);case"ww":return l(t("w"),2);case"YY":return(m+"").slice(-2);case"YYYY":return m;case"a":return o>11?"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.length<b)c="0"+c;return c}var d=this,e,f=["January","February","March","April","May","June","July","August","September","October","November","December"],g=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],h=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],i=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],j={future:"in %s",past:"%s ago",s:"less than a minute",m:"about a minute",mm:"%d minutes",h:"about an hour",hh:"about %d hours",d:"a day",dd:"%d days",M:"about a month",MM:"%d months",y:"about a year",yy:"%d years"},k=function(a){var b=a%10;return(a%100/10|0)===1?"th":b===1?"st":b===2?"nd":b===3?"rd":"th"};r.prototype.format=function(b){function r(b){var c,q;switch(b){case"M":return d+1;case"Mo":return d+1+k(d+1);case"MM":return l(d+1,2);case"MMM":return g[d];case"MMMM":return f[d];case"D":return e;case"Do":return e+k(e);case"DD":return l(e,2);case"DDD":c=new a(j,d,e),q=new a(j,0,1);return(c-q)/864e5+1.5|0;case"DDDo":c=r("DDD");return c+k(c);case"DDDD":return l(r("DDD"),3);case"d":return m;case"do":return m+k(m);case"ddd":return i[m];case"dddd":return h[m];case"w":c=new a(j,d,e-m+5),q=new a(c.getFullYear(),0,4);return(c-q)/864e5/7+1.5|0;case"wo":c=r("w");return c+k(c);case"ww":return l(r("w"),2);case"YY":return(j+"").slice(-2);case"YYYY":return j;case"a":return n>11?"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,_)