Comparing version 0.1.4 to 0.1.5
@@ -1,7 +0,6 @@ | ||
// Moment.js | ||
// | ||
// (c) 2011 Tim Wood | ||
// Moment.js is freely distributable under the terms of the MIT license. | ||
// | ||
// Version 1.3.0 | ||
// moment.js | ||
// version : 1.6.2 | ||
// author : Tim Wood | ||
// license : MIT | ||
// momentjs.com | ||
@@ -11,21 +10,126 @@ (function (Date, undefined) { | ||
var moment, | ||
round = Math.round, | ||
VERSION = "1.6.2", | ||
round = Math.round, i, | ||
// internal storage for language config files | ||
languages = {}, | ||
currentLanguage = 'en', | ||
// check for nodeJS | ||
hasModule = (typeof module !== 'undefined'), | ||
paramsToParse = 'months|monthsShort|monthsParse|weekdays|weekdaysShort|longDateFormat|calendar|relativeTime|ordinal|meridiem'.split('|'), | ||
i, | ||
charactersToReplace = /(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|dddd?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|zz?|ZZ?|LT|LL?L?L?)/g, | ||
nonuppercaseLetters = /[^A-Z]/g, | ||
timezoneRegex = /\([A-Za-z ]+\)|:[0-9]{2} [A-Z]{3} /g, | ||
tokenCharacters = /(\\)?(MM?M?M?|dd?d?d|DD?D?D?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|ZZ?|T)/g, | ||
inputCharacters = /(\\)?([0-9]+|([a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+|([\+\-]\d\d:?\d\d))/gi, | ||
timezoneParseRegex = /([\+\-]|\d\d)/gi, | ||
VERSION = "1.3.0", | ||
shortcuts = 'Month|Date|Hours|Minutes|Seconds|Milliseconds'.split('|'); | ||
// parameters to check for on the lang config | ||
langConfigProperties = 'months|monthsShort|monthsParse|weekdays|weekdaysShort|longDateFormat|calendar|relativeTime|ordinal|meridiem'.split('|'), | ||
// ASP.NET json date format regex | ||
aspNetJsonRegex = /^\/?Date\((\-?\d+)/i, | ||
// format tokens | ||
formattingTokens = /(\[[^\[]*\])|(\\)?(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, | ||
// parsing tokens | ||
parseMultipleFormatChunker = /([0-9a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)/gi, | ||
// parsing token regexes | ||
parseTokenOneOrTwoDigits = /\d\d?/, // 0 - 99 | ||
parseTokenOneToThreeDigits = /\d{1,3}/, // 0 - 999 | ||
parseTokenThreeDigits = /\d{3}/, // 000 - 999 | ||
parseTokenFourDigits = /\d{4}/, // 0000 - 9999 | ||
parseTokenWord = /[0-9a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+/i, // any word characters or numbers | ||
parseTokenTimezone = /Z|[\+\-]\d\d:?\d\d/i, // +00:00 -00:00 +0000 -0000 or Z | ||
parseTokenT = /T/i, // T (ISO seperator) | ||
// preliminary iso regex | ||
// 0000-00-00 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 | ||
isoRegex = /^\s*\d{4}-\d\d-\d\d(T(\d\d(:\d\d(:\d\d(\.\d\d?\d?)?)?)?)?([\+\-]\d\d:?\d\d)?)?/, | ||
isoFormat = 'YYYY-MM-DDTHH:mm:ssZ', | ||
// iso time formats and regexes | ||
isoTimes = [ | ||
['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/] | ||
], | ||
// timezone chunker "+10:00" > ["10", "00"] or "-1530" > ["-15", "30"] | ||
parseTimezoneChunker = /([\+\-]|\d\d)/gi, | ||
// getter and setter names | ||
proxyGettersAndSetters = 'Month|Date|Hours|Minutes|Seconds|Milliseconds'.split('|'), | ||
unitMillisecondFactors = { | ||
'Milliseconds' : 1, | ||
'Seconds' : 1e3, | ||
'Minutes' : 6e4, | ||
'Hours' : 36e5, | ||
'Days' : 864e5, | ||
'Months' : 2592e6, | ||
'Years' : 31536e6 | ||
}; | ||
// Moment prototype object | ||
function Moment(date) { | ||
function Moment(date, isUTC) { | ||
this._d = date; | ||
this._isUTC = !!isUTC; | ||
} | ||
function absRound(number) { | ||
if (number < 0) { | ||
return Math.ceil(number); | ||
} else { | ||
return Math.floor(number); | ||
} | ||
} | ||
// Duration Constructor | ||
function Duration(duration) { | ||
var data = this._data = {}, | ||
years = duration.years || duration.y || 0, | ||
months = duration.months || duration.M || 0, | ||
weeks = duration.weeks || duration.w || 0, | ||
days = duration.days || duration.d || 0, | ||
hours = duration.hours || duration.h || 0, | ||
minutes = duration.minutes || duration.m || 0, | ||
seconds = duration.seconds || duration.s || 0, | ||
milliseconds = duration.milliseconds || duration.ms || 0; | ||
// representation for dateAddRemove | ||
this._milliseconds = milliseconds + | ||
seconds * 1e3 + // 1000 | ||
minutes * 6e4 + // 1000 * 60 | ||
hours * 36e5; // 1000 * 60 * 60 | ||
// Because of dateAddRemove treats 24 hours as different from a | ||
// day when working around DST, we need to store them separately | ||
this._days = days + | ||
weeks * 7; | ||
// It is impossible translate months into days without knowing | ||
// which months you are are talking about, so we have to store | ||
// it separately. | ||
this._months = months + | ||
years * 12; | ||
// The following code bubbles up values, see the tests for | ||
// examples of what that means. | ||
data.milliseconds = milliseconds % 1000; | ||
seconds += absRound(milliseconds / 1000); | ||
data.seconds = seconds % 60; | ||
minutes += absRound(seconds / 60); | ||
data.minutes = minutes % 60; | ||
hours += absRound(minutes / 60); | ||
data.hours = hours % 24; | ||
days += absRound(hours / 24); | ||
days += weeks * 7; | ||
data.days = days % 30; | ||
months += absRound(days / 30); | ||
data.months = months % 12; | ||
years += absRound(months / 12); | ||
data.years = years; | ||
} | ||
// left zero fill a number | ||
@@ -42,30 +146,20 @@ // see http://jsperf.com/left-zero-filling for performance comparison | ||
// helper function for _.addTime and _.subtractTime | ||
function dateAddRemove(date, _input, adding, val) { | ||
var isString = (typeof _input === 'string'), | ||
input = isString ? {} : _input, | ||
ms, d, M, currentDate; | ||
if (isString && val) { | ||
input[_input] = val; | ||
} | ||
ms = (input.ms || input.milliseconds || 0) + | ||
(input.s || input.seconds || 0) * 1e3 + // 1000 | ||
(input.m || input.minutes || 0) * 6e4 + // 1000 * 60 | ||
(input.h || input.hours || 0) * 36e5; // 1000 * 60 * 60 | ||
d = (input.d || input.days || 0) + | ||
(input.w || input.weeks || 0) * 7; | ||
M = (input.M || input.months || 0) + | ||
(input.y || input.years || 0) * 12; | ||
function addOrSubtractDurationFromMoment(mom, duration, isAdding) { | ||
var ms = duration._milliseconds, | ||
d = duration._days, | ||
M = duration._months, | ||
currentDate; | ||
if (ms) { | ||
date.setTime(+date + ms * adding); | ||
mom._d.setTime(+mom + ms * isAdding); | ||
} | ||
if (d) { | ||
date.setDate(date.getDate() + d * adding); | ||
mom.date(mom.date() + d * isAdding); | ||
} | ||
if (M) { | ||
currentDate = date.getDate(); | ||
date.setDate(1); | ||
date.setMonth(date.getMonth() + M * adding); | ||
date.setDate(Math.min(new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate(), currentDate)); | ||
currentDate = mom.date(); | ||
mom.date(1) | ||
.month(mom.month() + M * isAdding) | ||
.date(Math.min(currentDate, mom.daysInMonth())); | ||
} | ||
return date; | ||
} | ||
@@ -87,5 +181,4 @@ | ||
// format date using native date object | ||
function formatDate(date, inputString) { | ||
var m = new Moment(date), | ||
currentMonth = m.month(), | ||
function formatMoment(m, inputString) { | ||
var currentMonth = m.month(), | ||
currentDate = m.date(), | ||
@@ -97,3 +190,4 @@ currentYear = m.year(), | ||
currentSeconds = m.seconds(), | ||
currentZone = m.zone(), | ||
currentMilliseconds = m.milliseconds(), | ||
currentZone = -m.zone(), | ||
ordinal = moment.ordinal, | ||
@@ -165,5 +259,5 @@ meridiem = moment.meridiem; | ||
case 'a' : | ||
return currentHours > 11 ? meridiem.pm : meridiem.am; | ||
return meridiem ? meridiem(currentHours, currentMinutes, false) : (currentHours > 11 ? 'pm' : 'am'); | ||
case 'A' : | ||
return currentHours > 11 ? meridiem.PM : meridiem.AM; | ||
return meridiem ? meridiem(currentHours, currentMinutes, true) : (currentHours > 11 ? 'PM' : 'AM'); | ||
// 24 HOUR | ||
@@ -189,11 +283,14 @@ case 'H' : | ||
return leftZeroFill(currentSeconds, 2); | ||
// MILLISECONDS | ||
case 'S' : | ||
return ~~ (currentMilliseconds / 100); | ||
case 'SS' : | ||
return leftZeroFill(~~(currentMilliseconds / 10), 2); | ||
case 'SSS' : | ||
return leftZeroFill(currentMilliseconds, 3); | ||
// TIMEZONE | ||
case 'zz' : | ||
// depreciating 'zz' fall through to 'z' | ||
case 'z' : | ||
return (date.toString().match(timezoneRegex) || [''])[0].replace(nonuppercaseLetters, ''); | ||
case 'Z' : | ||
return (currentZone > 0 ? '+' : '-') + leftZeroFill(~~(Math.abs(currentZone) / 60), 2) + ':' + leftZeroFill(~~(Math.abs(currentZone) % 60), 2); | ||
return (currentZone < 0 ? '-' : '+') + leftZeroFill(~~(Math.abs(currentZone) / 60), 2) + ':' + leftZeroFill(~~(Math.abs(currentZone) % 60), 2); | ||
case 'ZZ' : | ||
return (currentZone > 0 ? '+' : '-') + leftZeroFill(~~(10 * Math.abs(currentZone) / 6), 4); | ||
return (currentZone < 0 ? '-' : '+') + leftZeroFill(~~(10 * Math.abs(currentZone) / 6), 4); | ||
// LONG DATES | ||
@@ -205,3 +302,3 @@ case 'L' : | ||
case 'LT' : | ||
return formatDate(date, moment.longDateFormat[input]); | ||
return formatMoment(m, moment.longDateFormat[input]); | ||
// DEFAULT | ||
@@ -212,118 +309,160 @@ default : | ||
} | ||
return inputString.replace(charactersToReplace, replaceFunction); | ||
return inputString.replace(formattingTokens, replaceFunction); | ||
} | ||
// date from string and format string | ||
function makeDateFromStringAndFormat(string, format) { | ||
var inArray = [0, 0, 1, 0, 0, 0, 0], | ||
timezoneHours = 0, | ||
timezoneMinutes = 0, | ||
isUsingUTC = false, | ||
inputParts = string.match(inputCharacters), | ||
formatParts = format.match(tokenCharacters), | ||
i, | ||
isPm; | ||
// get the regex to find the next token | ||
function getParseRegexForToken(token) { | ||
switch (token) { | ||
case 'DDDD': | ||
return parseTokenThreeDigits; | ||
case 'YYYY': | ||
return parseTokenFourDigits; | ||
case 'S': | ||
case 'SS': | ||
case 'SSS': | ||
case 'DDD': | ||
return parseTokenOneToThreeDigits; | ||
case 'MMM': | ||
case 'MMMM': | ||
case 'ddd': | ||
case 'dddd': | ||
case 'a': | ||
case 'A': | ||
return parseTokenWord; | ||
case 'Z': | ||
case 'ZZ': | ||
return parseTokenTimezone; | ||
case 'T': | ||
return parseTokenT; | ||
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 parseTokenOneOrTwoDigits; | ||
default : | ||
return new RegExp(token.replace('\\', '')); | ||
} | ||
} | ||
// function to convert string input to date | ||
function addTime(format, input) { | ||
var a; | ||
switch (format) { | ||
// MONTH | ||
case 'M' : | ||
// fall through to MM | ||
case 'MM' : | ||
inArray[1] = ~~input - 1; | ||
break; | ||
case 'MMM' : | ||
// fall through to MMMM | ||
case 'MMMM' : | ||
for (a = 0; a < 12; a++) { | ||
if (moment.monthsParse[a].test(input)) { | ||
inArray[1] = a; | ||
break; | ||
} | ||
// function to convert string input to date | ||
function addTimeToArrayFromToken(token, input, datePartArray, config) { | ||
var a; | ||
//console.log('addTime', format, input); | ||
switch (token) { | ||
// MONTH | ||
case 'M' : // fall through to MM | ||
case 'MM' : | ||
datePartArray[1] = (input == null) ? 0 : ~~input - 1; | ||
break; | ||
case 'MMM' : // fall through to MMMM | ||
case 'MMMM' : | ||
for (a = 0; a < 12; a++) { | ||
if (moment.monthsParse[a].test(input)) { | ||
datePartArray[1] = a; | ||
break; | ||
} | ||
break; | ||
// DAY OF MONTH | ||
case 'D' : | ||
// fall through to DDDD | ||
case 'DD' : | ||
// fall through to DDDD | ||
case 'DDD' : | ||
// fall through to DDDD | ||
case 'DDDD' : | ||
inArray[2] = ~~input; | ||
break; | ||
// YEAR | ||
case 'YY' : | ||
input = ~~input; | ||
inArray[0] = input + (input > 70 ? 1900 : 2000); | ||
break; | ||
case 'YYYY' : | ||
inArray[0] = ~~Math.abs(input); | ||
break; | ||
// AM / PM | ||
case 'a' : | ||
// fall through to A | ||
case 'A' : | ||
isPm = (input.toLowerCase() === 'pm'); | ||
break; | ||
// 24 HOUR | ||
case 'H' : | ||
// fall through to hh | ||
case 'HH' : | ||
// fall through to hh | ||
case 'h' : | ||
// fall through to hh | ||
case 'hh' : | ||
inArray[3] = ~~input; | ||
break; | ||
// MINUTE | ||
case 'm' : | ||
// fall through to mm | ||
case 'mm' : | ||
inArray[4] = ~~input; | ||
break; | ||
// SECOND | ||
case 's' : | ||
// fall through to ss | ||
case 'ss' : | ||
inArray[5] = ~~input; | ||
break; | ||
// TIMEZONE | ||
case 'Z' : | ||
// fall through to ZZ | ||
case 'ZZ' : | ||
isUsingUTC = true; | ||
a = input.match(timezoneParseRegex); | ||
if (a[1]) { | ||
timezoneHours = ~~a[1]; | ||
} | ||
if (a[2]) { | ||
timezoneMinutes = ~~a[2]; | ||
} | ||
// reverse offsets | ||
if (a[0] === '-') { | ||
timezoneHours = -timezoneHours; | ||
timezoneMinutes = -timezoneMinutes; | ||
} | ||
break; | ||
} | ||
break; | ||
// DAY OF MONTH | ||
case 'D' : // fall through to DDDD | ||
case 'DD' : // fall through to DDDD | ||
case 'DDD' : // fall through to DDDD | ||
case 'DDDD' : | ||
datePartArray[2] = ~~input; | ||
break; | ||
// YEAR | ||
case 'YY' : | ||
input = ~~input; | ||
datePartArray[0] = input + (input > 70 ? 1900 : 2000); | ||
break; | ||
case 'YYYY' : | ||
datePartArray[0] = ~~Math.abs(input); | ||
break; | ||
// AM / PM | ||
case 'a' : // fall through to A | ||
case 'A' : | ||
config.isPm = ((input + '').toLowerCase() === 'pm'); | ||
break; | ||
// 24 HOUR | ||
case 'H' : // fall through to hh | ||
case 'HH' : // fall through to hh | ||
case 'h' : // fall through to hh | ||
case 'hh' : | ||
datePartArray[3] = ~~input; | ||
break; | ||
// MINUTE | ||
case 'm' : // fall through to mm | ||
case 'mm' : | ||
datePartArray[4] = ~~input; | ||
break; | ||
// SECOND | ||
case 's' : // fall through to ss | ||
case 'ss' : | ||
datePartArray[5] = ~~input; | ||
break; | ||
// MILLISECOND | ||
case 'S' : | ||
case 'SS' : | ||
case 'SSS' : | ||
datePartArray[6] = ~~ (('0.' + input) * 1000); | ||
break; | ||
// TIMEZONE | ||
case 'Z' : // fall through to ZZ | ||
case 'ZZ' : | ||
config.isUTC = true; | ||
a = (input + '').match(parseTimezoneChunker); | ||
if (a && a[1]) { | ||
config.tzh = ~~a[1]; | ||
} | ||
if (a && a[2]) { | ||
config.tzm = ~~a[2]; | ||
} | ||
// reverse offsets | ||
if (a && a[0] === '+') { | ||
config.tzh = -config.tzh; | ||
config.tzm = -config.tzm; | ||
} | ||
break; | ||
} | ||
for (i = 0; i < formatParts.length; i++) { | ||
addTime(formatParts[i], inputParts[i]); | ||
} | ||
// date from string and format string | ||
function makeDateFromStringAndFormat(string, format) { | ||
var datePartArray = [0, 0, 1, 0, 0, 0, 0], | ||
config = { | ||
tzh : 0, // timezone hour offset | ||
tzm : 0 // timezone minute offset | ||
}, | ||
tokens = format.match(formattingTokens), | ||
i, parsedInput; | ||
for (i = 0; i < tokens.length; i++) { | ||
parsedInput = (getParseRegexForToken(tokens[i]).exec(string) || [])[0]; | ||
string = string.replace(getParseRegexForToken(tokens[i]), ''); | ||
addTimeToArrayFromToken(tokens[i], parsedInput, datePartArray, config); | ||
} | ||
// handle am pm | ||
if (isPm && inArray[3] < 12) { | ||
inArray[3] += 12; | ||
if (config.isPm && datePartArray[3] < 12) { | ||
datePartArray[3] += 12; | ||
} | ||
// if is 12 am, change hours to 0 | ||
if (isPm === false && inArray[3] === 12) { | ||
inArray[3] = 0; | ||
if (config.isPm === false && datePartArray[3] === 12) { | ||
datePartArray[3] = 0; | ||
} | ||
// handle timezone | ||
inArray[3] += timezoneHours; | ||
inArray[4] += timezoneMinutes; | ||
datePartArray[3] += config.tzh; | ||
datePartArray[4] += config.tzm; | ||
// return | ||
return isUsingUTC ? new Date(Date.UTC.apply({}, inArray)) : dateFromArray(inArray); | ||
return config.isUTC ? new Date(Date.UTC.apply({}, datePartArray)) : dateFromArray(datePartArray); | ||
} | ||
@@ -348,14 +487,15 @@ | ||
var output, | ||
inputParts = string.match(inputCharacters), | ||
scores = [], | ||
inputParts = string.match(parseMultipleFormatChunker) || [], | ||
formattedInputParts, | ||
scoreToBeat = 99, | ||
i, | ||
curDate, | ||
curScore; | ||
currentDate, | ||
currentScore; | ||
for (i = 0; i < formats.length; i++) { | ||
curDate = makeDateFromStringAndFormat(string, formats[i]); | ||
curScore = compareArrays(inputParts, formatDate(curDate, formats[i]).match(inputCharacters)); | ||
if (curScore < scoreToBeat) { | ||
scoreToBeat = curScore; | ||
output = curDate; | ||
currentDate = makeDateFromStringAndFormat(string, formats[i]); | ||
formattedInputParts = formatMoment(new Moment(currentDate), formats[i]).match(parseMultipleFormatChunker) || []; | ||
currentScore = compareArrays(inputParts, formattedInputParts); | ||
if (currentScore < scoreToBeat) { | ||
scoreToBeat = currentScore; | ||
output = currentDate; | ||
} | ||
@@ -366,10 +506,60 @@ } | ||
// date from iso format | ||
function makeDateFromString(string) { | ||
var format = 'YYYY-MM-DDT', | ||
i; | ||
if (isoRegex.exec(string)) { | ||
for (i = 0; i < 4; i++) { | ||
if (isoTimes[i][1].exec(string)) { | ||
format += isoTimes[i][0]; | ||
break; | ||
} | ||
} | ||
return parseTokenTimezone.exec(string) ? | ||
makeDateFromStringAndFormat(string, format + ' Z') : | ||
makeDateFromStringAndFormat(string, format); | ||
} | ||
return new Date(string); | ||
} | ||
// helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize | ||
function substituteTimeAgo(string, number, withoutSuffix, isFuture) { | ||
var rt = moment.relativeTime[string]; | ||
return (typeof rt === 'function') ? | ||
rt(number || 1, !!withoutSuffix, string, isFuture) : | ||
rt.replace(/%d/i, number || 1); | ||
} | ||
function relativeTime(milliseconds, withoutSuffix) { | ||
var seconds = round(Math.abs(milliseconds) / 1000), | ||
minutes = round(seconds / 60), | ||
hours = round(minutes / 60), | ||
days = round(hours / 24), | ||
years = round(days / 365), | ||
args = seconds < 45 && ['s', seconds] || | ||
minutes === 1 && ['m'] || | ||
minutes < 45 && ['mm', minutes] || | ||
hours === 1 && ['h'] || | ||
hours < 22 && ['hh', hours] || | ||
days === 1 && ['d'] || | ||
days <= 25 && ['dd', days] || | ||
days <= 45 && ['M'] || | ||
days < 345 && ['MM', round(days / 30)] || | ||
years === 1 && ['y'] || ['yy', years]; | ||
args[2] = withoutSuffix; | ||
args[3] = milliseconds > 0; | ||
return substituteTimeAgo.apply({}, args); | ||
} | ||
moment = function (input, format) { | ||
if (input === null) { | ||
if (input === null || input === '') { | ||
return null; | ||
} | ||
var date; | ||
// parse UnderscoreDate object | ||
if (input && input._d instanceof Date) { | ||
var date, | ||
matched, | ||
isUTC; | ||
// parse Moment object | ||
if (moment.isMoment(input)) { | ||
date = new Date(+input._d); | ||
isUTC = input._isUTC; | ||
// parse string and format | ||
@@ -382,21 +572,67 @@ } else if (format) { | ||
} | ||
// parse everything else | ||
// evaluate it as a JSON-encoded date | ||
} else { | ||
matched = aspNetJsonRegex.exec(input); | ||
date = input === undefined ? new Date() : | ||
matched ? new Date(+matched[1]) : | ||
input instanceof Date ? input : | ||
isArray(input) ? dateFromArray(input) : | ||
typeof input === 'string' ? makeDateFromString(input) : | ||
new Date(input); | ||
} | ||
return new Moment(date); | ||
return new Moment(date, isUTC); | ||
}; | ||
// creating with utc | ||
moment.utc = function (input, format) { | ||
if (isArray(input)) { | ||
return new Moment(new Date(Date.UTC.apply({}, input)), true); | ||
} | ||
return (format && input) ? | ||
moment(input + ' +0000', format + ' Z').utc() : | ||
moment(input && !parseTokenTimezone.exec(input) ? input + '+0000' : input).utc(); | ||
}; | ||
// creating with unix timestamp (in seconds) | ||
moment.unix = function (input) { | ||
return moment(input * 1000); | ||
}; | ||
// duration | ||
moment.duration = function (input, key) { | ||
var isDuration = moment.isDuration(input), | ||
isNumber = (typeof input === 'number'), | ||
duration = (isDuration ? input._data : (isNumber ? {} : input)); | ||
if (isNumber) { | ||
if (key) { | ||
duration[key] = input; | ||
} else { | ||
duration.milliseconds = input; | ||
} | ||
} | ||
return new Duration(duration); | ||
}; | ||
// humanizeDuration | ||
// This method is deprecated in favor of the new Duration object. Please | ||
// see the moment.duration method. | ||
moment.humanizeDuration = function (num, type, withSuffix) { | ||
return moment.duration(num, type === true ? null : type).humanize(type === true ? true : withSuffix); | ||
}; | ||
// version number | ||
moment.version = VERSION; | ||
// default format | ||
moment.defaultFormat = isoFormat; | ||
// language switching and caching | ||
moment.lang = function (key, values) { | ||
var i, | ||
param, | ||
req, | ||
var i, req, | ||
parse = []; | ||
if (!key) { | ||
return currentLanguage; | ||
} | ||
if (values) { | ||
@@ -410,6 +646,7 @@ for (i = 0; i < 12; i++) { | ||
if (languages[key]) { | ||
for (i = 0; i < paramsToParse.length; i++) { | ||
param = paramsToParse[i]; | ||
moment[param] = languages[key][param] || moment[param]; | ||
for (i = 0; i < langConfigProperties.length; i++) { | ||
moment[langConfigProperties[i]] = languages[key][langConfigProperties[i]] || | ||
languages.en[langConfigProperties[i]]; | ||
} | ||
currentLanguage = key; | ||
} else { | ||
@@ -436,8 +673,3 @@ if (hasModule) { | ||
}, | ||
meridiem : { | ||
AM : 'AM', | ||
am : 'am', | ||
PM : 'PM', | ||
pm : 'pm' | ||
}, | ||
meridiem : false, | ||
calendar : { | ||
@@ -475,29 +707,11 @@ sameDay : '[Today at] LT', | ||
// helper function for _date.from() and _date.fromNow() | ||
function substituteTimeAgo(string, number, withoutSuffix) { | ||
var rt = moment.relativeTime[string]; | ||
return (typeof rt === 'function') ? | ||
rt(number || 1, !!withoutSuffix, string) : | ||
rt.replace(/%d/i, number || 1); | ||
} | ||
// compare moment object | ||
moment.isMoment = function (obj) { | ||
return obj instanceof Moment; | ||
}; | ||
function relativeTime(milliseconds, withoutSuffix) { | ||
var seconds = round(Math.abs(milliseconds) / 1000), | ||
minutes = round(seconds / 60), | ||
hours = round(minutes / 60), | ||
days = round(hours / 24), | ||
years = round(days / 365), | ||
args = seconds < 45 && ['s', seconds] || | ||
minutes === 1 && ['m'] || | ||
minutes < 45 && ['mm', minutes] || | ||
hours === 1 && ['h'] || | ||
hours < 22 && ['hh', hours] || | ||
days === 1 && ['d'] || | ||
days <= 25 && ['dd', days] || | ||
days <= 45 && ['M'] || | ||
days < 345 && ['MM', round(days / 30)] || | ||
years === 1 && ['y'] || ['yy', years]; | ||
args[2] = withoutSuffix; | ||
return substituteTimeAgo.apply({}, args); | ||
} | ||
// for typechecking Duration objects | ||
moment.isDuration = function (obj) { | ||
return obj instanceof Duration; | ||
}; | ||
@@ -515,4 +729,4 @@ // shortcut for prototype | ||
'native' : function () { | ||
return this._d; | ||
unix : function () { | ||
return Math.floor(+this._d / 1000); | ||
}, | ||
@@ -528,8 +742,19 @@ | ||
utc : function () { | ||
this._isUTC = true; | ||
return this; | ||
}, | ||
local : function () { | ||
this._isUTC = false; | ||
return this; | ||
}, | ||
format : function (inputString) { | ||
return formatDate(this._d, inputString); | ||
return formatMoment(this, inputString ? inputString : moment.defaultFormat); | ||
}, | ||
add : function (input, val) { | ||
this._d = dateAddRemove(this._d, input, 1, val); | ||
var dur = val ? moment.duration(+val, input) : moment.duration(input); | ||
addOrSubtractDurationFromMoment(this, dur, 1); | ||
return this; | ||
@@ -539,3 +764,4 @@ }, | ||
subtract : function (input, val) { | ||
this._d = dateAddRemove(this._d, input, -1, val); | ||
var dur = val ? moment.duration(+val, input) : moment.duration(input); | ||
addOrSubtractDurationFromMoment(this, dur, -1); | ||
return this; | ||
@@ -545,12 +771,13 @@ }, | ||
diff : function (input, val, asFloat) { | ||
var inputMoment = moment(input), | ||
diff = this._d - inputMoment._d, | ||
var inputMoment = this._isUTC ? moment(input).utc() : moment(input).local(), | ||
zoneDiff = (this.zone() - inputMoment.zone()) * 6e4, | ||
diff = this._d - inputMoment._d - zoneDiff, | ||
year = this.year() - inputMoment.year(), | ||
month = this.month() - inputMoment.month(), | ||
day = this.day() - inputMoment.day(), | ||
date = this.date() - inputMoment.date(), | ||
output; | ||
if (val === 'months') { | ||
output = year * 12 + month + day / 30; | ||
output = year * 12 + month + date / 30; | ||
} else if (val === 'years') { | ||
output = year + month / 12; | ||
output = year + (month + date / 30) / 12; | ||
} else { | ||
@@ -562,3 +789,3 @@ output = val === 'seconds' ? diff / 1e3 : // 1000 | ||
val === 'weeks' ? diff / 6048e5 : // 1000 * 60 * 60 * 24 * 7 | ||
val === 'days' ? diff / 3600 : diff; | ||
diff; | ||
} | ||
@@ -569,6 +796,3 @@ return asFloat ? output : round(output); | ||
from : function (time, withoutSuffix) { | ||
var difference = this.diff(time), | ||
rel = moment.relativeTime, | ||
output = relativeTime(difference, withoutSuffix); | ||
return withoutSuffix ? output : (difference <= 0 ? rel.past : rel.future).replace(/%s/i, output); | ||
return moment.duration(this.diff(time)).humanize(!withoutSuffix); | ||
}, | ||
@@ -581,5 +805,3 @@ | ||
calendar : function () { | ||
var today = moment(), | ||
todayAtZeroHour = moment([today.year(), today.month(), today.date()]), | ||
diff = this.diff(todayAtZeroHour, 'days', true), | ||
var diff = this.diff(moment().sod(), 'days', true), | ||
calendar = moment.calendar, | ||
@@ -602,9 +824,34 @@ allElse = calendar.sameElse, | ||
isDST : function () { | ||
return this.zone() !== moment([this.year()]).zone(); | ||
return (this.zone() < moment([this.year()]).zone() || | ||
this.zone() < moment([this.year(), 5]).zone()); | ||
}, | ||
day : function (input) { | ||
var day = this._d.getDay(); | ||
var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay(); | ||
return input == null ? day : | ||
this.add({ d : input - day }); | ||
}, | ||
sod: function () { | ||
return moment(this) | ||
.hours(0) | ||
.minutes(0) | ||
.seconds(0) | ||
.milliseconds(0); | ||
}, | ||
eod: function () { | ||
// end of day = start of day plus 1 day, minus 1 millisecond | ||
return this.sod().add({ | ||
d : 1, | ||
ms : -1 | ||
}); | ||
}, | ||
zone : function () { | ||
return this._isUTC ? 0 : this._d.getTimezoneOffset(); | ||
}, | ||
daysInMonth : function () { | ||
return moment(this).month(this.month() + 1).date(0).date(); | ||
} | ||
@@ -614,9 +861,10 @@ }; | ||
// helper for adding shortcuts | ||
function makeShortcut(name, key) { | ||
function makeGetterAndSetter(name, key) { | ||
moment.fn[name] = function (input) { | ||
var utc = this._isUTC ? 'UTC' : ''; | ||
if (input != null) { | ||
this._d['set' + key](input); | ||
this._d['set' + utc + key](input); | ||
return this; | ||
} else { | ||
return this._d['get' + key](); | ||
return this._d['get' + utc + key](); | ||
} | ||
@@ -627,14 +875,54 @@ }; | ||
// loop through and add shortcuts (Month, Date, Hours, Minutes, Seconds, Milliseconds) | ||
for (i = 0; i < shortcuts.length; i ++) { | ||
makeShortcut(shortcuts[i].toLowerCase(), shortcuts[i]); | ||
for (i = 0; i < proxyGettersAndSetters.length; i ++) { | ||
makeGetterAndSetter(proxyGettersAndSetters[i].toLowerCase(), proxyGettersAndSetters[i]); | ||
} | ||
// add shortcut for year (uses different syntax than the getter/setter 'year' == 'FullYear') | ||
makeShortcut('year', 'FullYear'); | ||
makeGetterAndSetter('year', 'FullYear'); | ||
// add shortcut for timezone offset (no setter) | ||
moment.fn.zone = function () { | ||
return this._d.getTimezoneOffset(); | ||
moment.duration.fn = Duration.prototype = { | ||
weeks : function () { | ||
return absRound(this.days() / 7); | ||
}, | ||
valueOf : function () { | ||
return this._milliseconds + | ||
this._days * 864e5 + | ||
this._months * 2592e6; | ||
}, | ||
humanize : function (withSuffix) { | ||
var difference = +this, | ||
rel = moment.relativeTime, | ||
output = relativeTime(difference, !withSuffix); | ||
if (withSuffix) { | ||
output = (difference <= 0 ? rel.past : rel.future).replace(/%s/i, output); | ||
} | ||
return output; | ||
} | ||
}; | ||
function makeDurationGetter(name) { | ||
moment.duration.fn[name] = function () { | ||
return this._data[name]; | ||
}; | ||
} | ||
function makeDurationAsGetter(name, factor) { | ||
moment.duration.fn['as' + name] = function () { | ||
return +this / factor; | ||
}; | ||
} | ||
for (i in unitMillisecondFactors) { | ||
if (unitMillisecondFactors.hasOwnProperty(i)) { | ||
makeDurationAsGetter(i, unitMillisecondFactors[i]); | ||
makeDurationGetter(i.toLowerCase()); | ||
} | ||
} | ||
makeDurationAsGetter('Weeks', 6048e5); | ||
// CommonJS module is defined | ||
@@ -644,6 +932,12 @@ if (hasModule) { | ||
} | ||
if (typeof window !== 'undefined') { | ||
/*global ender:false */ | ||
if (typeof window !== 'undefined' && typeof ender === 'undefined') { | ||
window.moment = moment; | ||
} | ||
/*global define:false */ | ||
if (typeof define === "function" && define.amd) { | ||
define("moment", [], function () { | ||
return moment; | ||
}); | ||
} | ||
})(Date); |
@@ -1,2 +0,6 @@ | ||
/* Moment.js | version : 1.3.0 | author : Tim Wood | license : MIT */ | ||
(function(a,b){function q(a){this._d=a}function r(a,b){var c=a+"";while(c.length<b)c="0"+c;return c}function s(b,c,d,e){var f=typeof c=="string",g=f?{}:c,h,i,j,k;return f&&e&&(g[c]=e),h=(g.ms||g.milliseconds||0)+(g.s||g.seconds||0)*1e3+(g.m||g.minutes||0)*6e4+(g.h||g.hours||0)*36e5,i=(g.d||g.days||0)+(g.w||g.weeks||0)*7,j=(g.M||g.months||0)+(g.y||g.years||0)*12,h&&b.setTime(+b+h*d),i&&b.setDate(b.getDate()+i*d),j&&(k=b.getDate(),b.setDate(1),b.setMonth(b.getMonth()+j*d),b.setDate(Math.min((new a(b.getFullYear(),b.getMonth()+1,0)).getDate(),k))),b}function t(a){return Object.prototype.toString.call(a)==="[object Array]"}function u(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 v(b,d){function u(d){var e,i;switch(d){case"M":return f+1;case"Mo":return f+1+s(f+1);case"MM":return r(f+1,2);case"MMM":return c.monthsShort[f];case"MMMM":return c.months[f];case"D":return g;case"Do":return g+s(g);case"DD":return r(g,2);case"DDD":return e=new a(h,f,g),i=new a(h,0,1),~~((e-i)/864e5+1.5);case"DDDo":return e=u("DDD"),e+s(e);case"DDDD":return r(u("DDD"),3);case"d":return l;case"do":return l+s(l);case"ddd":return c.weekdaysShort[l];case"dddd":return c.weekdays[l];case"w":return e=new a(h,f,g-l+5),i=new a(e.getFullYear(),0,4),~~((e-i)/864e5/7+1.5);case"wo":return e=u("w"),e+s(e);case"ww":return r(u("w"),2);case"YY":return r(h%100,2);case"YYYY":return h;case"a":return m>11?t.pm:t.am;case"A":return m>11?t.PM:t.AM;case"H":return m;case"HH":return r(m,2);case"h":return m%12||12;case"hh":return r(m%12||12,2);case"m":return n;case"mm":return r(n,2);case"s":return o;case"ss":return r(o,2);case"zz":case"z":return(b.toString().match(k)||[""])[0].replace(j,"");case"Z":return(p>0?"+":"-")+r(~~(Math.abs(p)/60),2)+":"+r(~~(Math.abs(p)%60),2);case"ZZ":return(p>0?"+":"-")+r(~~(10*Math.abs(p)/6),4);case"L":case"LL":case"LLL":case"LLLL":case"LT":return v(b,c.longDateFormat[d]);default:return d.replace(/(^\[)|(\\)|\]$/g,"")}}var e=new q(b),f=e.month(),g=e.date(),h=e.year(),l=e.day(),m=e.hours(),n=e.minutes(),o=e.seconds(),p=e.zone(),s=c.ordinal,t=c.meridiem;return d.replace(i,u)}function w(b,d){function p(a,b){var d;switch(a){case"M":case"MM":e[1]=~~b-1;break;case"MMM":case"MMMM":for(d=0;d<12;d++)if(c.monthsParse[d].test(b)){e[1]=d;break}break;case"D":case"DD":case"DDD":case"DDDD":e[2]=~~b;break;case"YY":b=~~b,e[0]=b+(b>70?1900:2e3);break;case"YYYY":e[0]=~~Math.abs(b);break;case"a":case"A":o=b.toLowerCase()==="pm";break;case"H":case"HH":case"h":case"hh":e[3]=~~b;break;case"m":case"mm":e[4]=~~b;break;case"s":case"ss":e[5]=~~b;break;case"Z":case"ZZ":h=!0,d=b.match(n),d[1]&&(f=~~d[1]),d[2]&&(g=~~d[2]),d[0]==="-"&&(f=-f,g=-g)}}var e=[0,0,1,0,0,0,0],f=0,g=0,h=!1,i=b.match(m),j=d.match(l),k,o;for(k=0;k<j.length;k++)p(j[k],i[k]);return o&&e[3]<12&&(e[3]+=12),o===!1&&e[3]===12&&(e[3]=0),e[3]+=f,e[4]+=g,h?new a(a.UTC.apply({},e)):u(e)}function x(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 y(a,b){var c,d=a.match(m),e=[],f=99,g,h,i;for(g=0;g<b.length;g++)h=w(a,b[g]),i=x(d,v(h,b[g]).match(m)),i<f&&(f=i,c=h);return c}function z(a,b,d){var e=c.relativeTime[a];return typeof e=="function"?e(b||1,!!d,a):e.replace(/%d/i,b||1)}function A(a,b){var c=d(Math.abs(a)/1e3),e=d(c/60),f=d(e/60),g=d(f/24),h=d(g/365),i=c<45&&["s",c]||e===1&&["m"]||e<45&&["mm",e]||f===1&&["h"]||f<22&&["hh",f]||g===1&&["d"]||g<=25&&["dd",g]||g<=45&&["M"]||g<345&&["MM",d(g/30)]||h===1&&["y"]||["yy",h];return i[2]=b,z.apply({},i)}function B(a,b){c.fn[a]=function(a){return a!=null?(this._d["set"+b](a),this):this._d["get"+b]()}}var c,d=Math.round,e={},f=typeof module!="undefined",g="months|monthsShort|monthsParse|weekdays|weekdaysShort|longDateFormat|calendar|relativeTime|ordinal|meridiem".split("|"),h,i=/(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|dddd?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|zz?|ZZ?|LT|LL?L?L?)/g,j=/[^A-Z]/g,k=/\([A-Za-z ]+\)|:[0-9]{2} [A-Z]{3} /g,l=/(\\)?(MM?M?M?|dd?d?d|DD?D?D?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|ZZ?|T)/g,m=/(\\)?([0-9]+|([a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+|([\+\-]\d\d:?\d\d))/gi,n=/([\+\-]|\d\d)/gi,o="1.3.0",p="Month|Date|Hours|Minutes|Seconds|Milliseconds".split("|");c=function(c,d){if(c===null)return null;var e;return c&&c._d instanceof a?e=new a(+c._d):d?t(d)?e=y(c,d):e=w(c,d):e=c===b?new a:c instanceof a?c:t(c)?u(c):new a(c),new q(e)},c.version=o,c.lang=function(a,b){var d,h,i,j=[];if(b){for(d=0;d<12;d++)j[d]=new RegExp("^"+b.months[d]+"|^"+b.monthsShort[d].replace(".",""),"i");b.monthsParse=b.monthsParse||j,e[a]=b}if(e[a])for(d=0;d<g.length;d++)h=g[d],c[h]=e[a][h]||c[h];else f&&(i=require("./lang/"+a),c.lang(a,i))},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:{AM:"AM",am:"am",PM:"PM",pm:"pm"},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.fn=q.prototype={clone:function(){return c(this)},valueOf:function(){return+this._d},"native":function(){return this._d},toString:function(){return this._d.toString()},toDate:function(){return this._d},format:function(a){return v(this._d,a)},add:function(a,b){return this._d=s(this._d,a,1,b),this},subtract:function(a,b){return this._d=s(this._d,a,-1,b),this},diff:function(a,b,e){var f=c(a),g=this._d-f._d,h=this.year()-f.year(),i=this.month()-f.month(),j=this.day()-f.day(),k;return b==="months"?k=h*12+i+j/30:b==="years"?k=h+i/12:k=b==="seconds"?g/1e3:b==="minutes"?g/6e4:b==="hours"?g/36e5:b==="days"?g/864e5:b==="weeks"?g/6048e5:b==="days"?g/3600:g,e?k:d(k)},from:function(a,b){var d=this.diff(a),e=c.relativeTime,f=A(d,b);return b?f:(d<=0?e.past:e.future).replace(/%s/i,f)},fromNow:function(a){return this.from(c(),a)},calendar:function(){var a=c(),b=c([a.year(),a.month(),a.date()]),d=this.diff(b,"days",!0),e=c.calendar,f=e.sameElse,g=d<-6?f:d<-1?e.lastWeek:d<0?e.lastDay:d<1?e.sameDay:d<2?e.nextDay:d<7?e.nextWeek:f;return this.format(typeof g=="function"?g.apply(this):g)},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()},day:function(a){var b=this._d.getDay();return a==null?b:this.add({d:a-b})}};for(h=0;h<p.length;h++)B(p[h].toLowerCase(),p[h]);B("year","FullYear"),c.fn.zone=function(){return this._d.getTimezoneOffset()},f&&(module.exports=c),typeof window!="undefined"&&(window.moment=c)})(Date) | ||
// moment.js | ||
// version : 1.6.2 | ||
// 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})},sod:function(){return c(this).hours(0).minutes(0).seconds(0).milliseconds(0)},eod:function(){return this.sod().add({d:1,ms:-1})},zone:function(){return this._isUTC?0:this._d.getTimezoneOffset()},daysInMonth:function(){return c(this).month(this.month()+1).date(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); |
105
bin/twix.js
@@ -0,3 +1,4 @@ | ||
// Generated by CoffeeScript 1.3.3 | ||
(function() { | ||
var Twix, datePart, extend, moment; | ||
var Twix, extend, moment; | ||
@@ -10,3 +11,5 @@ if (typeof module !== "undefined") { | ||
if (typeof moment === "undefined") throw "Can't find moment"; | ||
if (typeof moment === "undefined") { | ||
throw "Can't find moment"; | ||
} | ||
@@ -18,3 +21,3 @@ Twix = (function() { | ||
this.end = moment(end); | ||
this.allDay = allDay; | ||
this.allDay = allDay || false; | ||
} | ||
@@ -32,15 +35,16 @@ | ||
var endDate, startDate; | ||
startDate = datePart(this.start); | ||
endDate = datePart(this.end); | ||
startDate = this.start.sod(); | ||
endDate = this.end.sod(); | ||
return endDate.diff(startDate, 'days') + 1; | ||
}; | ||
Twix.prototype.daysIn = function(each) { | ||
var endDate, iter; | ||
iter = datePart(this.start); | ||
endDate = datePart(this.end); | ||
Twix.prototype.daysIn = function(minHours) { | ||
var endDate, iter, | ||
_this = this; | ||
iter = this.start.sod(); | ||
endDate = this.end.sod(); | ||
return { | ||
next: function() { | ||
var val; | ||
if (iter > endDate) { | ||
if (iter > endDate || (minHours && iter.valueOf() === endDate.valueOf() && _this.end.hours() < minHours)) { | ||
return null; | ||
@@ -54,3 +58,3 @@ } else { | ||
hasNext: function() { | ||
return iter <= endDate; | ||
return iter <= endDate && (!minHours || iter.valueOf() !== endDate.valueOf() || _this.end.hours() > minHours); | ||
} | ||
@@ -72,4 +76,53 @@ }; | ||
Twix.prototype.past = function() { | ||
if (this.allDay) { | ||
return this.end.eod() < moment(); | ||
} else { | ||
return this.end < moment(); | ||
} | ||
}; | ||
Twix.prototype.overlaps = function(other) { | ||
return !(this.trueEnd() < other.trueStart() || this.trueStart() > other.trueEnd()); | ||
}; | ||
Twix.prototype.engulfs = function(other) { | ||
return this.trueStart() <= other.trueStart() && this.trueEnd() >= other.trueEnd(); | ||
}; | ||
Twix.prototype.merge = function(other) { | ||
var allDay, newEnd, newStart; | ||
allDay = this.allDay && other.allDay; | ||
if (allDay) { | ||
newStart = this.start < other.start ? this.start : other.start; | ||
newEnd = this.end > other.end ? this.end : other.end; | ||
} else { | ||
newStart = this.trueStart() < other.trueStart() ? this.trueStart() : other.trueStart(); | ||
newEnd = this.trueEnd() > other.trueEnd() ? this.trueEnd() : other.trueEnd(); | ||
} | ||
return new Twix(newStart, newEnd, allDay); | ||
}; | ||
Twix.prototype.trueStart = function() { | ||
if (this.allDay) { | ||
return this.start.sod(); | ||
} else { | ||
return this.start; | ||
} | ||
}; | ||
Twix.prototype.trueEnd = function() { | ||
if (this.allDay) { | ||
return this.end.eod(); | ||
} else { | ||
return this.end; | ||
} | ||
}; | ||
Twix.prototype.equals = function(other) { | ||
return (other instanceof Twix) && this.allDay === other.allDay && this.start.valueOf() === other.start.valueOf() && this.end.valueOf() === other.end.valueOf(); | ||
}; | ||
Twix.prototype.format = function(inopts) { | ||
var common_bucket, end_bucket, fold, format, fs, global_first, needDate, options, process, start_bucket, together, _i, _len, | ||
var common_bucket, end_bucket, fold, format, fs, global_first, goesIntoTheMorning, needDate, options, process, start_bucket, together, _i, _len, | ||
_this = this; | ||
@@ -90,3 +143,5 @@ options = { | ||
minuteFormat: "mm", | ||
allDay: "all day" | ||
allDay: "all day", | ||
explicitAllDay: false, | ||
lastNightEndsAt: 0 | ||
}; | ||
@@ -98,4 +153,5 @@ extend(options, inopts || {}); | ||
} | ||
needDate = options.showDate || !this.sameDay(); | ||
if (this.allDay && this.sameDay() && !options.showDate) { | ||
goesIntoTheMorning = options.lastNightEndsAt > 0 && !this.allDay && this.end.sod().valueOf() === this.start.clone().add('days', 1).sod().valueOf() && this.start.hours() > 12 && this.end.hours() < options.lastNightEndsAt; | ||
needDate = options.showDate || (!this.sameDay() && !goesIntoTheMorning); | ||
if (this.allDay && this.sameDay() && (!options.showDate || options.explicitAllDay)) { | ||
fs.push({ | ||
@@ -126,2 +182,5 @@ name: "all day simple", | ||
}, | ||
ignoreEnd: function() { | ||
return goesIntoTheMorning; | ||
}, | ||
slot: 2, | ||
@@ -178,3 +237,5 @@ pre: " " | ||
if (!options.groupMeridiems && !options.twentyFourHour) { | ||
if (options.spaceBeforeMeridiem) str += " "; | ||
if (options.spaceBeforeMeridiem) { | ||
str += " "; | ||
} | ||
str += date.format(options.meridiemFormat); | ||
@@ -195,3 +256,3 @@ } | ||
start_str = format.fn(_this.start); | ||
end_str = format.fn(_this.end); | ||
end_str = format.ignoreEnd && format.ignoreEnd() ? start_str : format.fn(_this.end); | ||
start_group = { | ||
@@ -229,7 +290,7 @@ format: format, | ||
format = fs[_i]; | ||
if (format.skip !== true) process(format); | ||
process(format); | ||
} | ||
global_first = true; | ||
fold = function(array, skip_pre) { | ||
var local_first, section, str, _j, _len2, _ref; | ||
var local_first, section, str, _j, _len1, _ref; | ||
local_first = true; | ||
@@ -240,3 +301,3 @@ str = ""; | ||
}); | ||
for (_j = 0, _len2 = _ref.length; _j < _len2; _j++) { | ||
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { | ||
section = _ref[_j]; | ||
@@ -276,6 +337,2 @@ if (!global_first) { | ||
datePart = function(moment) { | ||
return moment.clone().hours(0).minutes(0).seconds(0).milliseconds(0); | ||
}; | ||
if (typeof module !== "undefined") { | ||
@@ -282,0 +339,0 @@ module.exports = Twix; |
@@ -1,1 +0,2 @@ | ||
((function(){var a,b,c,d;typeof module!="undefined"?d=require("moment"):d=window.moment;if(typeof d=="undefined")throw"Can't find moment";a=function(){function a(a,b,c){this.start=d(a),this.end=d(b),this.allDay=c}return a.prototype.sameDay=function(){return this.start.year()===this.end.year()&&this.start.month()===this.end.month()&&this.start.date()===this.end.date()},a.prototype.sameYear=function(){return this.start.year()===this.end.year()},a.prototype.countDays=function(){var a,c;return c=b(this.start),a=b(this.end),a.diff(c,"days")+1},a.prototype.daysIn=function(a){var c,d;return d=b(this.start),c=b(this.end),{next:function(){var a;return d>c?null:(a=d.clone(),d.add("days",1),a)},hasNext:function(){return d<=c}}},a.prototype.duration=function(){return this.allDay?this.sameDay()?"all day":this.start.from(this.end.clone().add("days",1),!0):this.start.from(this.end,!0)},a.prototype.format=function(a){var b,e,f,g,h,i,j,k,l,m,n,o,p,q=this;k={groupMeridiems:!0,spaceBeforeMeridiem:!0,showDate:!0,showDayOfWeek:!1,twentyFourHour:!1,implicitMinutes:!0,yearFormat:"YYYY",monthFormat:"MMM",weekdayFormat:"ddd",dayFormat:"D",meridiemFormat:"A",hourFormat:"h",minuteFormat:"mm",allDay:"all day"},c(k,a||{}),h=[],k.twentyFourHour&&(k.hourFormat=k.hourFormat.replace("h","H")),j=k.showDate||!this.sameDay(),this.allDay&&this.sameDay()&&!k.showDate&&h.push({name:"all day simple",fn:function(){return k.allDay},slot:0,pre:" "}),j&&(this.start.year()!==d().year()||!this.sameYear())&&h.push({name:"year",fn:function(a){return a.format(k.yearFormat)},pre:", ",slot:4}),!this.allDay&&j&&h.push({name:"all day month",fn:function(a){return a.format(""+k.monthFormat+" "+k.dayFormat)},slot:2,pre:" "}),this.allDay&&j&&h.push({name:"month",fn:function(a){return a.format("MMM")},slot:2,pre:" "}),this.allDay&&j&&h.push({name:"date",fn:function(a){return a.format(k.dayFormat)},slot:3,pre:" "}),j&&k.showDayOfWeek&&h.push({name:"day of week",fn:function(a){return a.format(k.weekdayFormat)},pre:" ",slot:1}),k.groupMeridiems&&!k.twentyFourHour&&!this.allDay&&h.push({name:"meridiem",fn:function(a){return a.format(k.meridiemFormat)},slot:6,pre:k.spaceBeforeMeridiem?" ":""}),this.allDay||h.push({name:"time",fn:function(a){var b;return b=a.minutes()===0&&k.implicitMinutes&&!k.twentyFourHour?a.format(k.hourFormat):a.format(""+k.hourFormat+":"+k.minuteFormat),!k.groupMeridiems&&!k.twentyFourHour&&(k.spaceBeforeMeridiem&&(b+=" "),b+=a.format(k.meridiemFormat)),b},pre:", ",slot:5}),m=[],e=[],b=[],n=!0,l=function(a){var c,d,g;return g=a.fn(q.start),c=a.fn(q.end),d={format:a,value:function(){return g}},c===g&&n?b.push(d):(n&&(n=!1,b.push({format:{slot:a.slot,pre:""},value:function(){return""+f(m)+" -"+f(e,!0)}})),m.push(d),e.push({format:a,value:function(){return c}}))};for(o=0,p=h.length;o<p;o++)g=h[o],g.skip!==!0&&l(g);return i=!0,f=function(a,b){var c,d,e,f,g,h;c=!0,e="",h=a.sort(function(a,b){return a.format.slot-b.format.slot});for(f=0,g=h.length;f<g;f++)d=h[f],i||(c&&b?e+=" ":e+=d.format.pre),e+=d.value(),i=!1,c=!1;return e},f(b)},a}(),c=function(a,b){var c,d;d=[];for(c in b)typeof b[c]!="undefined"?d.push(a[c]=b[c]):d.push(void 0);return d},b=function(a){return a.clone().hours(0).minutes(0).seconds(0).milliseconds(0)},typeof module!="undefined"?module.exports=a:window.Twix=a})).call(this); | ||
// Generated by CoffeeScript 1.3.3 | ||
((function(){var a,b,c;typeof module!="undefined"?c=require("moment"):c=window.moment;if(typeof c=="undefined")throw"Can't find moment";a=function(){function a(a,b,d){this.start=c(a),this.end=c(b),this.allDay=d||!1}return a.prototype.sameDay=function(){return this.start.year()===this.end.year()&&this.start.month()===this.end.month()&&this.start.date()===this.end.date()},a.prototype.sameYear=function(){return this.start.year()===this.end.year()},a.prototype.countDays=function(){var a,b;return b=this.start.sod(),a=this.end.sod(),a.diff(b,"days")+1},a.prototype.daysIn=function(a){var b,c,d=this;return c=this.start.sod(),b=this.end.sod(),{next:function(){var e;return c>b||a&&c.valueOf()===b.valueOf()&&d.end.hours()<a?null:(e=c.clone(),c.add("days",1),e)},hasNext:function(){return c<=b&&(!a||c.valueOf()!==b.valueOf()||d.end.hours()>a)}}},a.prototype.duration=function(){return this.allDay?this.sameDay()?"all day":this.start.from(this.end.clone().add("days",1),!0):this.start.from(this.end,!0)},a.prototype.past=function(){return this.allDay?this.end.eod()<c():this.end<c()},a.prototype.overlaps=function(a){return!(this.trueEnd()<a.trueStart()||this.trueStart()>a.trueEnd())},a.prototype.engulfs=function(a){return this.trueStart()<=a.trueStart()&&this.trueEnd()>=a.trueEnd()},a.prototype.merge=function(b){var c,d,e;return c=this.allDay&&b.allDay,c?(e=this.start<b.start?this.start:b.start,d=this.end>b.end?this.end:b.end):(e=this.trueStart()<b.trueStart()?this.trueStart():b.trueStart(),d=this.trueEnd()>b.trueEnd()?this.trueEnd():b.trueEnd()),new a(e,d,c)},a.prototype.trueStart=function(){return this.allDay?this.start.sod():this.start},a.prototype.trueEnd=function(){return this.allDay?this.end.eod():this.end},a.prototype.equals=function(b){return b instanceof a&&this.allDay===b.allDay&&this.start.valueOf()===b.start.valueOf()&&this.end.valueOf()===b.end.valueOf()},a.prototype.format=function(a){var d,e,f,g,h,i,j,k,l,m,n,o,p,q,r=this;l={groupMeridiems:!0,spaceBeforeMeridiem:!0,showDate:!0,showDayOfWeek:!1,twentyFourHour:!1,implicitMinutes:!0,yearFormat:"YYYY",monthFormat:"MMM",weekdayFormat:"ddd",dayFormat:"D",meridiemFormat:"A",hourFormat:"h",minuteFormat:"mm",allDay:"all day",explicitAllDay:!1,lastNightEndsAt:0},b(l,a||{}),h=[],l.twentyFourHour&&(l.hourFormat=l.hourFormat.replace("h","H")),j=l.lastNightEndsAt>0&&!this.allDay&&this.end.sod().valueOf()===this.start.clone().add("days",1).sod().valueOf()&&this.start.hours()>12&&this.end.hours()<l.lastNightEndsAt,k=l.showDate||!this.sameDay()&&!j,this.allDay&&this.sameDay()&&(!l.showDate||l.explicitAllDay)&&h.push({name:"all day simple",fn:function(){return l.allDay},slot:0,pre:" "}),k&&(this.start.year()!==c().year()||!this.sameYear())&&h.push({name:"year",fn:function(a){return a.format(l.yearFormat)},pre:", ",slot:4}),!this.allDay&&k&&h.push({name:"all day month",fn:function(a){return a.format(""+l.monthFormat+" "+l.dayFormat)},ignoreEnd:function(){return j},slot:2,pre:" "}),this.allDay&&k&&h.push({name:"month",fn:function(a){return a.format("MMM")},slot:2,pre:" "}),this.allDay&&k&&h.push({name:"date",fn:function(a){return a.format(l.dayFormat)},slot:3,pre:" "}),k&&l.showDayOfWeek&&h.push({name:"day of week",fn:function(a){return a.format(l.weekdayFormat)},pre:" ",slot:1}),l.groupMeridiems&&!l.twentyFourHour&&!this.allDay&&h.push({name:"meridiem",fn:function(a){return a.format(l.meridiemFormat)},slot:6,pre:l.spaceBeforeMeridiem?" ":""}),this.allDay||h.push({name:"time",fn:function(a){var b;return b=a.minutes()===0&&l.implicitMinutes&&!l.twentyFourHour?a.format(l.hourFormat):a.format(""+l.hourFormat+":"+l.minuteFormat),!l.groupMeridiems&&!l.twentyFourHour&&(l.spaceBeforeMeridiem&&(b+=" "),b+=a.format(l.meridiemFormat)),b},pre:", ",slot:5}),n=[],e=[],d=[],o=!0,m=function(a){var b,c,g;return g=a.fn(r.start),b=a.ignoreEnd&&a.ignoreEnd()?g:a.fn(r.end),c={format:a,value:function(){return g}},b===g&&o?d.push(c):(o&&(o=!1,d.push({format:{slot:a.slot,pre:""},value:function(){return""+f(n)+" -"+f(e,!0)}})),n.push(c),e.push({format:a,value:function(){return b}}))};for(p=0,q=h.length;p<q;p++)g=h[p],m(g);return i=!0,f=function(a,b){var c,d,e,f,g,h;c=!0,e="",h=a.sort(function(a,b){return a.format.slot-b.format.slot});for(f=0,g=h.length;f<g;f++)d=h[f],i||(c&&b?e+=" ":e+=d.format.pre),e+=d.value(),i=!1,c=!1;return e},f(d)},a}(),b=function(a,b){var c,d;d=[];for(c in b)typeof b[c]!="undefined"?d.push(a[c]=b[c]):d.push(void 0);return d},typeof module!="undefined"?module.exports=a:window.Twix=a})).call(this); |
@@ -1,7 +0,6 @@ | ||
// Moment.js | ||
// | ||
// (c) 2011 Tim Wood | ||
// Moment.js is freely distributable under the terms of the MIT license. | ||
// | ||
// Version 1.3.0 | ||
// moment.js | ||
// version : 1.6.2 | ||
// author : Tim Wood | ||
// license : MIT | ||
// momentjs.com | ||
@@ -11,21 +10,126 @@ (function (Date, undefined) { | ||
var moment, | ||
round = Math.round, | ||
VERSION = "1.6.2", | ||
round = Math.round, i, | ||
// internal storage for language config files | ||
languages = {}, | ||
currentLanguage = 'en', | ||
// check for nodeJS | ||
hasModule = (typeof module !== 'undefined'), | ||
paramsToParse = 'months|monthsShort|monthsParse|weekdays|weekdaysShort|longDateFormat|calendar|relativeTime|ordinal|meridiem'.split('|'), | ||
i, | ||
charactersToReplace = /(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|dddd?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|zz?|ZZ?|LT|LL?L?L?)/g, | ||
nonuppercaseLetters = /[^A-Z]/g, | ||
timezoneRegex = /\([A-Za-z ]+\)|:[0-9]{2} [A-Z]{3} /g, | ||
tokenCharacters = /(\\)?(MM?M?M?|dd?d?d|DD?D?D?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|ZZ?|T)/g, | ||
inputCharacters = /(\\)?([0-9]+|([a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+|([\+\-]\d\d:?\d\d))/gi, | ||
timezoneParseRegex = /([\+\-]|\d\d)/gi, | ||
VERSION = "1.3.0", | ||
shortcuts = 'Month|Date|Hours|Minutes|Seconds|Milliseconds'.split('|'); | ||
// parameters to check for on the lang config | ||
langConfigProperties = 'months|monthsShort|monthsParse|weekdays|weekdaysShort|longDateFormat|calendar|relativeTime|ordinal|meridiem'.split('|'), | ||
// ASP.NET json date format regex | ||
aspNetJsonRegex = /^\/?Date\((\-?\d+)/i, | ||
// format tokens | ||
formattingTokens = /(\[[^\[]*\])|(\\)?(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, | ||
// parsing tokens | ||
parseMultipleFormatChunker = /([0-9a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)/gi, | ||
// parsing token regexes | ||
parseTokenOneOrTwoDigits = /\d\d?/, // 0 - 99 | ||
parseTokenOneToThreeDigits = /\d{1,3}/, // 0 - 999 | ||
parseTokenThreeDigits = /\d{3}/, // 000 - 999 | ||
parseTokenFourDigits = /\d{4}/, // 0000 - 9999 | ||
parseTokenWord = /[0-9a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+/i, // any word characters or numbers | ||
parseTokenTimezone = /Z|[\+\-]\d\d:?\d\d/i, // +00:00 -00:00 +0000 -0000 or Z | ||
parseTokenT = /T/i, // T (ISO seperator) | ||
// preliminary iso regex | ||
// 0000-00-00 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 | ||
isoRegex = /^\s*\d{4}-\d\d-\d\d(T(\d\d(:\d\d(:\d\d(\.\d\d?\d?)?)?)?)?([\+\-]\d\d:?\d\d)?)?/, | ||
isoFormat = 'YYYY-MM-DDTHH:mm:ssZ', | ||
// iso time formats and regexes | ||
isoTimes = [ | ||
['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/] | ||
], | ||
// timezone chunker "+10:00" > ["10", "00"] or "-1530" > ["-15", "30"] | ||
parseTimezoneChunker = /([\+\-]|\d\d)/gi, | ||
// getter and setter names | ||
proxyGettersAndSetters = 'Month|Date|Hours|Minutes|Seconds|Milliseconds'.split('|'), | ||
unitMillisecondFactors = { | ||
'Milliseconds' : 1, | ||
'Seconds' : 1e3, | ||
'Minutes' : 6e4, | ||
'Hours' : 36e5, | ||
'Days' : 864e5, | ||
'Months' : 2592e6, | ||
'Years' : 31536e6 | ||
}; | ||
// Moment prototype object | ||
function Moment(date) { | ||
function Moment(date, isUTC) { | ||
this._d = date; | ||
this._isUTC = !!isUTC; | ||
} | ||
function absRound(number) { | ||
if (number < 0) { | ||
return Math.ceil(number); | ||
} else { | ||
return Math.floor(number); | ||
} | ||
} | ||
// Duration Constructor | ||
function Duration(duration) { | ||
var data = this._data = {}, | ||
years = duration.years || duration.y || 0, | ||
months = duration.months || duration.M || 0, | ||
weeks = duration.weeks || duration.w || 0, | ||
days = duration.days || duration.d || 0, | ||
hours = duration.hours || duration.h || 0, | ||
minutes = duration.minutes || duration.m || 0, | ||
seconds = duration.seconds || duration.s || 0, | ||
milliseconds = duration.milliseconds || duration.ms || 0; | ||
// representation for dateAddRemove | ||
this._milliseconds = milliseconds + | ||
seconds * 1e3 + // 1000 | ||
minutes * 6e4 + // 1000 * 60 | ||
hours * 36e5; // 1000 * 60 * 60 | ||
// Because of dateAddRemove treats 24 hours as different from a | ||
// day when working around DST, we need to store them separately | ||
this._days = days + | ||
weeks * 7; | ||
// It is impossible translate months into days without knowing | ||
// which months you are are talking about, so we have to store | ||
// it separately. | ||
this._months = months + | ||
years * 12; | ||
// The following code bubbles up values, see the tests for | ||
// examples of what that means. | ||
data.milliseconds = milliseconds % 1000; | ||
seconds += absRound(milliseconds / 1000); | ||
data.seconds = seconds % 60; | ||
minutes += absRound(seconds / 60); | ||
data.minutes = minutes % 60; | ||
hours += absRound(minutes / 60); | ||
data.hours = hours % 24; | ||
days += absRound(hours / 24); | ||
days += weeks * 7; | ||
data.days = days % 30; | ||
months += absRound(days / 30); | ||
data.months = months % 12; | ||
years += absRound(months / 12); | ||
data.years = years; | ||
} | ||
// left zero fill a number | ||
@@ -42,30 +146,20 @@ // see http://jsperf.com/left-zero-filling for performance comparison | ||
// helper function for _.addTime and _.subtractTime | ||
function dateAddRemove(date, _input, adding, val) { | ||
var isString = (typeof _input === 'string'), | ||
input = isString ? {} : _input, | ||
ms, d, M, currentDate; | ||
if (isString && val) { | ||
input[_input] = val; | ||
} | ||
ms = (input.ms || input.milliseconds || 0) + | ||
(input.s || input.seconds || 0) * 1e3 + // 1000 | ||
(input.m || input.minutes || 0) * 6e4 + // 1000 * 60 | ||
(input.h || input.hours || 0) * 36e5; // 1000 * 60 * 60 | ||
d = (input.d || input.days || 0) + | ||
(input.w || input.weeks || 0) * 7; | ||
M = (input.M || input.months || 0) + | ||
(input.y || input.years || 0) * 12; | ||
function addOrSubtractDurationFromMoment(mom, duration, isAdding) { | ||
var ms = duration._milliseconds, | ||
d = duration._days, | ||
M = duration._months, | ||
currentDate; | ||
if (ms) { | ||
date.setTime(+date + ms * adding); | ||
mom._d.setTime(+mom + ms * isAdding); | ||
} | ||
if (d) { | ||
date.setDate(date.getDate() + d * adding); | ||
mom.date(mom.date() + d * isAdding); | ||
} | ||
if (M) { | ||
currentDate = date.getDate(); | ||
date.setDate(1); | ||
date.setMonth(date.getMonth() + M * adding); | ||
date.setDate(Math.min(new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate(), currentDate)); | ||
currentDate = mom.date(); | ||
mom.date(1) | ||
.month(mom.month() + M * isAdding) | ||
.date(Math.min(currentDate, mom.daysInMonth())); | ||
} | ||
return date; | ||
} | ||
@@ -87,5 +181,4 @@ | ||
// format date using native date object | ||
function formatDate(date, inputString) { | ||
var m = new Moment(date), | ||
currentMonth = m.month(), | ||
function formatMoment(m, inputString) { | ||
var currentMonth = m.month(), | ||
currentDate = m.date(), | ||
@@ -97,3 +190,4 @@ currentYear = m.year(), | ||
currentSeconds = m.seconds(), | ||
currentZone = m.zone(), | ||
currentMilliseconds = m.milliseconds(), | ||
currentZone = -m.zone(), | ||
ordinal = moment.ordinal, | ||
@@ -165,5 +259,5 @@ meridiem = moment.meridiem; | ||
case 'a' : | ||
return currentHours > 11 ? meridiem.pm : meridiem.am; | ||
return meridiem ? meridiem(currentHours, currentMinutes, false) : (currentHours > 11 ? 'pm' : 'am'); | ||
case 'A' : | ||
return currentHours > 11 ? meridiem.PM : meridiem.AM; | ||
return meridiem ? meridiem(currentHours, currentMinutes, true) : (currentHours > 11 ? 'PM' : 'AM'); | ||
// 24 HOUR | ||
@@ -189,11 +283,14 @@ case 'H' : | ||
return leftZeroFill(currentSeconds, 2); | ||
// MILLISECONDS | ||
case 'S' : | ||
return ~~ (currentMilliseconds / 100); | ||
case 'SS' : | ||
return leftZeroFill(~~(currentMilliseconds / 10), 2); | ||
case 'SSS' : | ||
return leftZeroFill(currentMilliseconds, 3); | ||
// TIMEZONE | ||
case 'zz' : | ||
// depreciating 'zz' fall through to 'z' | ||
case 'z' : | ||
return (date.toString().match(timezoneRegex) || [''])[0].replace(nonuppercaseLetters, ''); | ||
case 'Z' : | ||
return (currentZone > 0 ? '+' : '-') + leftZeroFill(~~(Math.abs(currentZone) / 60), 2) + ':' + leftZeroFill(~~(Math.abs(currentZone) % 60), 2); | ||
return (currentZone < 0 ? '-' : '+') + leftZeroFill(~~(Math.abs(currentZone) / 60), 2) + ':' + leftZeroFill(~~(Math.abs(currentZone) % 60), 2); | ||
case 'ZZ' : | ||
return (currentZone > 0 ? '+' : '-') + leftZeroFill(~~(10 * Math.abs(currentZone) / 6), 4); | ||
return (currentZone < 0 ? '-' : '+') + leftZeroFill(~~(10 * Math.abs(currentZone) / 6), 4); | ||
// LONG DATES | ||
@@ -205,3 +302,3 @@ case 'L' : | ||
case 'LT' : | ||
return formatDate(date, moment.longDateFormat[input]); | ||
return formatMoment(m, moment.longDateFormat[input]); | ||
// DEFAULT | ||
@@ -212,118 +309,160 @@ default : | ||
} | ||
return inputString.replace(charactersToReplace, replaceFunction); | ||
return inputString.replace(formattingTokens, replaceFunction); | ||
} | ||
// date from string and format string | ||
function makeDateFromStringAndFormat(string, format) { | ||
var inArray = [0, 0, 1, 0, 0, 0, 0], | ||
timezoneHours = 0, | ||
timezoneMinutes = 0, | ||
isUsingUTC = false, | ||
inputParts = string.match(inputCharacters), | ||
formatParts = format.match(tokenCharacters), | ||
i, | ||
isPm; | ||
// get the regex to find the next token | ||
function getParseRegexForToken(token) { | ||
switch (token) { | ||
case 'DDDD': | ||
return parseTokenThreeDigits; | ||
case 'YYYY': | ||
return parseTokenFourDigits; | ||
case 'S': | ||
case 'SS': | ||
case 'SSS': | ||
case 'DDD': | ||
return parseTokenOneToThreeDigits; | ||
case 'MMM': | ||
case 'MMMM': | ||
case 'ddd': | ||
case 'dddd': | ||
case 'a': | ||
case 'A': | ||
return parseTokenWord; | ||
case 'Z': | ||
case 'ZZ': | ||
return parseTokenTimezone; | ||
case 'T': | ||
return parseTokenT; | ||
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 parseTokenOneOrTwoDigits; | ||
default : | ||
return new RegExp(token.replace('\\', '')); | ||
} | ||
} | ||
// function to convert string input to date | ||
function addTime(format, input) { | ||
var a; | ||
switch (format) { | ||
// MONTH | ||
case 'M' : | ||
// fall through to MM | ||
case 'MM' : | ||
inArray[1] = ~~input - 1; | ||
break; | ||
case 'MMM' : | ||
// fall through to MMMM | ||
case 'MMMM' : | ||
for (a = 0; a < 12; a++) { | ||
if (moment.monthsParse[a].test(input)) { | ||
inArray[1] = a; | ||
break; | ||
} | ||
// function to convert string input to date | ||
function addTimeToArrayFromToken(token, input, datePartArray, config) { | ||
var a; | ||
//console.log('addTime', format, input); | ||
switch (token) { | ||
// MONTH | ||
case 'M' : // fall through to MM | ||
case 'MM' : | ||
datePartArray[1] = (input == null) ? 0 : ~~input - 1; | ||
break; | ||
case 'MMM' : // fall through to MMMM | ||
case 'MMMM' : | ||
for (a = 0; a < 12; a++) { | ||
if (moment.monthsParse[a].test(input)) { | ||
datePartArray[1] = a; | ||
break; | ||
} | ||
break; | ||
// DAY OF MONTH | ||
case 'D' : | ||
// fall through to DDDD | ||
case 'DD' : | ||
// fall through to DDDD | ||
case 'DDD' : | ||
// fall through to DDDD | ||
case 'DDDD' : | ||
inArray[2] = ~~input; | ||
break; | ||
// YEAR | ||
case 'YY' : | ||
input = ~~input; | ||
inArray[0] = input + (input > 70 ? 1900 : 2000); | ||
break; | ||
case 'YYYY' : | ||
inArray[0] = ~~Math.abs(input); | ||
break; | ||
// AM / PM | ||
case 'a' : | ||
// fall through to A | ||
case 'A' : | ||
isPm = (input.toLowerCase() === 'pm'); | ||
break; | ||
// 24 HOUR | ||
case 'H' : | ||
// fall through to hh | ||
case 'HH' : | ||
// fall through to hh | ||
case 'h' : | ||
// fall through to hh | ||
case 'hh' : | ||
inArray[3] = ~~input; | ||
break; | ||
// MINUTE | ||
case 'm' : | ||
// fall through to mm | ||
case 'mm' : | ||
inArray[4] = ~~input; | ||
break; | ||
// SECOND | ||
case 's' : | ||
// fall through to ss | ||
case 'ss' : | ||
inArray[5] = ~~input; | ||
break; | ||
// TIMEZONE | ||
case 'Z' : | ||
// fall through to ZZ | ||
case 'ZZ' : | ||
isUsingUTC = true; | ||
a = input.match(timezoneParseRegex); | ||
if (a[1]) { | ||
timezoneHours = ~~a[1]; | ||
} | ||
if (a[2]) { | ||
timezoneMinutes = ~~a[2]; | ||
} | ||
// reverse offsets | ||
if (a[0] === '-') { | ||
timezoneHours = -timezoneHours; | ||
timezoneMinutes = -timezoneMinutes; | ||
} | ||
break; | ||
} | ||
break; | ||
// DAY OF MONTH | ||
case 'D' : // fall through to DDDD | ||
case 'DD' : // fall through to DDDD | ||
case 'DDD' : // fall through to DDDD | ||
case 'DDDD' : | ||
datePartArray[2] = ~~input; | ||
break; | ||
// YEAR | ||
case 'YY' : | ||
input = ~~input; | ||
datePartArray[0] = input + (input > 70 ? 1900 : 2000); | ||
break; | ||
case 'YYYY' : | ||
datePartArray[0] = ~~Math.abs(input); | ||
break; | ||
// AM / PM | ||
case 'a' : // fall through to A | ||
case 'A' : | ||
config.isPm = ((input + '').toLowerCase() === 'pm'); | ||
break; | ||
// 24 HOUR | ||
case 'H' : // fall through to hh | ||
case 'HH' : // fall through to hh | ||
case 'h' : // fall through to hh | ||
case 'hh' : | ||
datePartArray[3] = ~~input; | ||
break; | ||
// MINUTE | ||
case 'm' : // fall through to mm | ||
case 'mm' : | ||
datePartArray[4] = ~~input; | ||
break; | ||
// SECOND | ||
case 's' : // fall through to ss | ||
case 'ss' : | ||
datePartArray[5] = ~~input; | ||
break; | ||
// MILLISECOND | ||
case 'S' : | ||
case 'SS' : | ||
case 'SSS' : | ||
datePartArray[6] = ~~ (('0.' + input) * 1000); | ||
break; | ||
// TIMEZONE | ||
case 'Z' : // fall through to ZZ | ||
case 'ZZ' : | ||
config.isUTC = true; | ||
a = (input + '').match(parseTimezoneChunker); | ||
if (a && a[1]) { | ||
config.tzh = ~~a[1]; | ||
} | ||
if (a && a[2]) { | ||
config.tzm = ~~a[2]; | ||
} | ||
// reverse offsets | ||
if (a && a[0] === '+') { | ||
config.tzh = -config.tzh; | ||
config.tzm = -config.tzm; | ||
} | ||
break; | ||
} | ||
for (i = 0; i < formatParts.length; i++) { | ||
addTime(formatParts[i], inputParts[i]); | ||
} | ||
// date from string and format string | ||
function makeDateFromStringAndFormat(string, format) { | ||
var datePartArray = [0, 0, 1, 0, 0, 0, 0], | ||
config = { | ||
tzh : 0, // timezone hour offset | ||
tzm : 0 // timezone minute offset | ||
}, | ||
tokens = format.match(formattingTokens), | ||
i, parsedInput; | ||
for (i = 0; i < tokens.length; i++) { | ||
parsedInput = (getParseRegexForToken(tokens[i]).exec(string) || [])[0]; | ||
string = string.replace(getParseRegexForToken(tokens[i]), ''); | ||
addTimeToArrayFromToken(tokens[i], parsedInput, datePartArray, config); | ||
} | ||
// handle am pm | ||
if (isPm && inArray[3] < 12) { | ||
inArray[3] += 12; | ||
if (config.isPm && datePartArray[3] < 12) { | ||
datePartArray[3] += 12; | ||
} | ||
// if is 12 am, change hours to 0 | ||
if (isPm === false && inArray[3] === 12) { | ||
inArray[3] = 0; | ||
if (config.isPm === false && datePartArray[3] === 12) { | ||
datePartArray[3] = 0; | ||
} | ||
// handle timezone | ||
inArray[3] += timezoneHours; | ||
inArray[4] += timezoneMinutes; | ||
datePartArray[3] += config.tzh; | ||
datePartArray[4] += config.tzm; | ||
// return | ||
return isUsingUTC ? new Date(Date.UTC.apply({}, inArray)) : dateFromArray(inArray); | ||
return config.isUTC ? new Date(Date.UTC.apply({}, datePartArray)) : dateFromArray(datePartArray); | ||
} | ||
@@ -348,14 +487,15 @@ | ||
var output, | ||
inputParts = string.match(inputCharacters), | ||
scores = [], | ||
inputParts = string.match(parseMultipleFormatChunker) || [], | ||
formattedInputParts, | ||
scoreToBeat = 99, | ||
i, | ||
curDate, | ||
curScore; | ||
currentDate, | ||
currentScore; | ||
for (i = 0; i < formats.length; i++) { | ||
curDate = makeDateFromStringAndFormat(string, formats[i]); | ||
curScore = compareArrays(inputParts, formatDate(curDate, formats[i]).match(inputCharacters)); | ||
if (curScore < scoreToBeat) { | ||
scoreToBeat = curScore; | ||
output = curDate; | ||
currentDate = makeDateFromStringAndFormat(string, formats[i]); | ||
formattedInputParts = formatMoment(new Moment(currentDate), formats[i]).match(parseMultipleFormatChunker) || []; | ||
currentScore = compareArrays(inputParts, formattedInputParts); | ||
if (currentScore < scoreToBeat) { | ||
scoreToBeat = currentScore; | ||
output = currentDate; | ||
} | ||
@@ -366,10 +506,60 @@ } | ||
// date from iso format | ||
function makeDateFromString(string) { | ||
var format = 'YYYY-MM-DDT', | ||
i; | ||
if (isoRegex.exec(string)) { | ||
for (i = 0; i < 4; i++) { | ||
if (isoTimes[i][1].exec(string)) { | ||
format += isoTimes[i][0]; | ||
break; | ||
} | ||
} | ||
return parseTokenTimezone.exec(string) ? | ||
makeDateFromStringAndFormat(string, format + ' Z') : | ||
makeDateFromStringAndFormat(string, format); | ||
} | ||
return new Date(string); | ||
} | ||
// helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize | ||
function substituteTimeAgo(string, number, withoutSuffix, isFuture) { | ||
var rt = moment.relativeTime[string]; | ||
return (typeof rt === 'function') ? | ||
rt(number || 1, !!withoutSuffix, string, isFuture) : | ||
rt.replace(/%d/i, number || 1); | ||
} | ||
function relativeTime(milliseconds, withoutSuffix) { | ||
var seconds = round(Math.abs(milliseconds) / 1000), | ||
minutes = round(seconds / 60), | ||
hours = round(minutes / 60), | ||
days = round(hours / 24), | ||
years = round(days / 365), | ||
args = seconds < 45 && ['s', seconds] || | ||
minutes === 1 && ['m'] || | ||
minutes < 45 && ['mm', minutes] || | ||
hours === 1 && ['h'] || | ||
hours < 22 && ['hh', hours] || | ||
days === 1 && ['d'] || | ||
days <= 25 && ['dd', days] || | ||
days <= 45 && ['M'] || | ||
days < 345 && ['MM', round(days / 30)] || | ||
years === 1 && ['y'] || ['yy', years]; | ||
args[2] = withoutSuffix; | ||
args[3] = milliseconds > 0; | ||
return substituteTimeAgo.apply({}, args); | ||
} | ||
moment = function (input, format) { | ||
if (input === null) { | ||
if (input === null || input === '') { | ||
return null; | ||
} | ||
var date; | ||
// parse UnderscoreDate object | ||
if (input && input._d instanceof Date) { | ||
var date, | ||
matched, | ||
isUTC; | ||
// parse Moment object | ||
if (moment.isMoment(input)) { | ||
date = new Date(+input._d); | ||
isUTC = input._isUTC; | ||
// parse string and format | ||
@@ -382,21 +572,67 @@ } else if (format) { | ||
} | ||
// parse everything else | ||
// evaluate it as a JSON-encoded date | ||
} else { | ||
matched = aspNetJsonRegex.exec(input); | ||
date = input === undefined ? new Date() : | ||
matched ? new Date(+matched[1]) : | ||
input instanceof Date ? input : | ||
isArray(input) ? dateFromArray(input) : | ||
typeof input === 'string' ? makeDateFromString(input) : | ||
new Date(input); | ||
} | ||
return new Moment(date); | ||
return new Moment(date, isUTC); | ||
}; | ||
// creating with utc | ||
moment.utc = function (input, format) { | ||
if (isArray(input)) { | ||
return new Moment(new Date(Date.UTC.apply({}, input)), true); | ||
} | ||
return (format && input) ? | ||
moment(input + ' +0000', format + ' Z').utc() : | ||
moment(input && !parseTokenTimezone.exec(input) ? input + '+0000' : input).utc(); | ||
}; | ||
// creating with unix timestamp (in seconds) | ||
moment.unix = function (input) { | ||
return moment(input * 1000); | ||
}; | ||
// duration | ||
moment.duration = function (input, key) { | ||
var isDuration = moment.isDuration(input), | ||
isNumber = (typeof input === 'number'), | ||
duration = (isDuration ? input._data : (isNumber ? {} : input)); | ||
if (isNumber) { | ||
if (key) { | ||
duration[key] = input; | ||
} else { | ||
duration.milliseconds = input; | ||
} | ||
} | ||
return new Duration(duration); | ||
}; | ||
// humanizeDuration | ||
// This method is deprecated in favor of the new Duration object. Please | ||
// see the moment.duration method. | ||
moment.humanizeDuration = function (num, type, withSuffix) { | ||
return moment.duration(num, type === true ? null : type).humanize(type === true ? true : withSuffix); | ||
}; | ||
// version number | ||
moment.version = VERSION; | ||
// default format | ||
moment.defaultFormat = isoFormat; | ||
// language switching and caching | ||
moment.lang = function (key, values) { | ||
var i, | ||
param, | ||
req, | ||
var i, req, | ||
parse = []; | ||
if (!key) { | ||
return currentLanguage; | ||
} | ||
if (values) { | ||
@@ -410,6 +646,7 @@ for (i = 0; i < 12; i++) { | ||
if (languages[key]) { | ||
for (i = 0; i < paramsToParse.length; i++) { | ||
param = paramsToParse[i]; | ||
moment[param] = languages[key][param] || moment[param]; | ||
for (i = 0; i < langConfigProperties.length; i++) { | ||
moment[langConfigProperties[i]] = languages[key][langConfigProperties[i]] || | ||
languages.en[langConfigProperties[i]]; | ||
} | ||
currentLanguage = key; | ||
} else { | ||
@@ -436,8 +673,3 @@ if (hasModule) { | ||
}, | ||
meridiem : { | ||
AM : 'AM', | ||
am : 'am', | ||
PM : 'PM', | ||
pm : 'pm' | ||
}, | ||
meridiem : false, | ||
calendar : { | ||
@@ -475,29 +707,11 @@ sameDay : '[Today at] LT', | ||
// helper function for _date.from() and _date.fromNow() | ||
function substituteTimeAgo(string, number, withoutSuffix) { | ||
var rt = moment.relativeTime[string]; | ||
return (typeof rt === 'function') ? | ||
rt(number || 1, !!withoutSuffix, string) : | ||
rt.replace(/%d/i, number || 1); | ||
} | ||
// compare moment object | ||
moment.isMoment = function (obj) { | ||
return obj instanceof Moment; | ||
}; | ||
function relativeTime(milliseconds, withoutSuffix) { | ||
var seconds = round(Math.abs(milliseconds) / 1000), | ||
minutes = round(seconds / 60), | ||
hours = round(minutes / 60), | ||
days = round(hours / 24), | ||
years = round(days / 365), | ||
args = seconds < 45 && ['s', seconds] || | ||
minutes === 1 && ['m'] || | ||
minutes < 45 && ['mm', minutes] || | ||
hours === 1 && ['h'] || | ||
hours < 22 && ['hh', hours] || | ||
days === 1 && ['d'] || | ||
days <= 25 && ['dd', days] || | ||
days <= 45 && ['M'] || | ||
days < 345 && ['MM', round(days / 30)] || | ||
years === 1 && ['y'] || ['yy', years]; | ||
args[2] = withoutSuffix; | ||
return substituteTimeAgo.apply({}, args); | ||
} | ||
// for typechecking Duration objects | ||
moment.isDuration = function (obj) { | ||
return obj instanceof Duration; | ||
}; | ||
@@ -515,4 +729,4 @@ // shortcut for prototype | ||
'native' : function () { | ||
return this._d; | ||
unix : function () { | ||
return Math.floor(+this._d / 1000); | ||
}, | ||
@@ -528,8 +742,19 @@ | ||
utc : function () { | ||
this._isUTC = true; | ||
return this; | ||
}, | ||
local : function () { | ||
this._isUTC = false; | ||
return this; | ||
}, | ||
format : function (inputString) { | ||
return formatDate(this._d, inputString); | ||
return formatMoment(this, inputString ? inputString : moment.defaultFormat); | ||
}, | ||
add : function (input, val) { | ||
this._d = dateAddRemove(this._d, input, 1, val); | ||
var dur = val ? moment.duration(+val, input) : moment.duration(input); | ||
addOrSubtractDurationFromMoment(this, dur, 1); | ||
return this; | ||
@@ -539,3 +764,4 @@ }, | ||
subtract : function (input, val) { | ||
this._d = dateAddRemove(this._d, input, -1, val); | ||
var dur = val ? moment.duration(+val, input) : moment.duration(input); | ||
addOrSubtractDurationFromMoment(this, dur, -1); | ||
return this; | ||
@@ -545,12 +771,13 @@ }, | ||
diff : function (input, val, asFloat) { | ||
var inputMoment = moment(input), | ||
diff = this._d - inputMoment._d, | ||
var inputMoment = this._isUTC ? moment(input).utc() : moment(input).local(), | ||
zoneDiff = (this.zone() - inputMoment.zone()) * 6e4, | ||
diff = this._d - inputMoment._d - zoneDiff, | ||
year = this.year() - inputMoment.year(), | ||
month = this.month() - inputMoment.month(), | ||
day = this.day() - inputMoment.day(), | ||
date = this.date() - inputMoment.date(), | ||
output; | ||
if (val === 'months') { | ||
output = year * 12 + month + day / 30; | ||
output = year * 12 + month + date / 30; | ||
} else if (val === 'years') { | ||
output = year + month / 12; | ||
output = year + (month + date / 30) / 12; | ||
} else { | ||
@@ -562,3 +789,3 @@ output = val === 'seconds' ? diff / 1e3 : // 1000 | ||
val === 'weeks' ? diff / 6048e5 : // 1000 * 60 * 60 * 24 * 7 | ||
val === 'days' ? diff / 3600 : diff; | ||
diff; | ||
} | ||
@@ -569,6 +796,3 @@ return asFloat ? output : round(output); | ||
from : function (time, withoutSuffix) { | ||
var difference = this.diff(time), | ||
rel = moment.relativeTime, | ||
output = relativeTime(difference, withoutSuffix); | ||
return withoutSuffix ? output : (difference <= 0 ? rel.past : rel.future).replace(/%s/i, output); | ||
return moment.duration(this.diff(time)).humanize(!withoutSuffix); | ||
}, | ||
@@ -581,5 +805,3 @@ | ||
calendar : function () { | ||
var today = moment(), | ||
todayAtZeroHour = moment([today.year(), today.month(), today.date()]), | ||
diff = this.diff(todayAtZeroHour, 'days', true), | ||
var diff = this.diff(moment().sod(), 'days', true), | ||
calendar = moment.calendar, | ||
@@ -602,9 +824,34 @@ allElse = calendar.sameElse, | ||
isDST : function () { | ||
return this.zone() !== moment([this.year()]).zone(); | ||
return (this.zone() < moment([this.year()]).zone() || | ||
this.zone() < moment([this.year(), 5]).zone()); | ||
}, | ||
day : function (input) { | ||
var day = this._d.getDay(); | ||
var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay(); | ||
return input == null ? day : | ||
this.add({ d : input - day }); | ||
}, | ||
sod: function () { | ||
return moment(this) | ||
.hours(0) | ||
.minutes(0) | ||
.seconds(0) | ||
.milliseconds(0); | ||
}, | ||
eod: function () { | ||
// end of day = start of day plus 1 day, minus 1 millisecond | ||
return this.sod().add({ | ||
d : 1, | ||
ms : -1 | ||
}); | ||
}, | ||
zone : function () { | ||
return this._isUTC ? 0 : this._d.getTimezoneOffset(); | ||
}, | ||
daysInMonth : function () { | ||
return moment(this).month(this.month() + 1).date(0).date(); | ||
} | ||
@@ -614,9 +861,10 @@ }; | ||
// helper for adding shortcuts | ||
function makeShortcut(name, key) { | ||
function makeGetterAndSetter(name, key) { | ||
moment.fn[name] = function (input) { | ||
var utc = this._isUTC ? 'UTC' : ''; | ||
if (input != null) { | ||
this._d['set' + key](input); | ||
this._d['set' + utc + key](input); | ||
return this; | ||
} else { | ||
return this._d['get' + key](); | ||
return this._d['get' + utc + key](); | ||
} | ||
@@ -627,14 +875,54 @@ }; | ||
// loop through and add shortcuts (Month, Date, Hours, Minutes, Seconds, Milliseconds) | ||
for (i = 0; i < shortcuts.length; i ++) { | ||
makeShortcut(shortcuts[i].toLowerCase(), shortcuts[i]); | ||
for (i = 0; i < proxyGettersAndSetters.length; i ++) { | ||
makeGetterAndSetter(proxyGettersAndSetters[i].toLowerCase(), proxyGettersAndSetters[i]); | ||
} | ||
// add shortcut for year (uses different syntax than the getter/setter 'year' == 'FullYear') | ||
makeShortcut('year', 'FullYear'); | ||
makeGetterAndSetter('year', 'FullYear'); | ||
// add shortcut for timezone offset (no setter) | ||
moment.fn.zone = function () { | ||
return this._d.getTimezoneOffset(); | ||
moment.duration.fn = Duration.prototype = { | ||
weeks : function () { | ||
return absRound(this.days() / 7); | ||
}, | ||
valueOf : function () { | ||
return this._milliseconds + | ||
this._days * 864e5 + | ||
this._months * 2592e6; | ||
}, | ||
humanize : function (withSuffix) { | ||
var difference = +this, | ||
rel = moment.relativeTime, | ||
output = relativeTime(difference, !withSuffix); | ||
if (withSuffix) { | ||
output = (difference <= 0 ? rel.past : rel.future).replace(/%s/i, output); | ||
} | ||
return output; | ||
} | ||
}; | ||
function makeDurationGetter(name) { | ||
moment.duration.fn[name] = function () { | ||
return this._data[name]; | ||
}; | ||
} | ||
function makeDurationAsGetter(name, factor) { | ||
moment.duration.fn['as' + name] = function () { | ||
return +this / factor; | ||
}; | ||
} | ||
for (i in unitMillisecondFactors) { | ||
if (unitMillisecondFactors.hasOwnProperty(i)) { | ||
makeDurationAsGetter(i, unitMillisecondFactors[i]); | ||
makeDurationGetter(i.toLowerCase()); | ||
} | ||
} | ||
makeDurationAsGetter('Weeks', 6048e5); | ||
// CommonJS module is defined | ||
@@ -644,6 +932,12 @@ if (hasModule) { | ||
} | ||
if (typeof window !== 'undefined') { | ||
/*global ender:false */ | ||
if (typeof window !== 'undefined' && typeof ender === 'undefined') { | ||
window.moment = moment; | ||
} | ||
/*global define:false */ | ||
if (typeof define === "function" && define.amd) { | ||
define("moment", [], function () { | ||
return moment; | ||
}); | ||
} | ||
})(Date); |
@@ -1,2 +0,6 @@ | ||
/* Moment.js | version : 1.3.0 | author : Tim Wood | license : MIT */ | ||
(function(a,b){function q(a){this._d=a}function r(a,b){var c=a+"";while(c.length<b)c="0"+c;return c}function s(b,c,d,e){var f=typeof c=="string",g=f?{}:c,h,i,j,k;return f&&e&&(g[c]=e),h=(g.ms||g.milliseconds||0)+(g.s||g.seconds||0)*1e3+(g.m||g.minutes||0)*6e4+(g.h||g.hours||0)*36e5,i=(g.d||g.days||0)+(g.w||g.weeks||0)*7,j=(g.M||g.months||0)+(g.y||g.years||0)*12,h&&b.setTime(+b+h*d),i&&b.setDate(b.getDate()+i*d),j&&(k=b.getDate(),b.setDate(1),b.setMonth(b.getMonth()+j*d),b.setDate(Math.min((new a(b.getFullYear(),b.getMonth()+1,0)).getDate(),k))),b}function t(a){return Object.prototype.toString.call(a)==="[object Array]"}function u(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 v(b,d){function u(d){var e,i;switch(d){case"M":return f+1;case"Mo":return f+1+s(f+1);case"MM":return r(f+1,2);case"MMM":return c.monthsShort[f];case"MMMM":return c.months[f];case"D":return g;case"Do":return g+s(g);case"DD":return r(g,2);case"DDD":return e=new a(h,f,g),i=new a(h,0,1),~~((e-i)/864e5+1.5);case"DDDo":return e=u("DDD"),e+s(e);case"DDDD":return r(u("DDD"),3);case"d":return l;case"do":return l+s(l);case"ddd":return c.weekdaysShort[l];case"dddd":return c.weekdays[l];case"w":return e=new a(h,f,g-l+5),i=new a(e.getFullYear(),0,4),~~((e-i)/864e5/7+1.5);case"wo":return e=u("w"),e+s(e);case"ww":return r(u("w"),2);case"YY":return r(h%100,2);case"YYYY":return h;case"a":return m>11?t.pm:t.am;case"A":return m>11?t.PM:t.AM;case"H":return m;case"HH":return r(m,2);case"h":return m%12||12;case"hh":return r(m%12||12,2);case"m":return n;case"mm":return r(n,2);case"s":return o;case"ss":return r(o,2);case"zz":case"z":return(b.toString().match(k)||[""])[0].replace(j,"");case"Z":return(p>0?"+":"-")+r(~~(Math.abs(p)/60),2)+":"+r(~~(Math.abs(p)%60),2);case"ZZ":return(p>0?"+":"-")+r(~~(10*Math.abs(p)/6),4);case"L":case"LL":case"LLL":case"LLLL":case"LT":return v(b,c.longDateFormat[d]);default:return d.replace(/(^\[)|(\\)|\]$/g,"")}}var e=new q(b),f=e.month(),g=e.date(),h=e.year(),l=e.day(),m=e.hours(),n=e.minutes(),o=e.seconds(),p=e.zone(),s=c.ordinal,t=c.meridiem;return d.replace(i,u)}function w(b,d){function p(a,b){var d;switch(a){case"M":case"MM":e[1]=~~b-1;break;case"MMM":case"MMMM":for(d=0;d<12;d++)if(c.monthsParse[d].test(b)){e[1]=d;break}break;case"D":case"DD":case"DDD":case"DDDD":e[2]=~~b;break;case"YY":b=~~b,e[0]=b+(b>70?1900:2e3);break;case"YYYY":e[0]=~~Math.abs(b);break;case"a":case"A":o=b.toLowerCase()==="pm";break;case"H":case"HH":case"h":case"hh":e[3]=~~b;break;case"m":case"mm":e[4]=~~b;break;case"s":case"ss":e[5]=~~b;break;case"Z":case"ZZ":h=!0,d=b.match(n),d[1]&&(f=~~d[1]),d[2]&&(g=~~d[2]),d[0]==="-"&&(f=-f,g=-g)}}var e=[0,0,1,0,0,0,0],f=0,g=0,h=!1,i=b.match(m),j=d.match(l),k,o;for(k=0;k<j.length;k++)p(j[k],i[k]);return o&&e[3]<12&&(e[3]+=12),o===!1&&e[3]===12&&(e[3]=0),e[3]+=f,e[4]+=g,h?new a(a.UTC.apply({},e)):u(e)}function x(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 y(a,b){var c,d=a.match(m),e=[],f=99,g,h,i;for(g=0;g<b.length;g++)h=w(a,b[g]),i=x(d,v(h,b[g]).match(m)),i<f&&(f=i,c=h);return c}function z(a,b,d){var e=c.relativeTime[a];return typeof e=="function"?e(b||1,!!d,a):e.replace(/%d/i,b||1)}function A(a,b){var c=d(Math.abs(a)/1e3),e=d(c/60),f=d(e/60),g=d(f/24),h=d(g/365),i=c<45&&["s",c]||e===1&&["m"]||e<45&&["mm",e]||f===1&&["h"]||f<22&&["hh",f]||g===1&&["d"]||g<=25&&["dd",g]||g<=45&&["M"]||g<345&&["MM",d(g/30)]||h===1&&["y"]||["yy",h];return i[2]=b,z.apply({},i)}function B(a,b){c.fn[a]=function(a){return a!=null?(this._d["set"+b](a),this):this._d["get"+b]()}}var c,d=Math.round,e={},f=typeof module!="undefined",g="months|monthsShort|monthsParse|weekdays|weekdaysShort|longDateFormat|calendar|relativeTime|ordinal|meridiem".split("|"),h,i=/(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|dddd?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|zz?|ZZ?|LT|LL?L?L?)/g,j=/[^A-Z]/g,k=/\([A-Za-z ]+\)|:[0-9]{2} [A-Z]{3} /g,l=/(\\)?(MM?M?M?|dd?d?d|DD?D?D?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|ZZ?|T)/g,m=/(\\)?([0-9]+|([a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+|([\+\-]\d\d:?\d\d))/gi,n=/([\+\-]|\d\d)/gi,o="1.3.0",p="Month|Date|Hours|Minutes|Seconds|Milliseconds".split("|");c=function(c,d){if(c===null)return null;var e;return c&&c._d instanceof a?e=new a(+c._d):d?t(d)?e=y(c,d):e=w(c,d):e=c===b?new a:c instanceof a?c:t(c)?u(c):new a(c),new q(e)},c.version=o,c.lang=function(a,b){var d,h,i,j=[];if(b){for(d=0;d<12;d++)j[d]=new RegExp("^"+b.months[d]+"|^"+b.monthsShort[d].replace(".",""),"i");b.monthsParse=b.monthsParse||j,e[a]=b}if(e[a])for(d=0;d<g.length;d++)h=g[d],c[h]=e[a][h]||c[h];else f&&(i=require("./lang/"+a),c.lang(a,i))},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:{AM:"AM",am:"am",PM:"PM",pm:"pm"},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.fn=q.prototype={clone:function(){return c(this)},valueOf:function(){return+this._d},"native":function(){return this._d},toString:function(){return this._d.toString()},toDate:function(){return this._d},format:function(a){return v(this._d,a)},add:function(a,b){return this._d=s(this._d,a,1,b),this},subtract:function(a,b){return this._d=s(this._d,a,-1,b),this},diff:function(a,b,e){var f=c(a),g=this._d-f._d,h=this.year()-f.year(),i=this.month()-f.month(),j=this.day()-f.day(),k;return b==="months"?k=h*12+i+j/30:b==="years"?k=h+i/12:k=b==="seconds"?g/1e3:b==="minutes"?g/6e4:b==="hours"?g/36e5:b==="days"?g/864e5:b==="weeks"?g/6048e5:b==="days"?g/3600:g,e?k:d(k)},from:function(a,b){var d=this.diff(a),e=c.relativeTime,f=A(d,b);return b?f:(d<=0?e.past:e.future).replace(/%s/i,f)},fromNow:function(a){return this.from(c(),a)},calendar:function(){var a=c(),b=c([a.year(),a.month(),a.date()]),d=this.diff(b,"days",!0),e=c.calendar,f=e.sameElse,g=d<-6?f:d<-1?e.lastWeek:d<0?e.lastDay:d<1?e.sameDay:d<2?e.nextDay:d<7?e.nextWeek:f;return this.format(typeof g=="function"?g.apply(this):g)},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()},day:function(a){var b=this._d.getDay();return a==null?b:this.add({d:a-b})}};for(h=0;h<p.length;h++)B(p[h].toLowerCase(),p[h]);B("year","FullYear"),c.fn.zone=function(){return this._d.getTimezoneOffset()},f&&(module.exports=c),typeof window!="undefined"&&(window.moment=c)})(Date) | ||
// moment.js | ||
// version : 1.6.2 | ||
// 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})},sod:function(){return c(this).hours(0).minutes(0).seconds(0).milliseconds(0)},eod:function(){return this.sod().add({d:1,ms:-1})},zone:function(){return this._isUTC?0:this._d.getTimezoneOffset()},daysInMonth:function(){return c(this).month(this.month()+1).date(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); |
{ | ||
"name": "twix", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Twix.js allows you to work with date ranges", | ||
@@ -9,3 +9,3 @@ "homepage": "https://github.com/icambron/twix.js", | ||
"dependencies": { | ||
"moment": ">= 1.3" | ||
"moment": "1.6" | ||
}, | ||
@@ -12,0 +12,0 @@ "devDependencies": { |
@@ -0,3 +1,4 @@ | ||
// Generated by CoffeeScript 1.3.3 | ||
(function() { | ||
var Twix, assertEqual, moment, thisYear; | ||
var Twix, assertDeepEqual, assertEqual, moment, thatDay, thisYear, tomorrow, yesterday; | ||
@@ -7,2 +8,3 @@ if (typeof module !== "undefined") { | ||
assertEqual = require('assert').equal; | ||
assertDeepEqual = require('assert').deepEqual; | ||
Twix = require("../../bin/twix"); | ||
@@ -13,4 +15,11 @@ } else { | ||
assertEqual = function(a, b) { | ||
if (a !== b) throw new Error("Found " + b + ", expected " + a); | ||
if (a !== b) { | ||
throw new Error("Found " + b + ", expected " + a); | ||
} | ||
}; | ||
assertDeepEqual = function(a, b) { | ||
if (!a.equals(b)) { | ||
throw new Error("Found " + b + ", expected " + a); | ||
} | ||
}; | ||
} | ||
@@ -21,6 +30,24 @@ | ||
fullDate = "" + partial + "/" + (moment().year()); | ||
if (time) fullDate += " " + time; | ||
if (time) { | ||
fullDate += " " + time; | ||
} | ||
return moment(fullDate); | ||
}; | ||
yesterday = function() { | ||
return moment().subtract('days', 1).sod(); | ||
}; | ||
tomorrow = function() { | ||
return moment().add('days', 1).sod(); | ||
}; | ||
thatDay = function(start, end) { | ||
if (start) { | ||
return new Twix("5/25/1982 " + start, "5/25/1982 " + end); | ||
} else { | ||
return new Twix("5/25/1982", "5/25/1982", true); | ||
} | ||
}; | ||
describe("sameYear()", function() { | ||
@@ -79,3 +106,3 @@ it("returns true if they're the same year", function() { | ||
it("provides 1 day if the range includes 1 day", function() { | ||
var end, iter, range, start; | ||
var end, iter, next, range, start; | ||
start = thisYear("5/25", "3:00"); | ||
@@ -85,3 +112,5 @@ end = thisYear("5/25", "14:00"); | ||
iter = range.daysIn(); | ||
assertSameDay(thisYear("5/25"), iter.next()); | ||
next = iter.next(); | ||
console.log(next); | ||
assertSameDay(thisYear("5/25"), next); | ||
return assertEqual(null, iter.next()); | ||
@@ -99,3 +128,3 @@ }); | ||
}); | ||
return it("provides 366 days if the range is a year", function() { | ||
it("provides 366 days if the range is a year", function() { | ||
var end, iter, results, start; | ||
@@ -115,2 +144,11 @@ start = thisYear("5/25", "16:00"); | ||
}); | ||
return it("doesn't generate extra days when there's a min time", function() { | ||
var end, iter, range, start; | ||
start = thisYear("5/25", "16:00"); | ||
end = thisYear("5/26", "3:00"); | ||
range = new Twix(start, end); | ||
iter = range.daysIn(4); | ||
assertSameDay(thisYear("5/25"), iter.next()); | ||
return assertEqual(null, iter.next()); | ||
}); | ||
}); | ||
@@ -121,6 +159,6 @@ | ||
it("formats single-day correctly", function() { | ||
return assertEqual(new Twix("5/25/1982", "5.25/1982", true).duration(), "all day"); | ||
return assertEqual("all day", new Twix("5/25/1982", "5/25/1982", true).duration()); | ||
}); | ||
return it("formats multiday correctly", function() { | ||
return assertEqual(new Twix("5/25/1982", "5/27/1982", true).duration(), "3 days"); | ||
return assertEqual("3 days", new Twix("5/25/1982", "5/27/1982", true).duration()); | ||
}); | ||
@@ -130,6 +168,6 @@ }); | ||
it("formats single-day correctly", function() { | ||
return assertEqual(new Twix("5/25/1982 12:00", "5/25/1982 16:00").duration(), "4 hours"); | ||
return assertEqual("4 hours", thatDay("12:00", "16:00").duration()); | ||
}); | ||
return it("formats multiday correctly", function() { | ||
return assertEqual(new Twix("5/25/1982", "5/27/1982").duration(), "2 days"); | ||
return assertEqual("2 days", new Twix("5/25/1982", "5/27/1982").duration()); | ||
}); | ||
@@ -139,2 +177,223 @@ }); | ||
describe("past()", function() { | ||
describe("all-day events", function() { | ||
it("returns true for days in the past", function() { | ||
return assertEqual(true, new Twix(yesterday(), yesterday(), true).past()); | ||
}); | ||
it("returns false for today", function() { | ||
return assertEqual(false, new Twix(moment().sod(), moment().sod(), true).past()); | ||
}); | ||
return it("returns false for days in the future", function() { | ||
return assertEqual(false, new Twix(tomorrow(), tomorrow(), true).past()); | ||
}); | ||
}); | ||
return describe("non-all-day events", function() { | ||
it("returns true for the past", function() { | ||
return assertEqual(true, new Twix(moment().subtract('hours', 3), moment().subtract('hours', 2)).past()); | ||
}); | ||
return it("returns false for the future", function() { | ||
return assertEqual(false, new Twix(moment().add('hours', 2), moment().add('hours', 3)).past()); | ||
}); | ||
}); | ||
}); | ||
describe("overlaps", function() { | ||
var assertNoOverlap, assertOverlap, assertOverlapness, someDays, someTime; | ||
assertOverlap = function(first, second) { | ||
return assertOverlapness(true)(first, second); | ||
}; | ||
assertNoOverlap = function(first, second) { | ||
return assertOverlapness(false)(first, second); | ||
}; | ||
assertOverlapness = function(shouldOverlap) { | ||
return function(first, second) { | ||
assertEqual(shouldOverlap, first.overlaps(second)); | ||
return assertEqual(shouldOverlap, second.overlaps(first)); | ||
}; | ||
}; | ||
someTime = thatDay("5:30", "8:30"); | ||
someDays = new Twix("5/24/1982", "5/25/1982", true); | ||
describe("non-all-day events", function() { | ||
it("returns false for a later event", function() { | ||
return assertNoOverlap(someTime, thatDay("9:30", "11:30")); | ||
}); | ||
it("returns false for an earlier event", function() { | ||
return assertNoOverlap(someTime, thatDay("3:30", "4:30")); | ||
}); | ||
it("returns true for a partially later event", function() { | ||
return assertOverlap(someTime, thatDay("8:00", "11:30")); | ||
}); | ||
it("returns true for a partially earlier event", function() { | ||
return assertOverlap(someTime, thatDay("4:30", "6:30")); | ||
}); | ||
it("returns true for an engulfed event", function() { | ||
return assertOverlap(someTime, thatDay("6:30", "7:30")); | ||
}); | ||
return it("returns true for an engulfing event", function() { | ||
return assertOverlap(someTime, thatDay("4:30", "9:30")); | ||
}); | ||
}); | ||
describe("one all-day event", function() { | ||
it("returns true for a partially later event", function() { | ||
return assertOverlap(thatDay(), new Twix("5/25/1982 20:00", "5/26/1982 5:00")); | ||
}); | ||
it("returns true for a partially earlier event", function() { | ||
return assertOverlap(thatDay(), new Twix("5/24/1982", "20:00", "5/25/1982 7:00")); | ||
}); | ||
it("returns true for an engulfed event", function() { | ||
return assertOverlap(thatDay(), someTime); | ||
}); | ||
return it("returns true for an engulfing event", function() { | ||
return assertOverlap(thatDay(), new Twix("5/24/1982 20:00", "5/26/1982 5:00")); | ||
}); | ||
}); | ||
return describe("two all-day events", function() { | ||
it("returns false for a later event", function() { | ||
return assertNoOverlap(someDays, new Twix("5/26/1982", "5/27/1982", true)); | ||
}); | ||
it("returns false for an earlier event", function() { | ||
return assertNoOverlap(someDays, new Twix("5/22/1982", "5/23/1982", true)); | ||
}); | ||
it("returns true for a partially later event", function() { | ||
return assertOverlap(someDays, new Twix("5/24/1982", "5/26/1982", true)); | ||
}); | ||
it("returns true for a partially earlier event", function() { | ||
return assertOverlap(someDays, new Twix("5/22/1982", "5/24/1982", true)); | ||
}); | ||
it("returns true for an engulfed event", function() { | ||
return assertOverlap(someDays, new Twix("5/25/1982", "5/25/1982", true)); | ||
}); | ||
return it("returns true for an engulfing event", function() { | ||
return assertOverlap(someDays, new Twix("5/22/1982", "5/28/1982", true)); | ||
}); | ||
}); | ||
}); | ||
describe("engulfs", function() { | ||
var assertEngulfing, assertNotEngulfing, someDays, someTime; | ||
assertEngulfing = function(first, second) { | ||
return assertEqual(true, first.engulfs(second)); | ||
}; | ||
assertNotEngulfing = function(first, second) { | ||
return assertEqual(false, first.engulfs(second)); | ||
}; | ||
someTime = thatDay("5:30", "8:30"); | ||
someDays = new Twix("5/24/1982", "5/25/1982", true); | ||
describe("non-all-day events", function() { | ||
it("returns false for a later event", function() { | ||
return assertNotEngulfing(someTime, thatDay("9:30", "11:30")); | ||
}); | ||
it("returns false for an earlier event", function() { | ||
return assertNotEngulfing(someTime, thatDay("3:30", "4:30")); | ||
}); | ||
it("returns true for a partially later event", function() { | ||
return assertNotEngulfing(someTime, thatDay("8:00", "11:30")); | ||
}); | ||
it("returns true for a partially earlier event", function() { | ||
return assertNotEngulfing(someTime, thatDay("4:30", "6:30")); | ||
}); | ||
it("returns true for an engulfed event", function() { | ||
return assertEngulfing(someTime, thatDay("6:30", "7:30")); | ||
}); | ||
return it("returns true for an engulfing event", function() { | ||
return assertNotEngulfing(someTime, thatDay("4:30", "9:30")); | ||
}); | ||
}); | ||
describe("one all-day event", function() { | ||
it("returns true for a partially later event", function() { | ||
return assertNotEngulfing(thatDay(), new Twix("5/25/1982 20:00", "5/26/1982 5:00")); | ||
}); | ||
it("returns true for a partially earlier event", function() { | ||
return assertNotEngulfing(thatDay(), new Twix("5/24/1982", "20:00", "5/25/1982 7:00")); | ||
}); | ||
it("returns true for an engulfed event", function() { | ||
return assertEngulfing(thatDay(), someTime); | ||
}); | ||
return it("returns true for an engulfing event", function() { | ||
return assertNotEngulfing(thatDay(), new Twix("5/24/1982 20:00", "5/26/1982 5:00")); | ||
}); | ||
}); | ||
return describe("two all-day events", function() { | ||
it("returns false for a later event", function() { | ||
return assertNotEngulfing(someDays, new Twix("5/26/1982", "5/27/1982", true)); | ||
}); | ||
it("returns false for an earlier event", function() { | ||
return assertNotEngulfing(someDays, new Twix("5/22/1982", "5/23/1982", true)); | ||
}); | ||
it("returns true for a partially later event", function() { | ||
return assertNotEngulfing(someDays, new Twix("5/24/1982", "5/26/1982", true)); | ||
}); | ||
it("returns true for a partially earlier event", function() { | ||
return assertNotEngulfing(someDays, new Twix("5/22/1982", "5/24/1982", true)); | ||
}); | ||
it("returns true for an engulfed event", function() { | ||
return assertEngulfing(someDays, new Twix("5/25/1982", "5/25/1982", true)); | ||
}); | ||
return it("returns true for an engulfing event", function() { | ||
return assertNotEngulfing(someDays, new Twix("5/22/1982", "5/28/1982", true)); | ||
}); | ||
}); | ||
}); | ||
describe("merge()", function() { | ||
var someDays, someTime; | ||
someTime = thatDay("5:30", "8:30"); | ||
someDays = new Twix("5/24/1982", "5/25/1982", true); | ||
describe("non-all-day events", function() { | ||
it("spans a later time", function() { | ||
return assertDeepEqual(thatDay("5:30", "11:30"), someTime.merge(thatDay("9:30", "11:30"))); | ||
}); | ||
it("spans an earlier time", function() { | ||
return assertDeepEqual(thatDay("3:30", "8:30"), someTime.merge(thatDay("3:30", "4:30"))); | ||
}); | ||
it("spans a partially later event", function() { | ||
return assertDeepEqual(thatDay("5:30", "11:30"), someTime.merge(thatDay("8:00", "11:30"))); | ||
}); | ||
it("spans a partially earlier event", function() { | ||
return assertDeepEqual(thatDay("4:30", "8:30"), someTime.merge(thatDay("4:30", "6:30"))); | ||
}); | ||
it("isn't affected by engulfed events", function() { | ||
return assertDeepEqual(someTime, someTime.merge(thatDay("6:30", "7:30"))); | ||
}); | ||
return it("becomes an engulfing event", function() { | ||
return assertDeepEqual(thatDay("4:30", "9:30"), someTime.merge(thatDay("4:30", "9:30"))); | ||
}); | ||
}); | ||
describe("one all-day event", function() { | ||
it("spans a later time", function() { | ||
console.log(someDays.trueEnd()); | ||
return assertDeepEqual(new Twix("5/24/1982 00:00", "5/26/1982 7:00"), someDays.merge(new Twix("5/24/1982 20:00", "5/26/1982 7:00"))); | ||
}); | ||
it("spans an earlier time", function() { | ||
return assertDeepEqual(new Twix("5/23/1982 8:00", moment("5/25/1982").eod()), someDays.merge(new Twix("5/23/1982 8:00", "5/25/1982 7:00"))); | ||
}); | ||
it("isn't affected by engulfing events", function() { | ||
return assertDeepEqual(new Twix("5/24/1982 00:00", moment("5/25/1982").eod()), someDays.merge(someTime)); | ||
}); | ||
return it("becomes an engulfing event", function() { | ||
return assertDeepEqual(new Twix("5/23/1982 20:00", "5/26/1982 8:30"), someDays.merge(new Twix("5/23/1982 20:00", "5/26/1982 8:30"))); | ||
}); | ||
}); | ||
return describe("two all-day events", function() { | ||
it("spans a later time", function() { | ||
return assertDeepEqual(new Twix("5/24/1982", "5/28/1982", true), someDays.merge(new Twix("5/27/1982", "5/28/1982", true))); | ||
}); | ||
it("spans an earlier time", function() { | ||
return assertDeepEqual(new Twix("5/21/1982", "5/25/1982", true), someDays.merge(new Twix("5/21/1982", "5/22/1982", true))); | ||
}); | ||
it("spans a partially later time", function() { | ||
return assertDeepEqual(new Twix("5/24/1982", "5/26/1982", true), someDays.merge(new Twix("5/25/1982", "5/26/1982", true))); | ||
}); | ||
it("spans a partially earlier time", function() { | ||
return assertDeepEqual(new Twix("5/23/1982", "5/25/1982", true), someDays.merge(new Twix("5/23/1982", "5/25/1982", true))); | ||
}); | ||
it("isn't affected by engulfing events", function() { | ||
return assertDeepEqual(someDays, someDays.merge(thatDay())); | ||
}); | ||
return it("becomes an engulfing event", function() { | ||
return assertDeepEqual(someDays, thatDay().merge(someDays)); | ||
}); | ||
}); | ||
}); | ||
describe("format()", function() { | ||
@@ -224,3 +483,3 @@ var test; | ||
}); | ||
return test("different year different month shows the month at the end", { | ||
test("different year different month shows the month at the end", { | ||
start: "5/25/1982", | ||
@@ -231,2 +490,11 @@ end: "6/1/1983", | ||
}); | ||
return test("explicit allDay", { | ||
start: "5/25/1982", | ||
end: "5/25/1982", | ||
allDay: true, | ||
options: { | ||
explicitAllDay: true | ||
}, | ||
result: "all day May 25, 1982" | ||
}); | ||
}); | ||
@@ -307,3 +575,3 @@ describe("no single dates", function() { | ||
}); | ||
return describe("show day of week", function() { | ||
describe("show day of week", function() { | ||
test("should show day of week", { | ||
@@ -335,4 +603,57 @@ start: thisYear("5/25", "5:30 AM"), | ||
}); | ||
return describe("goes into the morning", function() { | ||
test("elides late nights", { | ||
start: "5/25/1982 5:00 PM", | ||
end: "5/26/1982 2:00 AM", | ||
options: { | ||
lastNightEndsAt: 5 | ||
}, | ||
result: "May 25, 1982, 5 PM - 2 AM" | ||
}); | ||
test("keeps late mornings", { | ||
start: "5/25/1982 5:00 PM", | ||
end: "5/26/1982 10:00 AM", | ||
options: { | ||
lastNightEndsAt: 5 | ||
}, | ||
result: "May 25, 5 PM - May 26, 10 AM, 1982" | ||
}); | ||
test("morning start is adjustable", { | ||
start: "5/25/1982 5:00 PM", | ||
end: "5/26/1982 10:00 AM", | ||
options: { | ||
lastNightEndsAt: 11 | ||
}, | ||
result: "May 25, 1982, 5 PM - 10 AM" | ||
}); | ||
test("doesn't elide if you start in the AM", { | ||
start: "5/25/1982 5:00 AM", | ||
end: "5/26/1982 4:00 AM", | ||
options: { | ||
lastNightEndsAt: 5 | ||
}, | ||
result: "May 25, 5 AM - May 26, 4 AM, 1982" | ||
}); | ||
return describe("and we're trying to hide the date", function() { | ||
test("elides the date too for early mornings", { | ||
start: "5/25/1982 5:00 PM", | ||
end: "5/26/1982 2:00 AM", | ||
options: { | ||
lastNightEndsAt: 5, | ||
showDate: false | ||
}, | ||
result: "5 PM - 2 AM" | ||
}); | ||
return test("doesn't elide if the morning ends late", { | ||
start: "5/25/1982 5:00 PM", | ||
end: "5/26/1982 10:00 AM", | ||
options: { | ||
lastNightEndsAt: 5 | ||
}, | ||
result: "May 25, 5 PM - May 26, 10 AM, 1982" | ||
}); | ||
}); | ||
}); | ||
}); | ||
}).call(this); |
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
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
149445
2611
0
+ Addedmoment@1.6.2(transitive)
- Removedmoment@2.30.1(transitive)
Updatedmoment@1.6