From 8dd2af94f355033cc005dfc2c5a1b030a6ac3c27 Mon Sep 17 00:00:00 2001 From: Iskren Chernev Date: Tue, 28 Aug 2012 23:17:11 +0300 Subject: [PATCH] isSame should clone original moment to prevent change --- min/moment.min.js | 2 +- min/moment.min.pretty.js | 2 +- moment.js | 2 +- test/moment/is_same.js | 36 ++++++++++++++++++++++++------------ 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/min/moment.min.js b/min/moment.min.js index 3dd18a06f..c5f65d23d 100644 --- a/min/moment.min.js +++ b/min/moment.min.js @@ -3,4 +3,4 @@ // author : Tim Wood // license : MIT // momentjs.com -(function(e,t){function D(e,t,n){this._d=e,this._isUTC=!!t,this._a=e._a||null,e._a=null,this._lang=n||!1}function P(e){var t=this._data={},n=e.years||e.y||0,r=e.months||e.M||0,i=e.weeks||e.w||0,s=e.days||e.d||0,o=e.hours||e.h||0,u=e.minutes||e.m||0,a=e.seconds||e.s||0,f=e.milliseconds||e.ms||0;this._milliseconds=f+a*1e3+u*6e4+o*36e5,this._days=s+i*7,this._months=r+n*12,t.milliseconds=f%1e3,a+=H(f/1e3),t.seconds=a%60,u+=H(a/60),t.minutes=u%60,o+=H(u/60),t.hours=o%24,s+=H(o/24),s+=i*7,t.days=s%30,r+=H(s/30),t.months=r%12,n+=H(r/12),t.years=n,this._lang=!1}function H(e){return e<0?Math.ceil(e):Math.floor(e)}function B(e,t){var n=e+"";while(n.length70?1900:2e3);break;case"YYYY":case"YYYYY":n[0]=~~t;break;case"a":case"A":r.isPm=(t+"").toLowerCase()==="pm";break;case"H":case"HH":case"h":case"hh":n[3]=~~t;break;case"m":case"mm":n[4]=~~t;break;case"s":case"ss":n[5]=~~t;break;case"S":case"SS":case"SSS":n[6]=~~(("0."+t)*1e3);break;case"Z":case"ZZ":r.isUTC=!0,i=(t+"").match(C),i&&i[1]&&(r.tzh=~~i[1]),i&&i[2]&&(r.tzm=~~i[2]),i&&i[0]==="+"&&(r.tzh=-r.tzh,r.tzm=-r.tzm)}}function Q(e,t){var n=[0,0,1,0,0,0,0],r={tzh:0,tzm:0},i=t.match(c),s,o;for(s=0;s0,f[4]=n,Z.apply({},f)}function tt(e,t){n.fn[e]=function(e){var n=this._isUTC?"UTC":"";return e!=null?(this._d["set"+n+t](e),this):this._d["get"+n+t]()}}function nt(e){n.duration.fn[e]=function(){return this._data[e]}}function rt(e,t){n.duration.fn["as"+e]=function(){return+this/t}}var n,r="1.7.0",i=Math.round,s,o={},u="en",a=typeof module!="undefined"&&module.exports,f="months|monthsShort|weekdays|weekdaysShort|weekdaysMin|longDateFormat|calendar|relativeTime|ordinal|meridiem".split("|"),l=/^\/?Date\((\-?\d+)/i,c=/(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|YYYYY|YYYY|YY|a|A|hh?|HH?|mm?|ss?|SS?S?|zz?|ZZ?|-)/g,h=/(LT|LL?L?L?)/g,p=/(^\[)|(\\)|\]$/g,d=/([0-9a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)/gi,v=/\d\d?/,m=/\d{1,3}/,g=/\d{3}/,y=/\d{1,4}/,b=/[+\-]?\d{1,6}/,w=/[0-9a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+/i,E=/Z|[\+\-]\d\d:?\d\d/i,S=/T/i,x=/^\s*\d{4}-\d\d-\d\d(T(\d\d(:\d\d(:\d\d(\.\d\d?\d?)?)?)?)?([\+\-]\d\d:?\d\d)?)?/,T="YYYY-MM-DDTHH:mm:ssZ",N=[["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/]],C=/([\+\-]|\d\d)/gi,k="Month|Date|Hours|Minutes|Seconds|Milliseconds".split("|"),L={Milliseconds:1,Seconds:1e3,Minutes:6e4,Hours:36e5,Days:864e5,Months:2592e6,Years:31536e6},A={},O={M:"(a=t.month()+1)",MMM:'v("monthsShort",t.month())',MMMM:'v("months",t.month())',D:"(a=t.date())",DDD:"(a=new Date(t.year(),t.month(),t.date()),b=new Date(t.year(),0,1),a=~~(((a-b)/864e5)+1.5))",d:"(a=t.day())",dd:'v("weekdaysMin",t.day())',ddd:'v("weekdaysShort",t.day())',dddd:'v("weekdays",t.day())',w:"(a=new Date(t.year(),t.month(),t.date()-t.day()+5),b=new Date(a.getFullYear(),0,4),a=~~((a-b)/864e5/7+1.5))",YY:"p(t.year()%100,2)",YYYY:"p(t.year(),4)",YYYYY:"p(t.year(),5)",a:"m(t.hours(),t.minutes(),!0)",A:"m(t.hours(),t.minutes(),!1)",H:"t.hours()",h:"t.hours()%12||12",m:"t.minutes()",s:"t.seconds()",S:"~~(t.milliseconds()/100)",SS:"p(~~(t.milliseconds()/10),2)",SSS:"p(t.milliseconds(),3)",Z:'((a=-t.zone())<0?((a=-a),"-"):"+")+p(~~(a/60),2)+":"+p(~~a%60,2)',ZZ:'((a=-t.zone())<0?((a=-a),"-"):"+")+p(~~(10*a/6),4)'},M="DDD w M D d".split(" "),_="M D H h m s w".split(" ");while(M.length)s=M.pop(),O[s+"o"]=O[s]+"+o(a)";while(_.length)s=_.pop(),O[s+s]="p("+O[s]+",2)";O.DDDD="p("+O.DDD+",3)",n=function(r,i){if(r===null||r==="")return null;var s,o;return n.isMoment(r)?new D(new e(+r._d),r._isUTC,r._lang):(i?F(i)?s=G(r,i):s=Q(r,i):(o=l.exec(r),s=r===t?new e:o?new e(+o[1]):r instanceof e?r:F(r)?q(r):typeof r=="string"?Y(r):new e(r)),new D(s))},n.utc=function(e,t){return F(e)?new D(q(e,!0),!0):(typeof e=="string"&&!E.exec(e)&&(e+=" +0000",t&&(t+=" Z")),n(e,t).utc())},n.unix=function(e){return n(e*1e3)},n.duration=function(e,t){var r=n.isDuration(e),i=typeof e=="number",s=r?e._data:i?{}:e,o;return i&&(t?s[t]=e:s.milliseconds=e),o=new P(s),r&&(o._lang=e._lang),o},n.humanizeDuration=function(e,t,r){return n.duration(e,t===!0?null:t).humanize(t===!0?!0:r)},n.version=r,n.defaultFormat=T,n.lang=function(e,t){var r;if(!e)return u;(t||!o[e])&&R(e,t);if(o[e]){for(r=0;r11?n?"pm":"PM":n?"am":"AM"},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(e){var t=e%10;return~~(e%100/10)===1?"th":t===1?"st":t===2?"nd":t===3?"rd":"th"}}),n.fn=D.prototype={clone:function(){return n(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 e=this;return[e.year(),e.month(),e.date(),e.hours(),e.minutes(),e.seconds(),e.milliseconds(),!!this._isUTC]},isValid:function(){return this._a?!I(this._a,(this._a[7]?n.utc(this):this).toArray()):!isNaN(this._d.getTime())},utc:function(){return this._isUTC=!0,this},local:function(){return this._isUTC=!1,this},format:function(e){return $(this,e?e:n.defaultFormat)},add:function(e,t){var r=t?n.duration(+t,e):n.duration(e);return j(this,r,1),this},subtract:function(e,t){var r=t?n.duration(+t,e):n.duration(e);return j(this,r,-1),this},diff:function(e,t,r){var s=this._isUTC?n(e).utc():n(e).local(),o=(this.zone()-s.zone())*6e4,u=this._d-s._d-o,a=this.year()-s.year(),f=this.month()-s.month(),l=this.date()-s.date(),c;return t==="months"?c=a*12+f+l/30:t==="years"?c=a+(f+l/30)/12:c=t==="seconds"?u/1e3:t==="minutes"?u/6e4:t==="hours"?u/36e5:t==="days"?u/864e5:t==="weeks"?u/6048e5:u,r?c:i(c)},from:function(e,t){return n.duration(this.diff(e)).lang(this._lang).humanize(!t)},fromNow:function(e){return this.from(n(),e)},calendar:function(){var e=this.diff(n().sod(),"days",!0),t=this.lang().calendar,r=t.sameElse,i=e<-6?r:e<-1?t.lastWeek:e<0?t.lastDay:e<1?t.sameDay:e<2?t.nextDay:e<7?t.nextWeek:r;return this.format(typeof i=="function"?i.apply(this):i)},isLeapYear:function(){var e=this.year();return e%4===0&&e%100!==0||e%400===0},isDST:function(){return this.zone()70?1900:2e3);break;case"YYYY":case"YYYYY":n[0]=~~t;break;case"a":case"A":r.isPm=(t+"").toLowerCase()==="pm";break;case"H":case"HH":case"h":case"hh":n[3]=~~t;break;case"m":case"mm":n[4]=~~t;break;case"s":case"ss":n[5]=~~t;break;case"S":case"SS":case"SSS":n[6]=~~(("0."+t)*1e3);break;case"Z":case"ZZ":r.isUTC=!0,i=(t+"").match(C),i&&i[1]&&(r.tzh=~~i[1]),i&&i[2]&&(r.tzm=~~i[2]),i&&i[0]==="+"&&(r.tzh=-r.tzh,r.tzm=-r.tzm)}}function Q(e,t){var n=[0,0,1,0,0,0,0],r={tzh:0,tzm:0},i=t.match(c),s,o;for(s=0;s0,f[4]=n,Z.apply({},f)}function tt(e,t){n.fn[e]=function(e){var n=this._isUTC?"UTC":"";return e!=null?(this._d["set"+n+t](e),this):this._d["get"+n+t]()}}function nt(e){n.duration.fn[e]=function(){return this._data[e]}}function rt(e,t){n.duration.fn["as"+e]=function(){return+this/t}}var n,r="1.7.0",i=Math.round,s,o={},u="en",a=typeof module!="undefined"&&module.exports,f="months|monthsShort|weekdays|weekdaysShort|weekdaysMin|longDateFormat|calendar|relativeTime|ordinal|meridiem".split("|"),l=/^\/?Date\((\-?\d+)/i,c=/(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|YYYYY|YYYY|YY|a|A|hh?|HH?|mm?|ss?|SS?S?|zz?|ZZ?|-)/g,h=/(LT|LL?L?L?)/g,p=/(^\[)|(\\)|\]$/g,d=/([0-9a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)/gi,v=/\d\d?/,m=/\d{1,3}/,g=/\d{3}/,y=/\d{1,4}/,b=/[+\-]?\d{1,6}/,w=/[0-9a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+/i,E=/Z|[\+\-]\d\d:?\d\d/i,S=/T/i,x=/^\s*\d{4}-\d\d-\d\d(T(\d\d(:\d\d(:\d\d(\.\d\d?\d?)?)?)?)?([\+\-]\d\d:?\d\d)?)?/,T="YYYY-MM-DDTHH:mm:ssZ",N=[["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/]],C=/([\+\-]|\d\d)/gi,k="Month|Date|Hours|Minutes|Seconds|Milliseconds".split("|"),L={Milliseconds:1,Seconds:1e3,Minutes:6e4,Hours:36e5,Days:864e5,Months:2592e6,Years:31536e6},A={},O={M:"(a=t.month()+1)",MMM:'v("monthsShort",t.month())',MMMM:'v("months",t.month())',D:"(a=t.date())",DDD:"(a=new Date(t.year(),t.month(),t.date()),b=new Date(t.year(),0,1),a=~~(((a-b)/864e5)+1.5))",d:"(a=t.day())",dd:'v("weekdaysMin",t.day())',ddd:'v("weekdaysShort",t.day())',dddd:'v("weekdays",t.day())',w:"(a=new Date(t.year(),t.month(),t.date()-t.day()+5),b=new Date(a.getFullYear(),0,4),a=~~((a-b)/864e5/7+1.5))",YY:"p(t.year()%100,2)",YYYY:"p(t.year(),4)",YYYYY:"p(t.year(),5)",a:"m(t.hours(),t.minutes(),!0)",A:"m(t.hours(),t.minutes(),!1)",H:"t.hours()",h:"t.hours()%12||12",m:"t.minutes()",s:"t.seconds()",S:"~~(t.milliseconds()/100)",SS:"p(~~(t.milliseconds()/10),2)",SSS:"p(t.milliseconds(),3)",Z:'((a=-t.zone())<0?((a=-a),"-"):"+")+p(~~(a/60),2)+":"+p(~~a%60,2)',ZZ:'((a=-t.zone())<0?((a=-a),"-"):"+")+p(~~(10*a/6),4)'},M="DDD w M D d".split(" "),_="M D H h m s w".split(" ");while(M.length)s=M.pop(),O[s+"o"]=O[s]+"+o(a)";while(_.length)s=_.pop(),O[s+s]="p("+O[s]+",2)";O.DDDD="p("+O.DDD+",3)",n=function(r,i){if(r===null||r==="")return null;var s,o;return n.isMoment(r)?new D(new e(+r._d),r._isUTC,r._lang):(i?F(i)?s=G(r,i):s=Q(r,i):(o=l.exec(r),s=r===t?new e:o?new e(+o[1]):r instanceof e?r:F(r)?q(r):typeof r=="string"?Y(r):new e(r)),new D(s))},n.utc=function(e,t){return F(e)?new D(q(e,!0),!0):(typeof e=="string"&&!E.exec(e)&&(e+=" +0000",t&&(t+=" Z")),n(e,t).utc())},n.unix=function(e){return n(e*1e3)},n.duration=function(e,t){var r=n.isDuration(e),i=typeof e=="number",s=r?e._data:i?{}:e,o;return i&&(t?s[t]=e:s.milliseconds=e),o=new P(s),r&&(o._lang=e._lang),o},n.humanizeDuration=function(e,t,r){return n.duration(e,t===!0?null:t).humanize(t===!0?!0:r)},n.version=r,n.defaultFormat=T,n.lang=function(e,t){var r;if(!e)return u;(t||!o[e])&&R(e,t);if(o[e]){for(r=0;r11?n?"pm":"PM":n?"am":"AM"},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(e){var t=e%10;return~~(e%100/10)===1?"th":t===1?"st":t===2?"nd":t===3?"rd":"th"}}),n.fn=D.prototype={clone:function(){return n(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 e=this;return[e.year(),e.month(),e.date(),e.hours(),e.minutes(),e.seconds(),e.milliseconds(),!!this._isUTC]},isValid:function(){return this._a?!I(this._a,(this._a[7]?n.utc(this):this).toArray()):!isNaN(this._d.getTime())},utc:function(){return this._isUTC=!0,this},local:function(){return this._isUTC=!1,this},format:function(e){return $(this,e?e:n.defaultFormat)},add:function(e,t){var r=t?n.duration(+t,e):n.duration(e);return j(this,r,1),this},subtract:function(e,t){var r=t?n.duration(+t,e):n.duration(e);return j(this,r,-1),this},diff:function(e,t,r){var s=this._isUTC?n(e).utc():n(e).local(),o=(this.zone()-s.zone())*6e4,u=this._d-s._d-o,a=this.year()-s.year(),f=this.month()-s.month(),l=this.date()-s.date(),c;return t==="months"?c=a*12+f+l/30:t==="years"?c=a+(f+l/30)/12:c=t==="seconds"?u/1e3:t==="minutes"?u/6e4:t==="hours"?u/36e5:t==="days"?u/864e5:t==="weeks"?u/6048e5:u,r?c:i(c)},from:function(e,t){return n.duration(this.diff(e)).lang(this._lang).humanize(!t)},fromNow:function(e){return this.from(n(),e)},calendar:function(){var e=this.diff(n().sod(),"days",!0),t=this.lang().calendar,r=t.sameElse,i=e<-6?r:e<-1?t.lastWeek:e<0?t.lastDay:e<1?t.sameDay:e<2?t.nextDay:e<7?t.nextWeek:r;return this.format(typeof i=="function"?i.apply(this):i)},isLeapYear:function(){var e=this.year();return e%4===0&&e%100!==0||e%400===0},isDST:function(){return this.zone()