Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Adding moment.fn.isValid #306

Merged
merged 7 commits into from

3 participants

@timrwood
Owner

Not ready to be pulled in yet, just wanted to open the discussion.

timrwood added some commits
@timrwood timrwood First pass at isValid 776103b
@timrwood timrwood More work on isValid
I moved all calls to Date.utc.apply({}, array) into makeDateFromArray.
I also noticed a bug where moment([2010, 0, 0]) would be converted to
moment([2010, 0, 1]) and had to fix a bunch of unit tests that were
dependent on this bug.
7fcf274
@timrwood timrwood Adding logic for handling whether the array was created with new Date…
…() or Date.utc()
4b65aa3
@timrwood
Owner

Right now, ISO8601, array, and string from format(s) all run through the internal function dateFromArray(input, asUTC). See the function here

The way I intend to check date validity is by comparing the input array to an array constructed from the date getters. I might as well expose the method on the prototype as moment.fn.toArray.

If the string was just parsed as a string like in Date.parse(), it should also fail on the line with return !isNaN(this._d.getTime());

@rockymeza and @nailor what do you guys think about this? I need to add some more unit tests before pulling this in for future regressions, but I think it's pretty solid.

@rockymeza

What is the use case for this again?

@timrwood
Owner

This is to address #235. The main use case would be validating user input.

var input = moment($('#datepicker').val(), 'MM-DD-YYYY');
if (input.isValid()) {
    // do something
} else {
    alert("Thats not a date silly...");
}
@rockymeza

This should test a valid date, like 2010-01-01T24. Otherwise how do you know what it's failing on?

Owner

Nice catch, I fixed it in a later commit. Additionally, there aren't any invalid fractional seconds as the range is from 0 - 999. I'm removing the test for fractional seconds failing.

@rockymeza

this test cannot have the same name as the previous test.

Owner

Oops, copy paste error. Fixed in a later commit.

timrwood added some commits
@timrwood timrwood Fixing duplicated unit test names 9a0e96d
@timrwood timrwood Fixing tests so that they use actual dates so we can test that hours …
…minutes and seconds can fail

I think its impossible to have an invalid fractional second, as it can
be from 0 - 999. Removing the test for it.
3bf93a2
@timrwood timrwood Merge commit '618441a45f2937d9294e92f73d624f5a7d0ffe1a' into feature/…
…isValid
568bb72
This was referenced
@timrwood
Owner

Note: This will not work after manipulating the moment as it compares the current array of date parts against the one that was used to create the date.

var a = moment([2010, 0, 1]);
a.isValid(); // true
a.add('months', 1);
a.isValid(); // false

Other than that, I think this is ready to merge in. @nailor, want to weigh in as you opened the issue that warranted this change?

@nailor

Looks good to me :)

@timrwood timrwood referenced this pull request
Closed

1.7.0 Changelog #288

@rockymeza

That it ceases to be valid after manipulation is a bit odd. But I think that the major use case is supposed to be right after instantiation, not after manipulation. We should document that, or maybe change the behavior after instantiation?

@timrwood
Owner

The reason I wanted to avoid checking at instantiation was to avoid a performance hit on all moments.

The way we determine if a moment is valid is by checking if the date is Invalid Date or by comparing the input array to the generated array after creation. Comparing array is used with moments created with an array as well as moments created with a string and format (including the automatic iso8601 parsing).

So the two ways to check for validity are to check when the moment is created, or check the first time isValid is called.

// add to the instantiation
function Moment(date) {
    ...
    // this is added to every moment() call
    this.isValid = true;
    if (isEqualArray(originalArray, this.toArray())) {
        this.isValid = false;
    }
}
// add on first call
function Moment(date) {
    ...
    this.originalArray = originalArray;
}
Moment.prototype.isValid = function() {
    if (isEqualArray(this.originalArray, this.toArray())) {
        return false;
    }
    return true;
}

I guess I should do a jsperf on the actual impact of checking during instantiation before making a decision though.

I'm not sure of the use case where someone would want to check the validity of a moment after they have modified it. There isn't really any way to right now, as all manipulation methods can overflow, so there would never be an invalid date that was modified.

@timrwood timrwood merged commit eaca7e6 into develop
@timrwood
Owner

Here are the jsperf results. http://jsperf.com/momentjs-validation

If we make it so that isValid will work even after modifying the moment, it will cut performance in half for any moment created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 10, 2012
  1. @timrwood

    First pass at isValid

    timrwood authored
  2. @timrwood

    More work on isValid

    timrwood authored
    I moved all calls to Date.utc.apply({}, array) into makeDateFromArray.
    I also noticed a bug where moment([2010, 0, 0]) would be converted to
    moment([2010, 0, 1]) and had to fix a bunch of unit tests that were
    dependent on this bug.
  3. @timrwood
Commits on May 11, 2012
  1. @timrwood
  2. @timrwood

    Fixing tests so that they use actual dates so we can test that hours …

    timrwood authored
    …minutes and seconds can fail
    
    I think its impossible to have an invalid fractional second, as it can
    be from 0 - 999. Removing the test for it.
  3. @timrwood
Commits on May 24, 2012
  1. @timrwood
This page is out of date. Refresh to see the latest.
View
2  min/moment.min.js
@@ -3,4 +3,4 @@
// author : Tim Wood
// license : MIT
// momentjs.com
-(function(a,b){function A(a,b){this._d=a,this._isUTC=!!b}function B(a){return a<0?Math.ceil(a):Math.floor(a)}function C(a){var b=this._data={},c=a.years||a.y||0,d=a.months||a.M||0,e=a.weeks||a.w||0,f=a.days||a.d||0,g=a.hours||a.h||0,h=a.minutes||a.m||0,i=a.seconds||a.s||0,j=a.milliseconds||a.ms||0;this._milliseconds=j+i*1e3+h*6e4+g*36e5,this._days=f+e*7,this._months=d+c*12,b.milliseconds=j%1e3,i+=B(j/1e3),b.seconds=i%60,h+=B(i/60),b.minutes=h%60,g+=B(h/60),b.hours=g%24,f+=B(g/24),f+=e*7,b.days=f%30,d+=B(f/30),b.months=d%12,c+=B(d/12),b.years=c}function D(a,b){var c=a+"";while(c.length<b)c="0"+c;return c}function E(a,b,c){var d=b._milliseconds,e=b._days,f=b._months,g;d&&a._d.setTime(+a+d*c),e&&a.date(a.date()+e*c),f&&(g=a.date(),a.date(1).month(a.month()+f*c).date(Math.min(g,a.daysInMonth())))}function F(a){return Object.prototype.toString.call(a)==="[object Array]"}function G(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 H(b,d){function q(d){var l,r;switch(d){case"M":return e+1;case"Mo":return e+1+o(e+1);case"MM":return D(e+1,2);case"MMM":return c.monthsShort[e];case"MMMM":return c.months[e];case"D":return f;case"Do":return f+o(f);case"DD":return D(f,2);case"DDD":return l=new a(g,e,f),r=new a(g,0,1),~~((l-r)/864e5+1.5);case"DDDo":return l=q("DDD"),l+o(l);case"DDDD":return D(q("DDD"),3);case"d":return h;case"do":return h+o(h);case"ddd":return c.weekdaysShort[h];case"dddd":return c.weekdays[h];case"w":return l=new a(g,e,f-h+5),r=new a(l.getFullYear(),0,4),~~((l-r)/864e5/7+1.5);case"wo":return l=q("w"),l+o(l);case"ww":return D(q("w"),2);case"YY":return D(g%100,2);case"YYYY":return g;case"a":return p?p(i,j,!1):i>11?"pm":"am";case"A":return p?p(i,j,!0):i>11?"PM":"AM";case"H":return i;case"HH":return D(i,2);case"h":return i%12||12;case"hh":return D(i%12||12,2);case"m":return j;case"mm":return D(j,2);case"s":return k;case"ss":return D(k,2);case"S":return~~(m/100);case"SS":return D(~~(m/10),2);case"SSS":return D(m,3);case"Z":return(n<0?"-":"+")+D(~~(Math.abs(n)/60),2)+":"+D(~~(Math.abs(n)%60),2);case"ZZ":return(n<0?"-":"+")+D(~~(10*Math.abs(n)/6),4);case"L":case"LL":case"LLL":case"LLLL":case"LT":return H(b,c.longDateFormat[d]);default:return d.replace(/(^\[)|(\\)|\]$/g,"")}}var e=b.month(),f=b.date(),g=b.year(),h=b.day(),i=b.hours(),j=b.minutes(),k=b.seconds(),m=b.milliseconds(),n=-b.zone(),o=c.ordinal,p=c.meridiem;return d.replace(l,q)}function I(a){switch(a){case"DDDD":return p;case"YYYY":return q;case"S":case"SS":case"SSS":case"DDD":return o;case"MMM":case"MMMM":case"ddd":case"dddd":case"a":case"A":return r;case"Z":case"ZZ":return s;case"T":return t;case"MM":case"DD":case"dd":case"YY":case"HH":case"hh":case"mm":case"ss":case"M":case"D":case"d":case"H":case"h":case"m":case"s":return n;default:return new RegExp(a.replace("\\",""))}}function J(a,b,d,e){var f;switch(a){case"M":case"MM":d[1]=b==null?0:~~b-1;break;case"MMM":case"MMMM":for(f=0;f<12;f++)if(c.monthsParse[f].test(b)){d[1]=f;break}break;case"D":case"DD":case"DDD":case"DDDD":d[2]=~~b;break;case"YY":b=~~b,d[0]=b+(b>70?1900:2e3);break;case"YYYY":d[0]=~~Math.abs(b);break;case"a":case"A":e.isPm=(b+"").toLowerCase()==="pm";break;case"H":case"HH":case"h":case"hh":d[3]=~~b;break;case"m":case"mm":d[4]=~~b;break;case"s":case"ss":d[5]=~~b;break;case"S":case"SS":case"SSS":d[6]=~~(("0."+b)*1e3);break;case"Z":case"ZZ":e.isUTC=!0,f=(b+"").match(x),f&&f[1]&&(e.tzh=~~f[1]),f&&f[2]&&(e.tzm=~~f[2]),f&&f[0]==="+"&&(e.tzh=-e.tzh,e.tzm=-e.tzm)}}function K(b,c){var d=[0,0,1,0,0,0,0],e={tzh:0,tzm:0},f=c.match(l),g,h;for(g=0;g<f.length;g++)h=(I(f[g]).exec(b)||[])[0],b=b.replace(I(f[g]),""),J(f[g],h,d,e);return e.isPm&&d[3]<12&&(d[3]+=12),e.isPm===!1&&d[3]===12&&(d[3]=0),d[3]+=e.tzh,d[4]+=e.tzm,e.isUTC?new a(a.UTC.apply({},d)):G(d)}function L(a,b){var c=Math.min(a.length,b.length),d=Math.abs(a.length-b.length),e=0,f;for(f=0;f<c;f++)~~a[f]!==~~b[f]&&e++;return e+d}function M(a,b){var c,d=a.match(m)||[],e,f=99,g,h,i;for(g=0;g<b.length;g++)h=K(a,b[g]),e=H(new A(h),b[g]).match(m)||[],i=L(d,e),i<f&&(f=i,c=h);return c}function N(b){var c="YYYY-MM-DDT",d;if(u.exec(b)){for(d=0;d<4;d++)if(w[d][1].exec(b)){c+=w[d][0];break}return s.exec(b)?K(b,c+" Z"):K(b,c)}return new a(b)}function O(a,b,d,e){var f=c.relativeTime[a];return typeof f=="function"?f(b||1,!!d,a,e):f.replace(/%d/i,b||1)}function P(a,b){var c=e(Math.abs(a)/1e3),d=e(c/60),f=e(d/60),g=e(f/24),h=e(g/365),i=c<45&&["s",c]||d===1&&["m"]||d<45&&["mm",d]||f===1&&["h"]||f<22&&["hh",f]||g===1&&["d"]||g<=25&&["dd",g]||g<=45&&["M"]||g<345&&["MM",e(g/30)]||h===1&&["y"]||["yy",h];return i[2]=b,i[3]=a>0,O.apply({},i)}function Q(a,b){c.fn[a]=function(a){var c=this._isUTC?"UTC":"";return a!=null?(this._d["set"+c+b](a),this):this._d["get"+c+b]()}}function R(a){c.duration.fn[a]=function(){return this._data[a]}}function S(a,b){c.duration.fn["as"+a]=function(){return+this/b}}var c,d="1.6.2",e=Math.round,f,g={},h="en",i=typeof module!="undefined",j="months|monthsShort|monthsParse|weekdays|weekdaysShort|longDateFormat|calendar|relativeTime|ordinal|meridiem".split("|"),k=/^\/?Date\((\-?\d+)/i,l=/(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|dddd?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|SS?S?|zz?|ZZ?|LT|LL?L?L?)/g,m=/([0-9a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)/gi,n=/\d\d?/,o=/\d{1,3}/,p=/\d{3}/,q=/\d{4}/,r=/[0-9a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+/i,s=/Z|[\+\-]\d\d:?\d\d/i,t=/T/i,u=/^\s*\d{4}-\d\d-\d\d(T(\d\d(:\d\d(:\d\d(\.\d\d?\d?)?)?)?)?([\+\-]\d\d:?\d\d)?)?/,v="YYYY-MM-DDTHH:mm:ssZ",w=[["HH:mm:ss.S",/T\d\d:\d\d:\d\d\.\d{1,3}/],["HH:mm:ss",/T\d\d:\d\d:\d\d/],["HH:mm",/T\d\d:\d\d/],["HH",/T\d\d/]],x=/([\+\-]|\d\d)/gi,y="Month|Date|Hours|Minutes|Seconds|Milliseconds".split("|"),z={Milliseconds:1,Seconds:1e3,Minutes:6e4,Hours:36e5,Days:864e5,Months:2592e6,Years:31536e6};c=function(d,e){if(d===null||d==="")return null;var f,g,h;return c.isMoment(d)?(f=new a(+d._d),h=d._isUTC):e?F(e)?f=M(d,e):f=K(d,e):(g=k.exec(d),f=d===b?new a:g?new a(+g[1]):d instanceof a?d:F(d)?G(d):typeof d=="string"?N(d):new a(d)),new A(f,h)},c.utc=function(b,d){return F(b)?new A(new a(a.UTC.apply({},b)),!0):d&&b?c(b+" +0000",d+" Z").utc():c(b&&!s.exec(b)?b+"+0000":b).utc()},c.unix=function(a){return c(a*1e3)},c.duration=function(a,b){var d=c.isDuration(a),e=typeof a=="number",f=d?a._data:e?{}:a;return e&&(b?f[b]=a:f.milliseconds=a),new C(f)},c.humanizeDuration=function(a,b,d){return c.duration(a,b===!0?null:b).humanize(b===!0?!0:d)},c.version=d,c.defaultFormat=v,c.lang=function(a,b){var d,e,f=[];if(!a)return h;if(b){for(d=0;d<12;d++)f[d]=new RegExp("^"+b.months[d]+"|^"+b.monthsShort[d].replace(".",""),"i");b.monthsParse=b.monthsParse||f,g[a]=b}if(g[a]){for(d=0;d<j.length;d++)c[j[d]]=g[a][j[d]]||g.en[j[d]];h=a}else i&&(e=require("./lang/"+a),c.lang(a,e))},c.lang("en",{months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),monthsShort:"Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),weekdaysShort:"Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),longDateFormat:{LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D YYYY",LLL:"MMMM D YYYY LT",LLLL:"dddd, MMMM D YYYY LT"},meridiem:!1,calendar:{sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[last] dddd [at] LT",sameElse:"L"},relativeTime:{future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},ordinal:function(a){var b=a%10;return~~(a%100/10)===1?"th":b===1?"st":b===2?"nd":b===3?"rd":"th"}}),c.isMoment=function(a){return a instanceof A},c.isDuration=function(a){return a instanceof C},c.fn=A.prototype={clone:function(){return c(this)},valueOf:function(){return+this._d},unix:function(){return Math.floor(+this._d/1e3)},toString:function(){return this._d.toString()},toDate:function(){return this._d},utc:function(){return this._isUTC=!0,this},local:function(){return this._isUTC=!1,this},format:function(a){return H(this,a?a:c.defaultFormat)},add:function(a,b){var d=b?c.duration(+b,a):c.duration(a);return E(this,d,1),this},subtract:function(a,b){var d=b?c.duration(+b,a):c.duration(a);return E(this,d,-1),this},diff:function(a,b,d){var f=this._isUTC?c(a).utc():c(a).local(),g=(this.zone()-f.zone())*6e4,h=this._d-f._d-g,i=this.year()-f.year(),j=this.month()-f.month(),k=this.date()-f.date(),l;return b==="months"?l=i*12+j+k/30:b==="years"?l=i+(j+k/30)/12:l=b==="seconds"?h/1e3:b==="minutes"?h/6e4:b==="hours"?h/36e5:b==="days"?h/864e5:b==="weeks"?h/6048e5:h,d?l:e(l)},from:function(a,b){return c.duration(this.diff(a)).humanize(!b)},fromNow:function(a){return this.from(c(),a)},calendar:function(){var a=this.diff(c().sod(),"days",!0),b=c.calendar,d=b.sameElse,e=a<-6?d:a<-1?b.lastWeek:a<0?b.lastDay:a<1?b.sameDay:a<2?b.nextDay:a<7?b.nextWeek:d;return this.format(typeof e=="function"?e.apply(this):e)},isLeapYear:function(){var a=this.year();return a%4===0&&a%100!==0||a%400===0},isDST:function(){return this.zone()<c([this.year()]).zone()||this.zone()<c([this.year(),5]).zone()},day:function(a){var b=this._isUTC?this._d.getUTCDay():this._d.getDay();return a==null?b:this.add({d:a-b})},startOf:function(a){var b=this.clone();switch(a){case"year":b.month(0);case"month":b.date(1);case"day":b.hours(0);case"hour":b.minutes(0);case"minute":b.seconds(0);case"second":b.milliseconds(0)}return b},endOf:function(a){return this.startOf(a).add(a+"s",1).subtract("milliseconds",1)},sod:function(){return this.startOf("day")},eod:function(){return this.endOf("day")},zone:function(){return this._isUTC?0:this._d.getTimezoneOffset()},daysInMonth:function(){return c.utc([this.year(),this.month()+1,0]).date()}};for(f=0;f<y.length;f++)Q(y[f].toLowerCase(),y[f]);Q("year","FullYear"),c.duration.fn=C.prototype={weeks:function(){return B(this.days()/7)},valueOf:function(){return this._milliseconds+this._days*864e5+this._months*2592e6},humanize:function(a){var b=+this,d=c.relativeTime,e=P(b,!a);return a&&(e=(b<=0?d.past:d.future).replace(/%s/i,e)),e}};for(f in z)z.hasOwnProperty(f)&&(S(f,z[f]),R(f.toLowerCase()));S("Weeks",6048e5),i&&(module.exports=c),typeof window!="undefined"&&typeof ender=="undefined"&&(window.moment=c),typeof define=="function"&&define.amd&&define("moment",[],function(){return c})})(Date);
+(function(a,b){function A(a,b){this._d=a,this._isUTC=!!b,this._a=a._a||null,a._a=null}function B(a){return a<0?Math.ceil(a):Math.floor(a)}function C(a){var b=this._data={},c=a.years||a.y||0,d=a.months||a.M||0,e=a.weeks||a.w||0,f=a.days||a.d||0,g=a.hours||a.h||0,h=a.minutes||a.m||0,i=a.seconds||a.s||0,j=a.milliseconds||a.ms||0;this._milliseconds=j+i*1e3+h*6e4+g*36e5,this._days=f+e*7,this._months=d+c*12,b.milliseconds=j%1e3,i+=B(j/1e3),b.seconds=i%60,h+=B(i/60),b.minutes=h%60,g+=B(h/60),b.hours=g%24,f+=B(g/24),f+=e*7,b.days=f%30,d+=B(f/30),b.months=d%12,c+=B(d/12),b.years=c}function D(a,b){var c=a+"";while(c.length<b)c="0"+c;return c}function E(a,b,c){var d=b._milliseconds,e=b._days,f=b._months,g;d&&a._d.setTime(+a+d*c),e&&a.date(a.date()+e*c),f&&(g=a.date(),a.date(1).month(a.month()+f*c).date(Math.min(g,a.daysInMonth())))}function F(a){return Object.prototype.toString.call(a)==="[object Array]"}function G(b,c){var d,e;for(d=1;d<7;d++)b[d]=b[d]==null?d===2?1:0:b[d];return b[7]=c,e=c?new a(a.UTC.apply({},b)):new a(b[0],b[1],b[2],b[3],b[4],b[5],b[6]),e._a=b,e}function H(b,d){function q(d){var l,r;switch(d){case"M":return e+1;case"Mo":return e+1+o(e+1);case"MM":return D(e+1,2);case"MMM":return c.monthsShort[e];case"MMMM":return c.months[e];case"D":return f;case"Do":return f+o(f);case"DD":return D(f,2);case"DDD":return l=new a(g,e,f),r=new a(g,0,1),~~((l-r)/864e5+1.5);case"DDDo":return l=q("DDD"),l+o(l);case"DDDD":return D(q("DDD"),3);case"d":return h;case"do":return h+o(h);case"ddd":return c.weekdaysShort[h];case"dddd":return c.weekdays[h];case"w":return l=new a(g,e,f-h+5),r=new a(l.getFullYear(),0,4),~~((l-r)/864e5/7+1.5);case"wo":return l=q("w"),l+o(l);case"ww":return D(q("w"),2);case"YY":return D(g%100,2);case"YYYY":return g;case"a":return p?p(i,j,!1):i>11?"pm":"am";case"A":return p?p(i,j,!0):i>11?"PM":"AM";case"H":return i;case"HH":return D(i,2);case"h":return i%12||12;case"hh":return D(i%12||12,2);case"m":return j;case"mm":return D(j,2);case"s":return k;case"ss":return D(k,2);case"S":return~~(m/100);case"SS":return D(~~(m/10),2);case"SSS":return D(m,3);case"Z":return(n<0?"-":"+")+D(~~(Math.abs(n)/60),2)+":"+D(~~(Math.abs(n)%60),2);case"ZZ":return(n<0?"-":"+")+D(~~(10*Math.abs(n)/6),4);case"L":case"LL":case"LLL":case"LLLL":case"LT":return H(b,c.longDateFormat[d]);default:return d.replace(/(^\[)|(\\)|\]$/g,"")}}var e=b.month(),f=b.date(),g=b.year(),h=b.day(),i=b.hours(),j=b.minutes(),k=b.seconds(),m=b.milliseconds(),n=-b.zone(),o=c.ordinal,p=c.meridiem;return d.replace(l,q)}function I(a){switch(a){case"DDDD":return p;case"YYYY":return q;case"S":case"SS":case"SSS":case"DDD":return o;case"MMM":case"MMMM":case"ddd":case"dddd":case"a":case"A":return r;case"Z":case"ZZ":return s;case"T":return t;case"MM":case"DD":case"dd":case"YY":case"HH":case"hh":case"mm":case"ss":case"M":case"D":case"d":case"H":case"h":case"m":case"s":return n;default:return new RegExp(a.replace("\\",""))}}function J(a,b,d,e){var f;switch(a){case"M":case"MM":d[1]=b==null?0:~~b-1;break;case"MMM":case"MMMM":for(f=0;f<12;f++)if(c.monthsParse[f].test(b)){d[1]=f;break}break;case"D":case"DD":case"DDD":case"DDDD":b!=null&&(d[2]=~~b);break;case"YY":b=~~b,d[0]=b+(b>70?1900:2e3);break;case"YYYY":d[0]=~~Math.abs(b);break;case"a":case"A":e.isPm=(b+"").toLowerCase()==="pm";break;case"H":case"HH":case"h":case"hh":d[3]=~~b;break;case"m":case"mm":d[4]=~~b;break;case"s":case"ss":d[5]=~~b;break;case"S":case"SS":case"SSS":d[6]=~~(("0."+b)*1e3);break;case"Z":case"ZZ":e.isUTC=!0,f=(b+"").match(x),f&&f[1]&&(e.tzh=~~f[1]),f&&f[2]&&(e.tzm=~~f[2]),f&&f[0]==="+"&&(e.tzh=-e.tzh,e.tzm=-e.tzm)}}function K(a,b){var c=[0,0,1,0,0,0,0],d={tzh:0,tzm:0},e=b.match(l),f,g;for(f=0;f<e.length;f++)g=(I(e[f]).exec(a)||[])[0],a=a.replace(I(e[f]),""),J(e[f],g,c,d);return d.isPm&&c[3]<12&&(c[3]+=12),d.isPm===!1&&c[3]===12&&(c[3]=0),c[3]+=d.tzh,c[4]+=d.tzm,G(c,d.isUTC)}function L(a,b){var c=Math.min(a.length,b.length),d=Math.abs(a.length-b.length),e=0,f;for(f=0;f<c;f++)~~a[f]!==~~b[f]&&e++;return e+d}function M(a,b){var c,d=a.match(m)||[],e,f=99,g,h,i;for(g=0;g<b.length;g++)h=K(a,b[g]),e=H(new A(h),b[g]).match(m)||[],i=L(d,e),i<f&&(f=i,c=h);return c}function N(b){var c="YYYY-MM-DDT",d;if(u.exec(b)){for(d=0;d<4;d++)if(w[d][1].exec(b)){c+=w[d][0];break}return s.exec(b)?K(b,c+" Z"):K(b,c)}return new a(b)}function O(a,b,d,e){var f=c.relativeTime[a];return typeof f=="function"?f(b||1,!!d,a,e):f.replace(/%d/i,b||1)}function P(a,b){var c=e(Math.abs(a)/1e3),d=e(c/60),f=e(d/60),g=e(f/24),h=e(g/365),i=c<45&&["s",c]||d===1&&["m"]||d<45&&["mm",d]||f===1&&["h"]||f<22&&["hh",f]||g===1&&["d"]||g<=25&&["dd",g]||g<=45&&["M"]||g<345&&["MM",e(g/30)]||h===1&&["y"]||["yy",h];return i[2]=b,i[3]=a>0,O.apply({},i)}function Q(a,b){c.fn[a]=function(a){var c=this._isUTC?"UTC":"";return a!=null?(this._d["set"+c+b](a),this):this._d["get"+c+b]()}}function R(a){c.duration.fn[a]=function(){return this._data[a]}}function S(a,b){c.duration.fn["as"+a]=function(){return+this/b}}var c,d="1.6.2",e=Math.round,f,g={},h="en",i=typeof module!="undefined",j="months|monthsShort|monthsParse|weekdays|weekdaysShort|longDateFormat|calendar|relativeTime|ordinal|meridiem".split("|"),k=/^\/?Date\((\-?\d+)/i,l=/(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|dddd?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|SS?S?|zz?|ZZ?|LT|LL?L?L?)/g,m=/([0-9a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)/gi,n=/\d\d?/,o=/\d{1,3}/,p=/\d{3}/,q=/\d{4}/,r=/[0-9a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+/i,s=/Z|[\+\-]\d\d:?\d\d/i,t=/T/i,u=/^\s*\d{4}-\d\d-\d\d(T(\d\d(:\d\d(:\d\d(\.\d\d?\d?)?)?)?)?([\+\-]\d\d:?\d\d)?)?/,v="YYYY-MM-DDTHH:mm:ssZ",w=[["HH:mm:ss.S",/T\d\d:\d\d:\d\d\.\d{1,3}/],["HH:mm:ss",/T\d\d:\d\d:\d\d/],["HH:mm",/T\d\d:\d\d/],["HH",/T\d\d/]],x=/([\+\-]|\d\d)/gi,y="Month|Date|Hours|Minutes|Seconds|Milliseconds".split("|"),z={Milliseconds:1,Seconds:1e3,Minutes:6e4,Hours:36e5,Days:864e5,Months:2592e6,Years:31536e6};c=function(d,e){if(d===null||d==="")return null;var f,g,h;return c.isMoment(d)?(f=new a(+d._d),h=d._isUTC):e?F(e)?f=M(d,e):f=K(d,e):(g=k.exec(d),f=d===b?new a:g?new a(+g[1]):d instanceof a?d:F(d)?G(d):typeof d=="string"?N(d):new a(d)),new A(f,h)},c.utc=function(a,b){return F(a)?new A(G(a,!0),!0):b&&a?c(a+" +0000",b+" Z").utc():c(a&&!s.exec(a)?a+"+0000":a).utc()},c.unix=function(a){return c(a*1e3)},c.duration=function(a,b){var d=c.isDuration(a),e=typeof a=="number",f=d?a._data:e?{}:a;return e&&(b?f[b]=a:f.milliseconds=a),new C(f)},c.humanizeDuration=function(a,b,d){return c.duration(a,b===!0?null:b).humanize(b===!0?!0:d)},c.version=d,c.defaultFormat=v,c.lang=function(a,b){var d,e,f=[];if(!a)return h;if(b){for(d=0;d<12;d++)f[d]=new RegExp("^"+b.months[d]+"|^"+b.monthsShort[d].replace(".",""),"i");b.monthsParse=b.monthsParse||f,g[a]=b}if(g[a]){for(d=0;d<j.length;d++)c[j[d]]=g[a][j[d]]||g.en[j[d]];h=a}else i&&(e=require("./lang/"+a),c.lang(a,e))},c.lang("en",{months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),monthsShort:"Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),weekdaysShort:"Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),longDateFormat:{LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D YYYY",LLL:"MMMM D YYYY LT",LLLL:"dddd, MMMM D YYYY LT"},meridiem:!1,calendar:{sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[last] dddd [at] LT",sameElse:"L"},relativeTime:{future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},ordinal:function(a){var b=a%10;return~~(a%100/10)===1?"th":b===1?"st":b===2?"nd":b===3?"rd":"th"}}),c.isMoment=function(a){return a instanceof A},c.isDuration=function(a){return a instanceof C},c.fn=A.prototype={clone:function(){return c(this)},valueOf:function(){return+this._d},unix:function(){return Math.floor(+this._d/1e3)},toString:function(){return this._d.toString()},toDate:function(){return this._d},toArray:function(){var a=this;return[a.year(),a.month(),a.date(),a.hours(),a.minutes(),a.seconds(),a.milliseconds()]},isValid:function(){var a,b;if(this._a)for(a=0;a<7;a++){b=(this._a[7]?c.utc(this):this).toArray();if(this._a[a]!==b[a])return!1}return!isNaN(this._d.getTime())},utc:function(){return this._isUTC=!0,this},local:function(){return this._isUTC=!1,this},format:function(a){return H(this,a?a:c.defaultFormat)},add:function(a,b){var d=b?c.duration(+b,a):c.duration(a);return E(this,d,1),this},subtract:function(a,b){var d=b?c.duration(+b,a):c.duration(a);return E(this,d,-1),this},diff:function(a,b,d){var f=this._isUTC?c(a).utc():c(a).local(),g=(this.zone()-f.zone())*6e4,h=this._d-f._d-g,i=this.year()-f.year(),j=this.month()-f.month(),k=this.date()-f.date(),l;return b==="months"?l=i*12+j+k/30:b==="years"?l=i+(j+k/30)/12:l=b==="seconds"?h/1e3:b==="minutes"?h/6e4:b==="hours"?h/36e5:b==="days"?h/864e5:b==="weeks"?h/6048e5:h,d?l:e(l)},from:function(a,b){return c.duration(this.diff(a)).humanize(!b)},fromNow:function(a){return this.from(c(),a)},calendar:function(){var a=this.diff(c().sod(),"days",!0),b=c.calendar,d=b.sameElse,e=a<-6?d:a<-1?b.lastWeek:a<0?b.lastDay:a<1?b.sameDay:a<2?b.nextDay:a<7?b.nextWeek:d;return this.format(typeof e=="function"?e.apply(this):e)},isLeapYear:function(){var a=this.year();return a%4===0&&a%100!==0||a%400===0},isDST:function(){return this.zone()<c([this.year()]).zone()||this.zone()<c([this.year(),5]).zone()},day:function(a){var b=this._isUTC?this._d.getUTCDay():this._d.getDay();return a==null?b:this.add({d:a-b})},startOf:function(a){var b=this.clone();switch(a){case"year":b.month(0);case"month":b.date(1);case"day":b.hours(0);case"hour":b.minutes(0);case"minute":b.seconds(0);case"second":b.milliseconds(0)}return b},endOf:function(a){return this.startOf(a).add(a+"s",1).subtract("milliseconds",1)},sod:function(){return this.startOf("day")},eod:function(){return this.endOf("day")},zone:function(){return this._isUTC?0:this._d.getTimezoneOffset()},daysInMonth:function(){return c.utc([this.year(),this.month()+1,0]).date()}};for(f=0;f<y.length;f++)Q(y[f].toLowerCase(),y[f]);Q("year","FullYear"),c.duration.fn=C.prototype={weeks:function(){return B(this.days()/7)},valueOf:function(){return this._milliseconds+this._days*864e5+this._months*2592e6},humanize:function(a){var b=+this,d=c.relativeTime,e=P(b,!a);return a&&(e=(b<=0?d.past:d.future).replace(/%s/i,e)),e}};for(f in z)z.hasOwnProperty(f)&&(S(f,z[f]),R(f.toLowerCase()));S("Weeks",6048e5),i&&(module.exports=c),typeof window!="undefined"&&typeof ender=="undefined"&&(window.moment=c),typeof define=="function"&&define.amd&&define("moment",[],function(){return c})})(Date);
View
36 min/moment.min.pretty.js
@@ -5,7 +5,7 @@
// momentjs.com
(function(a, b) {
function A(a, b) {
- this._d = a, this._isUTC = !!b;
+ this._d = a, this._isUTC = !!b, this._a = a._a || null, a._a = null;
}
function B(a) {
return a < 0 ? Math.ceil(a) : Math.floor(a);
@@ -26,8 +26,10 @@
function F(a) {
return Object.prototype.toString.call(a) === "[object Array]";
}
- function G(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 G(b, c) {
+ var d, e;
+ for (d = 1; d < 7; d++) b[d] = b[d] == null ? d === 2 ? 1 : 0 : b[d];
+ return b[7] = c, e = c ? new a(a.UTC.apply({}, b)) : new a(b[0], b[1], b[2], b[3], b[4], b[5], b[6]), e._a = b, e;
}
function H(b, d) {
function q(d) {
@@ -177,7 +179,7 @@
case "DD":
case "DDD":
case "DDDD":
- d[2] = ~~b;
+ b != null && (d[2] = ~~b);
break;
case "YY":
b = ~~b, d[0] = b + (b > 70 ? 1900 : 2e3);
@@ -213,13 +215,13 @@
e.isUTC = !0, f = (b + "").match(x), f && f[1] && (e.tzh = ~~f[1]), f && f[2] && (e.tzm = ~~f[2]), f && f[0] === "+" && (e.tzh = -e.tzh, e.tzm = -e.tzm);
}
}
- function K(b, c) {
- var d = [ 0, 0, 1, 0, 0, 0, 0 ], e = {
+ function K(a, b) {
+ var c = [ 0, 0, 1, 0, 0, 0, 0 ], d = {
tzh: 0,
tzm: 0
- }, f = c.match(l), g, h;
- for (g = 0; g < f.length; g++) h = (I(f[g]).exec(b) || [])[0], b = b.replace(I(f[g]), ""), J(f[g], h, d, e);
- return e.isPm && d[3] < 12 && (d[3] += 12), e.isPm === !1 && d[3] === 12 && (d[3] = 0), d[3] += e.tzh, d[4] += e.tzm, e.isUTC ? new a(a.UTC.apply({}, d)) : G(d);
+ }, e = b.match(l), f, g;
+ for (f = 0; f < e.length; f++) g = (I(e[f]).exec(a) || [])[0], a = a.replace(I(e[f]), ""), J(e[f], g, c, d);
+ return d.isPm && c[3] < 12 && (c[3] += 12), d.isPm === !1 && c[3] === 12 && (c[3] = 0), c[3] += d.tzh, c[4] += d.tzm, G(c, d.isUTC);
}
function L(a, b) {
var c = Math.min(a.length, b.length), d = Math.abs(a.length - b.length), e = 0, f;
@@ -279,8 +281,8 @@
if (d === null || d === "") return null;
var f, g, h;
return c.isMoment(d) ? (f = new a(+d._d), h = d._isUTC) : e ? F(e) ? f = M(d, e) : f = K(d, e) : (g = k.exec(d), f = d === b ? new a : g ? new a(+g[1]) : d instanceof a ? d : F(d) ? G(d) : typeof d == "string" ? N(d) : new a(d)), new A(f, h);
- }, c.utc = function(b, d) {
- return F(b) ? new A(new a(a.UTC.apply({}, b)), !0) : d && b ? c(b + " +0000", d + " Z").utc() : c(b && !s.exec(b) ? b + "+0000" : b).utc();
+ }, c.utc = function(a, b) {
+ return F(a) ? new A(G(a, !0), !0) : b && a ? c(a + " +0000", b + " Z").utc() : c(a && !s.exec(a) ? a + "+0000" : a).utc();
}, c.unix = function(a) {
return c(a * 1e3);
}, c.duration = function(a, b) {
@@ -359,6 +361,18 @@
toDate: function() {
return this._d;
},
+ toArray: function() {
+ var a = this;
+ return [ a.year(), a.month(), a.date(), a.hours(), a.minutes(), a.seconds(), a.milliseconds() ];
+ },
+ isValid: function() {
+ var a, b;
+ if (this._a) for (a = 0; a < 7; a++) {
+ b = (this._a[7] ? c.utc(this) : this).toArray();
+ if (this._a[a] !== b[a]) return !1;
+ }
+ return !isNaN(this._d.getTime());
+ },
utc: function() {
return this._isUTC = !0, this;
},
View
49 moment.js
@@ -69,6 +69,8 @@
function Moment(date, isUTC) {
this._d = date;
this._isUTC = !!isUTC;
+ this._a = date._a || null;
+ date._a = null;
}
function absRound(number) {
@@ -171,8 +173,17 @@
// the array should mirror the parameters below
// note: all values past the year are optional and will default to the lowest possible value.
// [year, month, day , hour, minute, second, millisecond]
- function dateFromArray(input) {
- return new Date(input[0], input[1] || 0, input[2] || 1, input[3] || 0, input[4] || 0, input[5] || 0, input[6] || 0);
+ function dateFromArray(input, asUTC) {
+ var i, date;
+ for (i = 1; i < 7; i++) {
+ input[i] = (input[i] == null) ? (i === 2 ? 1 : 0) : input[i];
+ }
+ // we store whether we used utc or not in the input array
+ input[7] = asUTC;
+ date = asUTC ? new Date(Date.UTC.apply({}, input)) :
+ new Date(input[0], input[1], input[2], input[3], input[4], input[5], input[6]);
+ date._a = input;
+ return date;
}
// format date using native date object
@@ -371,7 +382,9 @@
case 'DD' : // fall through to DDDD
case 'DDD' : // fall through to DDDD
case 'DDDD' :
- datePartArray[2] = ~~input;
+ if (input != null) {
+ datePartArray[2] = ~~input;
+ }
break;
// YEAR
case 'YY' :
@@ -456,7 +469,7 @@
datePartArray[3] += config.tzh;
datePartArray[4] += config.tzm;
// return
- return config.isUTC ? new Date(Date.UTC.apply({}, datePartArray)) : dateFromArray(datePartArray);
+ return dateFromArray(datePartArray, config.isUTC);
}
// compare two arrays, return the number of differences
@@ -575,7 +588,7 @@
// creating with utc
moment.utc = function (input, format) {
if (isArray(input)) {
- return new Moment(new Date(Date.UTC.apply({}, input)), true);
+ return new Moment(dateFromArray(input, true), true);
}
return (format && input) ?
moment(input + ' +0000', format + ' Z').utc() :
@@ -724,6 +737,32 @@
return this._d;
},
+ toArray : function () {
+ var m = this;
+ return [
+ m.year(),
+ m.month(),
+ m.date(),
+ m.hours(),
+ m.minutes(),
+ m.seconds(),
+ m.milliseconds()
+ ];
+ },
+
+ isValid : function () {
+ var i, toArray;
+ if (this._a) {
+ for (i = 0; i < 7; i++) {
+ toArray = (this._a[7] ? moment.utc(this) : this).toArray();
+ if (this._a[i] !== toArray[i]) {
+ return false;
+ }
+ }
+ }
+ return !isNaN(this._d.getTime());
+ },
+
utc : function () {
this._isUTC = true;
return this;
View
2  test/lang/ca.js
@@ -76,7 +76,7 @@ exports["lang:ca"] = {
var expected = "Gener Gen._Febrer Febr._Març Mar._Abril Abr._Maig Mai._Juny Jun._Juliol Jul._Agost Ag._Setembre Set._Octubre Oct._Novembre Nov._Desembre Des.".split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/lang/cv.js
@@ -105,7 +105,7 @@ exports["lang:cv"] = {
var expected = 'кăрлач кăр_нарăс нар_пуш пуш_ака ака_май май_çĕртме çĕр_утă утă_çурла çур_авăн ав_юпа юпа_чӳк чӳк_раштав раш'.split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/lang/da.js
@@ -105,7 +105,7 @@ exports["lang:da"] = {
var expected = 'Januar Jan_Februar Feb_Marts Mar_April Apr_Maj Maj_Juni Jun_Juli Jul_August Aug_September Sep_Oktober Okt_November Nov_December Dec'.split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/lang/de.js
@@ -105,7 +105,7 @@ exports["lang:de"] = {
var expected = 'Januar Jan._Februar Febr._März Mrz._April Apr._Mai Mai_Juni Jun._Juli Jul._August Aug._September Sept._Oktober Okt._November Nov._Dezember Dez.'.split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/lang/en-gb.js
@@ -105,7 +105,7 @@ exports["lang:en-gb"] = {
var expected = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/lang/en.js
@@ -105,7 +105,7 @@ exports["lang:en"] = {
var expected = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/lang/es.js
@@ -74,7 +74,7 @@ exports["lang:es"] = {
var expected = 'Enero Ene._Febrero Feb._Marzo Mar._Abril Abr._Mayo May._Junio Jun._Julio Jul._Agosto Ago._Septiembre Sep._Octubre Oct._Noviembre Nov._Diciembre Dic.'.split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/lang/eu.js
@@ -105,7 +105,7 @@ exports["lang:eu"] = {
var expected = 'urtarrila urt._otsaila ots._martxoa mar._apirila api._maiatza mai._ekaina eka._uztaila uzt._abuztua abu._iraila ira._urria urr._azaroa aza._abendua abe.'.split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/lang/fi.js
@@ -105,7 +105,7 @@ exports["lang:fi"] = {
var expected = 'tammikuu tam_helmikuu hel_maaliskuu maa_huhtikuu huh_toukokuu tou_kesäkuu kes_heinäkuu hei_elokuu elo_syyskuu syy_lokakuu lok_marraskuu mar_joulukuu jou'.split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/lang/fr.js
@@ -105,7 +105,7 @@ exports["lang:fr"] = {
var expected = 'janvier janv._février févr._mars mars_avril avr._mai mai_juin juin_juillet juil._août août_septembre sept._octobre oct._novembre nov._décembre déc.'.split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/lang/gl.js
@@ -75,7 +75,7 @@ exports["lang:gl"] = {
var expected = "Xaneiro Xan._Febreiro Feb._Marzo Mar._Abril Abr._Maio Mai._Xuño Xuñ._Xullo Xul._Agosto Ago._Setembro Set._Octubro Out._Novembro Nov._Decembro Dec.".split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/lang/is.js
@@ -105,7 +105,7 @@ exports["lang:is"] = {
var expected = 'janúar jan_febrúar feb_mars mar_apríl apr_maí maí_júní jún_júlí júl_ágúst ágú_september sep_október okt_nóvember nóv_desember des'.split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/lang/it.js
@@ -105,7 +105,7 @@ exports["lang:it"] = {
var expected = 'Gennaio Gen_Febbraio Feb_Marzo Mar_Aprile Apr_Maggio Mag_Giugno Giu_Luglio Lug_Agosto Ago_Settebre Set_Ottobre Ott_Novembre Nov_Dicembre Dic'.split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/lang/jp.js
@@ -65,7 +65,7 @@ exports["lang:jp"] = {
var expected = '1月 1月_2月 2月_3月 3月_4月 4月_5月 5月_6月 6月_7月 7月_8月 8月_9月 9月_10月 10月_11月 11月_12月 12月'.split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/lang/kr.js
@@ -104,7 +104,7 @@ exports["lang:kr"] = {
var expected = '1월 1월_2월 2월_3월 3월_4월 4월_5월 5월_6월 6월_7월 7월_8월 8월_9월 9월_10월 10월_11월 11월_12월 12월'.split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/lang/nb.js
@@ -105,7 +105,7 @@ exports["lang:nb"] = {
var expected = 'januar jan_februar feb_mars mar_april apr_mai mai_juni jun_juli jul_august aug_september sep_oktober okt_november nov_desember des'.split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/lang/nl.js
@@ -105,7 +105,7 @@ exports["lang:nl"] = {
var expected = 'januari jan._februari feb._maart mar._april apr._mei mei._juni jun._juli jul._augustus aug._september sep._oktober okt._november nov._december dec.'.split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/lang/pl.js
@@ -105,7 +105,7 @@ exports["lang:pl"] = {
var expected = 'styczeń sty_luty lut_marzec mar_kwiecień kwi_maj maj_czerwiec cze_lipiec lip_sierpień sie_wrzesień wrz_październik paź_listopad lis_grudzień gru'.split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/lang/pt.js
@@ -105,7 +105,7 @@ exports["lang:pt"] = {
var expected = 'Janeiro Jan_Fevereiro Fev_Março Mar_Abril Abr_Maio Mai_Junho Jun_Julho Jul_Agosto Ago_Setembro Set_Outubro Out_Novembro Nov_Dezembro Dez'.split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/lang/ru.js
@@ -105,7 +105,7 @@ exports["lang:ru"] = {
var expected = 'январь янв_февраль фев_март мар_апрель апр_май май_июнь июн_июль июл_август авг_сентябрь сен_октябрь окт_ноябрь ноя_декабрь дек'.split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/lang/sv.js
@@ -105,7 +105,7 @@ exports["lang:sv"] = {
var expected = 'januari jan_februari feb_mars mar_april apr_maj maj_juni jun_juli jul_augusti aug_september sep_oktober okt_november nov_december dec'.split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/lang/tr.js
@@ -105,7 +105,7 @@ exports["lang:tr"] = {
var expected = 'Ocak Oca_Şubat Şub_Mart Mar_Nisan Nis_Mayıs May_Haziran Haz_Temmuz Tem_Ağustos Ağu_Eylül Eyl_Ekim Eki_Kasım Kas_Aralık Ara'.split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/lang/zh-cn.js
@@ -65,7 +65,7 @@ exports["lang:zh-cn"] = {
var expected = '一月 1月_二月 2月_三月 3月_四月 4月_五月 5月_六月 6月_七月 7月_八月 8月_九月 9月_十月 10月_十一月 11月_十二月 12月'.split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/lang/zh-tw.js
@@ -65,7 +65,7 @@ exports["lang:zh-tw"] = {
var expected = '一月 1月_二月 2月_三月 3月_四月 4月_五月 5月_六月 6月_七月 7月_八月 8月_九月 9月_十月 10月_十一月 11月_十二月 12月'.split("_");
var i;
for (i = 0; i < expected.length; i++) {
- test.equal(moment([2011, i, 0]).format('MMMM MMM'), expected[i], expected[i]);
+ test.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
}
test.done();
},
View
2  test/moment/create.js
@@ -10,7 +10,7 @@ exports.create = {
test.ok(moment([2010, 1, 12, 1, 1]).toDate() instanceof Date, "[2010, 1, 12, 1, 1]");
test.ok(moment([2010, 1, 12, 1, 1, 1]).toDate() instanceof Date, "[2010, 1, 12, 1, 1, 1]");
test.ok(moment([2010, 1, 12, 1, 1, 1, 1]).toDate() instanceof Date, "[2010, 1, 12, 1, 1, 1, 1]");
- test.deepEqual(moment(new Date(2010, 1, 14, 15, 25, 50, 125)), moment([2010, 1, 14, 15, 25, 50, 125]), "constructing with array === constructing with new Date()");
+ test.equal(+moment(new Date(2010, 1, 14, 15, 25, 50, 125)), +moment([2010, 1, 14, 15, 25, 50, 125]), "constructing with array === constructing with new Date()");
test.done();
},
View
118 test/moment/is_valid.js
@@ -0,0 +1,118 @@
+var moment = require("../../moment");
+
+exports.is_valid = {
+ "array bad month" : function (test) {
+ test.expect(2);
+
+ test.equal(moment([2010, -1]).isValid(), false, 'month -1');
+ test.equal(moment([2100, 12]).isValid(), false, 'month 12');
+
+ test.done();
+ },
+
+ "array good month" : function (test) {
+ test.expect(24);
+
+ for (var i = 0; i < 12; i++) {
+ test.equal(moment([2010, i]).isValid(), true, 'month ' + i);
+ test.equal(moment.utc([2010, i]).isValid(), true, 'month ' + i);
+ }
+
+ test.done();
+ },
+
+ "array bad date" : function (test) {
+ test.expect(4);
+
+ test.equal(moment([2010, 0, 0]).isValid(), false, 'date 0');
+ test.equal(moment([2100, 0, 32]).isValid(), false, 'date 32');
+
+ test.equal(moment.utc([2010, 0, 0]).isValid(), false, 'utc date 0');
+ test.equal(moment.utc([2100, 0, 32]).isValid(), false, 'utc date 32');
+
+ test.done();
+ },
+
+ "array bad date leap year" : function (test) {
+ test.expect(8);
+
+ test.equal(moment([2010, 1, 29]).isValid(), false, '2010 feb 29');
+ test.equal(moment([2100, 1, 29]).isValid(), false, '2100 feb 29');
+ test.equal(moment([2008, 1, 30]).isValid(), false, '2008 feb 30');
+ test.equal(moment([2000, 1, 30]).isValid(), false, '2000 feb 30');
+
+ test.equal(moment.utc([2010, 1, 29]).isValid(), false, 'utc 2010 feb 29');
+ test.equal(moment.utc([2100, 1, 29]).isValid(), false, 'utc 2100 feb 29');
+ test.equal(moment.utc([2008, 1, 30]).isValid(), false, 'utc 2008 feb 30');
+ test.equal(moment.utc([2000, 1, 30]).isValid(), false, 'utc 2000 feb 30');
+
+ test.done();
+ },
+
+ "string nonsensical" : function (test) {
+ test.expect(1);
+
+ test.equal(moment('fail').isValid(), false, 'string "fail"');
+ test.done();
+ },
+
+ "invalid string iso 8601" : function (test) {
+
+ var tests = [
+ '2010-00-00',
+ '2010-01-00',
+ '2010-01-40',
+ '2010-01-01T24',
+ '2010-01-01T23:60',
+ '2010-01-01T23:59:60'
+ ];
+
+ test.expect(tests.length * 2);
+
+ for (var i = 0; i < tests.length; i++) {
+ test.equal(moment(tests[i]).isValid(), false, tests[i] + ' should be invalid');
+ test.equal(moment.utc(tests[i]).isValid(), false, tests[i] + ' should be invalid');
+ }
+ test.done();
+ },
+
+ "invalid string iso 8601 + timezone" : function (test) {
+
+ var tests = [
+ '2010-00-00+00:00',
+ '2010-01-00+00:00',
+ '2010-01-40+00:00',
+ '2010-01-40T24+00:00',
+ '2010-01-40T23:60+00:00',
+ '2010-01-40T23:59:60+00:00',
+ '2010-01-40T23:59:59.9999+00:00'
+ ];
+
+ test.expect(tests.length * 2);
+
+ for (var i = 0; i < tests.length; i++) {
+ test.equal(moment(tests[i]).isValid(), false, tests[i] + ' should be invalid');
+ test.equal(moment.utc(tests[i]).isValid(), false, tests[i] + ' should be invalid');
+ }
+ test.done();
+ },
+
+ "valid string iso 8601 + timezone" : function (test) {
+ var tests = [
+ '2010-01-01',
+ '2010-01-30',
+ '2010-01-30T23+00:00',
+ '2010-01-30T23:59+00:00',
+ '2010-01-30T23:59:59+00:00',
+ '2010-01-30T23:59:59.999+00:00'
+ ];
+
+ test.expect(tests.length * 2);
+
+ for (var i = 0; i < tests.length; i++) {
+ test.equal(moment(tests[i]).isValid(), true, tests[i] + ' should be valid');
+ test.equal(moment.utc(tests[i]).isValid(), true, tests[i] + ' should be valid');
+ }
+ test.done();
+ }
+};
Something went wrong with that request. Please try again.