@acpaas-ui/js-date-utils
Advanced tools
Comparing version 1.0.1-alpha.2 to 1.0.1-alpha.3
@@ -1,2 +0,2 @@ | ||
define(["exports"],function(exports){"use strict";var addLeadingZero=function(){var value=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",strValue=String(value);return strValue.length>=2?strValue:0===strValue.length?"00":"0"+strValue},parseDate=function(d){return d instanceof Date?isNaN(d.valueOf())?null:d:isNaN(Date.parse(d))?null:new Date(d)},getMonthLength=function(date){if(!parseDate(date))return-1;var monthStart=new Date(date),monthEnd=new Date(date);return monthStart.setDate(1),monthEnd.setMonth(monthStart.getMonth()+1,1),Math.round((monthEnd-monthStart)/864e5)},closestDateForRange=function(date,range){if(!parseDate(date))return null;if(!range||!Array.isArray(range))return new Date(date);var monthLength=getMonthLength(date),dates=Array.from(Array(monthLength),function(val,index){return index+1}).filter(function(val){return range.indexOf(val)<0}),startDate=date.getDate(),closestDay=dates.reduce(function(prev,curr){return Math.abs(curr-startDate)<Math.abs(prev-startDate)?curr:prev},-1),closestDate=new Date(date);return closestDate.setDate(closestDay),closestDate},dateOutOfRange=function(date,range){return!!parseDate(date)&&(!range||!Array.isArray(range)||range.indexOf(date.getDate())<0)},dateValuesAreEqual=function(){var dates=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],comparator=arguments[1];return comparator in new Date&&dates.map(function(date){return parseDate(date)?date[comparator]():-1}).reduce(function(acc,curr,i){return 0===i?acc=curr:acc>=0&&curr>=0&&acc===curr?acc:-1})>=0},datesAreEqual=function(){var dates=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],specifier=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"value";if(!dates.length)return!1;var compareMethods={Y:"getFullYear",M:"getMonth",D:"getDate",h:"getHours",m:"getMinutes",s:"getSeconds",ms:"getMilliseconds",value:"valueOf"},compareDates=function(d,s){var verifiedSpecifier=compareMethods.hasOwnProperty(s)?compareMethods[s]:compareMethods.value;return dateValuesAreEqual(d,verifiedSpecifier)};if(Array.isArray(specifier)){for(var i=0;i<specifier.length;i+=1)if(!compareDates(dates,specifier[i]))return!1;return!0}return compareDates(dates,specifier)},DEFAULT_FORMATTING_OPTIONS={leadingZero:!1,monthLabels:["January","February","March","April","May","June","July","August","September","October","November","December"],weekdayLabels:["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]},getWeekday=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var weekday=(date.getDay()-startOfWeek)%7;return weekday<0?weekday+7:weekday},formatDate=function(dateString){var format=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",options=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},date=parseDate(dateString);if(!date)return null;var formattingOptions=babelHelpers.extends({},DEFAULT_FORMATTING_OPTIONS,options),formats={YY:function(d){return addLeadingZero(String(d.getFullYear()).substr(2),formattingOptions.leadingZero)},YYYY:function(d){return addLeadingZero(d.getFullYear(),formattingOptions.leadingZero)},MM:function(d){return addLeadingZero(d.getMonth()+1,formattingOptions.leadingZero)},MMMM:function(d){return addLeadingZero(formattingOptions.monthLabels[d.getMonth()],formattingOptions.leadingZero)},DD:function(d){return addLeadingZero(d.getDate(),formattingOptions.leadingZero)},DDDD:function(d){return addLeadingZero(formattingOptions.weekdayLabels[getWeekday(d,options.startOfWeek)],formattingOptions.leadingZero)},hh:function(d){return addLeadingZero(d.getHours(),formattingOptions.leadingZero)},mm:function(d){return addLeadingZero(d.getMinutes(),formattingOptions.leadingZero)},ss:function(d){return addLeadingZero(d.getSeconds(),formattingOptions.leadingZero)},ms:function(d){return addLeadingZero(d.getMilliseconds(),formattingOptions.leadingZero)}};return format.split(/[^YMDhms]/).reduce(function(acc,curr){return formats.hasOwnProperty(curr)?acc.replace(curr,formats[curr](date)):acc},format)},getFirstWeekdayOfMonth=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var providedDate=new Date(date);return providedDate.setDate(1),getWeekday(providedDate,startOfWeek)},getLastWeekdayOfMonth=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var providedDate=new Date(date),monthLength=getMonthLength(providedDate);return providedDate.setDate(monthLength),getWeekday(providedDate,startOfWeek)},updateDate=function(date,day){if(!parseDate(date)||isNaN(parseInt(day,10)))return date;var targetDate=new Date(date),targetMonthLength=getMonthLength(targetDate);return day>targetMonthLength?targetDate.setDate(targetMonthLength):targetDate.setDate(day),targetDate},updateMonth=function(date,month){if(!parseDate(date)||isNaN(parseInt(month,10)))return date;var targetDate=new Date(date),day=targetDate.getDate(),year=targetDate.getFullYear();return month>11?(year+=1,month-=12):month<0&&(year-=1,month+=12),targetDate.setDate(1),targetDate.setMonth(month),targetDate.setFullYear(year),updateDate(targetDate,day)},week=function(start){var options=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},padding=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],offset=options.hasOwnProperty("offset")?options.offset:0,dayOffset=options.hasOwnProperty("dayOffset")?options.dayOffset:0,addPadding=options.hasOwnProperty("padding")&&options.padding,fromStart=options.hasOwnProperty("fromStart")&&options.fromStart;start=start||(dayOffset>0?0:1);for(var val,weekLength=addPadding?7:7-offset,week=[],i=start;i<start+weekLength;i+=1)if(val=i,addPadding&&(fromStart?val<start+offset:val>start+(6-offset))){if(addPadding){var paddingIndex=fromStart?i-start:i-start-(7-offset);week.push({date:padding.length?padding[paddingIndex]:null,padding:!0})}}else week.push({date:(fromStart&&addPadding?i-offset:i)+dayOffset});return week},padding=function(date){var count=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,fromStart=arguments[2],padding=[];if(!parseDate(date))return padding;for(var targetMonth=updateMonth(date,fromStart?date.getMonth()-1:date.getMonth()+1),monthLength=getMonthLength(targetMonth),i=0;i<count&&(padding.push(fromStart?monthLength-(count-i-1):padding.length+1),fromStart||!(i>=monthLength));i+=1);return padding},month=function(date){var options=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!parseDate(date))return[];for(var startOfWeek=options.startOfWeek||0,monthLength=getMonthLength(date),startOfMonth=getFirstWeekdayOfMonth(date,startOfWeek),endOfMonth=getLastWeekdayOfMonth(date,startOfWeek),offsetStart=startOfMonth,offsetEnd=monthLength-endOfMonth,firstWeek=week(0,{offset:offsetStart,dayOffset:startOfWeek,fromStart:!0,padding:options.padding},options.generatePadding?padding(date,offsetStart,!0):[]),lastWeek=week(offsetEnd,{offset:6-endOfMonth,padding:options.padding},options.generatePadding?padding(date,offsetEnd):[]),wholeWeeks=Math.floor((lastWeek[0].date-firstWeek[firstWeek.length-1].date)/7),weeks=[firstWeek],i=0;i<wholeWeeks;i+=1){var currDate=weeks[i][weeks[i].length-1].date+1;weeks.push(week(currDate))}return weeks.push(lastWeek),weeks},range=function(date,range){var options=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!parseDate(date)||!range||range&&!range.length)return[];var dateRange=[],weekdays=[];return range.forEach(function(value){if(value instanceof Date){var dateValue=(rangeDate=value)instanceof Date&&datesAreEqual([date,rangeDate],["Y","M"])?rangeDate.getDate():null;return!!dateValue&&dateRange.push(dateValue)}var rangeDate;isNaN(parseInt(value,10))||weekdays.push(value)}),weekdays.length&&(dateRange=dateRange.concat(function(targetDate,weekdays,_ref){for(var _ref$startOfWeek=_ref.startOfWeek,offset=getFirstWeekdayOfMonth(date,void 0===_ref$startOfWeek?0:_ref$startOfWeek),monthLength=getMonthLength(date),dateRange=[],i=0;i<monthLength;i+=1)weekdays.indexOf((i+offset)%7)>=0&&dateRange.push(i+1);return dateRange}(0,weekdays,options))),dateRange.reduce(function(acc,curr){return acc.indexOf(curr)>=0?acc:acc.concat(curr)},[]).sort(function(val1,val2){return val1-val2})},DateHelper=function DateHelper(){babelHelpers.classCallCheck(this,DateHelper)};DateHelper.addLeadingZero=addLeadingZero,DateHelper.closestDateForRange=closestDateForRange,DateHelper.dateOutOfRange=dateOutOfRange,DateHelper.datesAreEqual=datesAreEqual,DateHelper.dateValuesAreEqual=dateValuesAreEqual,DateHelper.formatDate=formatDate,DateHelper.getFirstWeekdayOfMonth=getFirstWeekdayOfMonth,DateHelper.getLastWeekdayOfMonth=getLastWeekdayOfMonth,DateHelper.getMonthLength=getMonthLength,DateHelper.getWeekday=getWeekday,DateHelper.parseDate=parseDate,DateHelper.updateDate=updateDate,DateHelper.updateMonth=updateMonth;var DateGenerator=function DateGenerator(){babelHelpers.classCallCheck(this,DateGenerator)};DateGenerator.generateMonth=month,DateGenerator.generatePadding=padding,DateGenerator.generateRange=range,DateGenerator.generateWeek=week,exports.addLeadingZero=addLeadingZero,exports.closestDateForRange=closestDateForRange,exports.dateOutOfRange=dateOutOfRange,exports.datesAreEqual=datesAreEqual,exports.dateValuesAreEqual=dateValuesAreEqual,exports.formatDate=formatDate,exports.getFirstWeekdayOfMonth=getFirstWeekdayOfMonth,exports.getLastWeekdayOfMonth=getLastWeekdayOfMonth,exports.getMonthLength=getMonthLength,exports.getWeekday=getWeekday,exports.parseDate=parseDate,exports.updateDate=updateDate,exports.updateMonth=updateMonth,exports.generateMonth=month,exports.generatePadding=padding,exports.generateRange=range,exports.generateWeek=week,exports.DEFAULT_FORMATTING_OPTIONS=DEFAULT_FORMATTING_OPTIONS,exports.DateHelper=DateHelper,exports.DateGenerator=DateGenerator,Object.defineProperty(exports,"__esModule",{value:!0})}); | ||
define(["exports"],function(exports){"use strict";var addLeadingZero=function(){var value=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",strValue=String(value);return strValue.length>=2?strValue:0===strValue.length?"00":"0"+strValue},parseDate=function(d){return d instanceof Date?isNaN(d.valueOf())?null:d:isNaN(Date.parse(d))?null:new Date(d)},getMonthLength=function(date){if(!parseDate(date))return-1;var monthStart=new Date(date),monthEnd=new Date(date);return monthStart.setDate(1),monthEnd.setMonth(monthStart.getMonth()+1,1),Math.round((monthEnd-monthStart)/864e5)},closestDateForRange=function(date,range){if(!parseDate(date))return null;if(!range||!Array.isArray(range))return new Date(date);var monthLength=getMonthLength(date),dates=Array.from(Array(monthLength),function(val,index){return index+1}).filter(function(val){return range.indexOf(val)<0}),startDate=date.getDate(),closestDay=dates.reduce(function(prev,curr){return Math.abs(curr-startDate)<Math.abs(prev-startDate)?curr:prev},-1),closestDate=new Date(date);return closestDate.setDate(closestDay),closestDate},dateOutOfRange=function(date,range){return!!parseDate(date)&&(!range||!Array.isArray(range)||range.indexOf(date.getDate())<0)},dateValuesAreEqual=function(){var dates=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],comparator=arguments[1];return comparator in new Date&&dates.map(function(date){return parseDate(date)?date[comparator]():-1}).reduce(function(acc,curr,i){return 0===i?acc=curr:acc>=0&&curr>=0&&acc===curr?acc:-1})>=0},datesAreEqual=function(){var dates=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],specifier=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"value";if(!dates.length)return!1;var compareMethods={Y:"getFullYear",M:"getMonth",D:"getDate",h:"getHours",m:"getMinutes",s:"getSeconds",ms:"getMilliseconds",value:"valueOf"},compareDates=function(d,s){var verifiedSpecifier=compareMethods.hasOwnProperty(s)?compareMethods[s]:compareMethods.value;return dateValuesAreEqual(d,verifiedSpecifier)};if(Array.isArray(specifier)){for(var i=0;i<specifier.length;i+=1)if(!compareDates(dates,specifier[i]))return!1;return!0}return compareDates(dates,specifier)},DEFAULT_FORMATTING_OPTIONS={leadingZero:!1,monthLabels:["January","February","March","April","May","June","July","August","September","October","November","December"],weekdayLabels:["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]},getWeekday=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var weekday=(date.getDay()-startOfWeek)%7;return weekday<0?weekday+7:weekday},classCallCheck=function(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")},_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source)Object.prototype.hasOwnProperty.call(source,key)&&(target[key]=source[key])}return target},formatDate=function(dateString){var format=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",options=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},date=parseDate(dateString);if(!date)return null;var formattingOptions=_extends({},DEFAULT_FORMATTING_OPTIONS,options),formats={YY:function(d){return addLeadingZero(String(d.getFullYear()).substr(2),formattingOptions.leadingZero)},YYYY:function(d){return addLeadingZero(d.getFullYear(),formattingOptions.leadingZero)},MM:function(d){return addLeadingZero(d.getMonth()+1,formattingOptions.leadingZero)},MMMM:function(d){return addLeadingZero(formattingOptions.monthLabels[d.getMonth()],formattingOptions.leadingZero)},DD:function(d){return addLeadingZero(d.getDate(),formattingOptions.leadingZero)},DDDD:function(d){return addLeadingZero(formattingOptions.weekdayLabels[getWeekday(d,options.startOfWeek)],formattingOptions.leadingZero)},hh:function(d){return addLeadingZero(d.getHours(),formattingOptions.leadingZero)},mm:function(d){return addLeadingZero(d.getMinutes(),formattingOptions.leadingZero)},ss:function(d){return addLeadingZero(d.getSeconds(),formattingOptions.leadingZero)},ms:function(d){return addLeadingZero(d.getMilliseconds(),formattingOptions.leadingZero)}};return format.split(/[^YMDhms]/).reduce(function(acc,curr){return formats.hasOwnProperty(curr)?acc.replace(curr,formats[curr](date)):acc},format)},getFirstWeekdayOfMonth=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var providedDate=new Date(date);return providedDate.setDate(1),getWeekday(providedDate,startOfWeek)},getLastWeekdayOfMonth=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var providedDate=new Date(date),monthLength=getMonthLength(providedDate);return providedDate.setDate(monthLength),getWeekday(providedDate,startOfWeek)},updateDate=function(date,day){if(!parseDate(date)||isNaN(parseInt(day,10)))return date;var targetDate=new Date(date),targetMonthLength=getMonthLength(targetDate);return day>targetMonthLength?targetDate.setDate(targetMonthLength):targetDate.setDate(day),targetDate},updateMonth=function(date,month){if(!parseDate(date)||isNaN(parseInt(month,10)))return date;var targetDate=new Date(date),day=targetDate.getDate(),year=targetDate.getFullYear();return month>11?(year+=1,month-=12):month<0&&(year-=1,month+=12),targetDate.setDate(1),targetDate.setMonth(month),targetDate.setFullYear(year),updateDate(targetDate,day)},week=function(start){var options=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},padding=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],offset=options.hasOwnProperty("offset")?options.offset:0,dayOffset=options.hasOwnProperty("dayOffset")?options.dayOffset:0,addPadding=options.hasOwnProperty("padding")&&options.padding,fromStart=options.hasOwnProperty("fromStart")&&options.fromStart;start=start||(dayOffset>0?0:1);for(var val,weekLength=addPadding?7:7-offset,week=[],i=start;i<start+weekLength;i+=1)if(val=i,addPadding&&(fromStart?val<start+offset:val>start+(6-offset))){if(addPadding){var paddingIndex=fromStart?i-start:i-start-(7-offset);week.push({date:padding.length?padding[paddingIndex]:null,padding:!0})}}else week.push({date:(fromStart&&addPadding?i-offset:i)+dayOffset});return week},padding=function(date){var count=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,fromStart=arguments[2],padding=[];if(!parseDate(date))return padding;for(var targetMonth=updateMonth(date,fromStart?date.getMonth()-1:date.getMonth()+1),monthLength=getMonthLength(targetMonth),i=0;i<count&&(padding.push(fromStart?monthLength-(count-i-1):padding.length+1),fromStart||!(i>=monthLength));i+=1);return padding},month=function(date){var options=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!parseDate(date))return[];for(var startOfWeek=options.startOfWeek||0,monthLength=getMonthLength(date),startOfMonth=getFirstWeekdayOfMonth(date,startOfWeek),endOfMonth=getLastWeekdayOfMonth(date,startOfWeek),offsetStart=startOfMonth,offsetEnd=monthLength-endOfMonth,firstWeek=week(0,{offset:offsetStart,dayOffset:startOfWeek,fromStart:!0,padding:options.padding},options.generatePadding?padding(date,offsetStart,!0):[]),lastWeek=week(offsetEnd,{offset:6-endOfMonth,padding:options.padding},options.generatePadding?padding(date,offsetEnd):[]),wholeWeeks=Math.floor((lastWeek[0].date-firstWeek[firstWeek.length-1].date)/7),weeks=[firstWeek],i=0;i<wholeWeeks;i+=1){var currDate=weeks[i][weeks[i].length-1].date+1;weeks.push(week(currDate))}return weeks.push(lastWeek),weeks},range=function(date,range){var options=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!parseDate(date)||!range||range&&!range.length)return[];var dateRange=[],weekdays=[];return range.forEach(function(value){if(value instanceof Date){var dateValue=(rangeDate=value)instanceof Date&&datesAreEqual([date,rangeDate],["Y","M"])?rangeDate.getDate():null;return!!dateValue&&dateRange.push(dateValue)}var rangeDate;isNaN(parseInt(value,10))||weekdays.push(value)}),weekdays.length&&(dateRange=dateRange.concat(function(targetDate,weekdays,_ref){for(var _ref$startOfWeek=_ref.startOfWeek,offset=getFirstWeekdayOfMonth(date,void 0===_ref$startOfWeek?0:_ref$startOfWeek),monthLength=getMonthLength(date),dateRange=[],i=0;i<monthLength;i+=1)weekdays.indexOf((i+offset)%7)>=0&&dateRange.push(i+1);return dateRange}(0,weekdays,options))),dateRange.reduce(function(acc,curr){return acc.indexOf(curr)>=0?acc:acc.concat(curr)},[]).sort(function(val1,val2){return val1-val2})},DateHelper=function DateHelper(){classCallCheck(this,DateHelper)};DateHelper.addLeadingZero=addLeadingZero,DateHelper.closestDateForRange=closestDateForRange,DateHelper.dateOutOfRange=dateOutOfRange,DateHelper.datesAreEqual=datesAreEqual,DateHelper.dateValuesAreEqual=dateValuesAreEqual,DateHelper.formatDate=formatDate,DateHelper.getFirstWeekdayOfMonth=getFirstWeekdayOfMonth,DateHelper.getLastWeekdayOfMonth=getLastWeekdayOfMonth,DateHelper.getMonthLength=getMonthLength,DateHelper.getWeekday=getWeekday,DateHelper.parseDate=parseDate,DateHelper.updateDate=updateDate,DateHelper.updateMonth=updateMonth;var DateGenerator=function DateGenerator(){classCallCheck(this,DateGenerator)};DateGenerator.generateMonth=month,DateGenerator.generatePadding=padding,DateGenerator.generateRange=range,DateGenerator.generateWeek=week,exports.addLeadingZero=addLeadingZero,exports.closestDateForRange=closestDateForRange,exports.dateOutOfRange=dateOutOfRange,exports.datesAreEqual=datesAreEqual,exports.dateValuesAreEqual=dateValuesAreEqual,exports.formatDate=formatDate,exports.getFirstWeekdayOfMonth=getFirstWeekdayOfMonth,exports.getLastWeekdayOfMonth=getLastWeekdayOfMonth,exports.getMonthLength=getMonthLength,exports.getWeekday=getWeekday,exports.parseDate=parseDate,exports.updateDate=updateDate,exports.updateMonth=updateMonth,exports.generateMonth=month,exports.generatePadding=padding,exports.generateRange=range,exports.generateWeek=week,exports.DEFAULT_FORMATTING_OPTIONS=DEFAULT_FORMATTING_OPTIONS,exports.DateHelper=DateHelper,exports.DateGenerator=DateGenerator,Object.defineProperty(exports,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=acpaas-ui-js-date-utils.amd.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var addLeadingZero=function(){var value=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",strValue=String(value);return strValue.length>=2?strValue:0===strValue.length?"00":"0"+strValue},parseDate=function(d){return d instanceof Date?isNaN(d.valueOf())?null:d:isNaN(Date.parse(d))?null:new Date(d)},getMonthLength=function(date){if(!parseDate(date))return-1;var monthStart=new Date(date),monthEnd=new Date(date);return monthStart.setDate(1),monthEnd.setMonth(monthStart.getMonth()+1,1),Math.round((monthEnd-monthStart)/864e5)},closestDateForRange=function(date,range){if(!parseDate(date))return null;if(!range||!Array.isArray(range))return new Date(date);var monthLength=getMonthLength(date),dates=Array.from(Array(monthLength),function(val,index){return index+1}).filter(function(val){return range.indexOf(val)<0}),startDate=date.getDate(),closestDay=dates.reduce(function(prev,curr){return Math.abs(curr-startDate)<Math.abs(prev-startDate)?curr:prev},-1),closestDate=new Date(date);return closestDate.setDate(closestDay),closestDate},dateOutOfRange=function(date,range){return!!parseDate(date)&&(!range||!Array.isArray(range)||range.indexOf(date.getDate())<0)},dateValuesAreEqual=function(){var dates=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],comparator=arguments[1];return comparator in new Date&&dates.map(function(date){return parseDate(date)?date[comparator]():-1}).reduce(function(acc,curr,i){return 0===i?acc=curr:acc>=0&&curr>=0&&acc===curr?acc:-1})>=0},datesAreEqual=function(){var dates=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],specifier=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"value";if(!dates.length)return!1;var compareMethods={Y:"getFullYear",M:"getMonth",D:"getDate",h:"getHours",m:"getMinutes",s:"getSeconds",ms:"getMilliseconds",value:"valueOf"},compareDates=function(d,s){var verifiedSpecifier=compareMethods.hasOwnProperty(s)?compareMethods[s]:compareMethods.value;return dateValuesAreEqual(d,verifiedSpecifier)};if(Array.isArray(specifier)){for(var i=0;i<specifier.length;i+=1)if(!compareDates(dates,specifier[i]))return!1;return!0}return compareDates(dates,specifier)},DEFAULT_FORMATTING_OPTIONS={leadingZero:!1,monthLabels:["January","February","March","April","May","June","July","August","September","October","November","December"],weekdayLabels:["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]},getWeekday=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var weekday=(date.getDay()-startOfWeek)%7;return weekday<0?weekday+7:weekday},formatDate=function(dateString){var format=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",options=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},date=parseDate(dateString);if(!date)return null;var formattingOptions=babelHelpers.extends({},DEFAULT_FORMATTING_OPTIONS,options),formats={YY:function(d){return addLeadingZero(String(d.getFullYear()).substr(2),formattingOptions.leadingZero)},YYYY:function(d){return addLeadingZero(d.getFullYear(),formattingOptions.leadingZero)},MM:function(d){return addLeadingZero(d.getMonth()+1,formattingOptions.leadingZero)},MMMM:function(d){return addLeadingZero(formattingOptions.monthLabels[d.getMonth()],formattingOptions.leadingZero)},DD:function(d){return addLeadingZero(d.getDate(),formattingOptions.leadingZero)},DDDD:function(d){return addLeadingZero(formattingOptions.weekdayLabels[getWeekday(d,options.startOfWeek)],formattingOptions.leadingZero)},hh:function(d){return addLeadingZero(d.getHours(),formattingOptions.leadingZero)},mm:function(d){return addLeadingZero(d.getMinutes(),formattingOptions.leadingZero)},ss:function(d){return addLeadingZero(d.getSeconds(),formattingOptions.leadingZero)},ms:function(d){return addLeadingZero(d.getMilliseconds(),formattingOptions.leadingZero)}};return format.split(/[^YMDhms]/).reduce(function(acc,curr){return formats.hasOwnProperty(curr)?acc.replace(curr,formats[curr](date)):acc},format)},getFirstWeekdayOfMonth=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var providedDate=new Date(date);return providedDate.setDate(1),getWeekday(providedDate,startOfWeek)},getLastWeekdayOfMonth=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var providedDate=new Date(date),monthLength=getMonthLength(providedDate);return providedDate.setDate(monthLength),getWeekday(providedDate,startOfWeek)},updateDate=function(date,day){if(!parseDate(date)||isNaN(parseInt(day,10)))return date;var targetDate=new Date(date),targetMonthLength=getMonthLength(targetDate);return day>targetMonthLength?targetDate.setDate(targetMonthLength):targetDate.setDate(day),targetDate},updateMonth=function(date,month){if(!parseDate(date)||isNaN(parseInt(month,10)))return date;var targetDate=new Date(date),day=targetDate.getDate(),year=targetDate.getFullYear();return month>11?(year+=1,month-=12):month<0&&(year-=1,month+=12),targetDate.setDate(1),targetDate.setMonth(month),targetDate.setFullYear(year),updateDate(targetDate,day)},week=function(start){var options=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},padding=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],offset=options.hasOwnProperty("offset")?options.offset:0,dayOffset=options.hasOwnProperty("dayOffset")?options.dayOffset:0,addPadding=options.hasOwnProperty("padding")&&options.padding,fromStart=options.hasOwnProperty("fromStart")&&options.fromStart;start=start||(dayOffset>0?0:1);for(var val,weekLength=addPadding?7:7-offset,week=[],i=start;i<start+weekLength;i+=1)if(val=i,addPadding&&(fromStart?val<start+offset:val>start+(6-offset))){if(addPadding){var paddingIndex=fromStart?i-start:i-start-(7-offset);week.push({date:padding.length?padding[paddingIndex]:null,padding:!0})}}else week.push({date:(fromStart&&addPadding?i-offset:i)+dayOffset});return week},padding=function(date){var count=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,fromStart=arguments[2],padding=[];if(!parseDate(date))return padding;for(var targetMonth=updateMonth(date,fromStart?date.getMonth()-1:date.getMonth()+1),monthLength=getMonthLength(targetMonth),i=0;i<count&&(padding.push(fromStart?monthLength-(count-i-1):padding.length+1),fromStart||!(i>=monthLength));i+=1);return padding},month=function(date){var options=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!parseDate(date))return[];for(var startOfWeek=options.startOfWeek||0,monthLength=getMonthLength(date),startOfMonth=getFirstWeekdayOfMonth(date,startOfWeek),endOfMonth=getLastWeekdayOfMonth(date,startOfWeek),offsetStart=startOfMonth,offsetEnd=monthLength-endOfMonth,firstWeek=week(0,{offset:offsetStart,dayOffset:startOfWeek,fromStart:!0,padding:options.padding},options.generatePadding?padding(date,offsetStart,!0):[]),lastWeek=week(offsetEnd,{offset:6-endOfMonth,padding:options.padding},options.generatePadding?padding(date,offsetEnd):[]),wholeWeeks=Math.floor((lastWeek[0].date-firstWeek[firstWeek.length-1].date)/7),weeks=[firstWeek],i=0;i<wholeWeeks;i+=1){var currDate=weeks[i][weeks[i].length-1].date+1;weeks.push(week(currDate))}return weeks.push(lastWeek),weeks},range=function(date,range){var options=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!parseDate(date)||!range||range&&!range.length)return[];var dateRange=[],weekdays=[];return range.forEach(function(value){if(value instanceof Date){var dateValue=(rangeDate=value)instanceof Date&&datesAreEqual([date,rangeDate],["Y","M"])?rangeDate.getDate():null;return!!dateValue&&dateRange.push(dateValue)}var rangeDate;isNaN(parseInt(value,10))||weekdays.push(value)}),weekdays.length&&(dateRange=dateRange.concat(function(targetDate,weekdays,_ref){for(var _ref$startOfWeek=_ref.startOfWeek,offset=getFirstWeekdayOfMonth(date,void 0===_ref$startOfWeek?0:_ref$startOfWeek),monthLength=getMonthLength(date),dateRange=[],i=0;i<monthLength;i+=1)weekdays.indexOf((i+offset)%7)>=0&&dateRange.push(i+1);return dateRange}(0,weekdays,options))),dateRange.reduce(function(acc,curr){return acc.indexOf(curr)>=0?acc:acc.concat(curr)},[]).sort(function(val1,val2){return val1-val2})},DateHelper=function DateHelper(){babelHelpers.classCallCheck(this,DateHelper)};DateHelper.addLeadingZero=addLeadingZero,DateHelper.closestDateForRange=closestDateForRange,DateHelper.dateOutOfRange=dateOutOfRange,DateHelper.datesAreEqual=datesAreEqual,DateHelper.dateValuesAreEqual=dateValuesAreEqual,DateHelper.formatDate=formatDate,DateHelper.getFirstWeekdayOfMonth=getFirstWeekdayOfMonth,DateHelper.getLastWeekdayOfMonth=getLastWeekdayOfMonth,DateHelper.getMonthLength=getMonthLength,DateHelper.getWeekday=getWeekday,DateHelper.parseDate=parseDate,DateHelper.updateDate=updateDate,DateHelper.updateMonth=updateMonth;var DateGenerator=function DateGenerator(){babelHelpers.classCallCheck(this,DateGenerator)};DateGenerator.generateMonth=month,DateGenerator.generatePadding=padding,DateGenerator.generateRange=range,DateGenerator.generateWeek=week,exports.addLeadingZero=addLeadingZero,exports.closestDateForRange=closestDateForRange,exports.dateOutOfRange=dateOutOfRange,exports.datesAreEqual=datesAreEqual,exports.dateValuesAreEqual=dateValuesAreEqual,exports.formatDate=formatDate,exports.getFirstWeekdayOfMonth=getFirstWeekdayOfMonth,exports.getLastWeekdayOfMonth=getLastWeekdayOfMonth,exports.getMonthLength=getMonthLength,exports.getWeekday=getWeekday,exports.parseDate=parseDate,exports.updateDate=updateDate,exports.updateMonth=updateMonth,exports.generateMonth=month,exports.generatePadding=padding,exports.generateRange=range,exports.generateWeek=week,exports.DEFAULT_FORMATTING_OPTIONS=DEFAULT_FORMATTING_OPTIONS,exports.DateHelper=DateHelper,exports.DateGenerator=DateGenerator; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var addLeadingZero=function(){var value=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",strValue=String(value);return strValue.length>=2?strValue:0===strValue.length?"00":"0"+strValue},parseDate=function(d){return d instanceof Date?isNaN(d.valueOf())?null:d:isNaN(Date.parse(d))?null:new Date(d)},getMonthLength=function(date){if(!parseDate(date))return-1;var monthStart=new Date(date),monthEnd=new Date(date);return monthStart.setDate(1),monthEnd.setMonth(monthStart.getMonth()+1,1),Math.round((monthEnd-monthStart)/864e5)},closestDateForRange=function(date,range){if(!parseDate(date))return null;if(!range||!Array.isArray(range))return new Date(date);var monthLength=getMonthLength(date),dates=Array.from(Array(monthLength),function(val,index){return index+1}).filter(function(val){return range.indexOf(val)<0}),startDate=date.getDate(),closestDay=dates.reduce(function(prev,curr){return Math.abs(curr-startDate)<Math.abs(prev-startDate)?curr:prev},-1),closestDate=new Date(date);return closestDate.setDate(closestDay),closestDate},dateOutOfRange=function(date,range){return!!parseDate(date)&&(!range||!Array.isArray(range)||range.indexOf(date.getDate())<0)},dateValuesAreEqual=function(){var dates=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],comparator=arguments[1];return comparator in new Date&&dates.map(function(date){return parseDate(date)?date[comparator]():-1}).reduce(function(acc,curr,i){return 0===i?acc=curr:acc>=0&&curr>=0&&acc===curr?acc:-1})>=0},datesAreEqual=function(){var dates=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],specifier=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"value";if(!dates.length)return!1;var compareMethods={Y:"getFullYear",M:"getMonth",D:"getDate",h:"getHours",m:"getMinutes",s:"getSeconds",ms:"getMilliseconds",value:"valueOf"},compareDates=function(d,s){var verifiedSpecifier=compareMethods.hasOwnProperty(s)?compareMethods[s]:compareMethods.value;return dateValuesAreEqual(d,verifiedSpecifier)};if(Array.isArray(specifier)){for(var i=0;i<specifier.length;i+=1)if(!compareDates(dates,specifier[i]))return!1;return!0}return compareDates(dates,specifier)},DEFAULT_FORMATTING_OPTIONS={leadingZero:!1,monthLabels:["January","February","March","April","May","June","July","August","September","October","November","December"],weekdayLabels:["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]},getWeekday=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var weekday=(date.getDay()-startOfWeek)%7;return weekday<0?weekday+7:weekday},classCallCheck=function(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")},_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source)Object.prototype.hasOwnProperty.call(source,key)&&(target[key]=source[key])}return target},formatDate=function(dateString){var format=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",options=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},date=parseDate(dateString);if(!date)return null;var formattingOptions=_extends({},DEFAULT_FORMATTING_OPTIONS,options),formats={YY:function(d){return addLeadingZero(String(d.getFullYear()).substr(2),formattingOptions.leadingZero)},YYYY:function(d){return addLeadingZero(d.getFullYear(),formattingOptions.leadingZero)},MM:function(d){return addLeadingZero(d.getMonth()+1,formattingOptions.leadingZero)},MMMM:function(d){return addLeadingZero(formattingOptions.monthLabels[d.getMonth()],formattingOptions.leadingZero)},DD:function(d){return addLeadingZero(d.getDate(),formattingOptions.leadingZero)},DDDD:function(d){return addLeadingZero(formattingOptions.weekdayLabels[getWeekday(d,options.startOfWeek)],formattingOptions.leadingZero)},hh:function(d){return addLeadingZero(d.getHours(),formattingOptions.leadingZero)},mm:function(d){return addLeadingZero(d.getMinutes(),formattingOptions.leadingZero)},ss:function(d){return addLeadingZero(d.getSeconds(),formattingOptions.leadingZero)},ms:function(d){return addLeadingZero(d.getMilliseconds(),formattingOptions.leadingZero)}};return format.split(/[^YMDhms]/).reduce(function(acc,curr){return formats.hasOwnProperty(curr)?acc.replace(curr,formats[curr](date)):acc},format)},getFirstWeekdayOfMonth=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var providedDate=new Date(date);return providedDate.setDate(1),getWeekday(providedDate,startOfWeek)},getLastWeekdayOfMonth=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var providedDate=new Date(date),monthLength=getMonthLength(providedDate);return providedDate.setDate(monthLength),getWeekday(providedDate,startOfWeek)},updateDate=function(date,day){if(!parseDate(date)||isNaN(parseInt(day,10)))return date;var targetDate=new Date(date),targetMonthLength=getMonthLength(targetDate);return day>targetMonthLength?targetDate.setDate(targetMonthLength):targetDate.setDate(day),targetDate},updateMonth=function(date,month){if(!parseDate(date)||isNaN(parseInt(month,10)))return date;var targetDate=new Date(date),day=targetDate.getDate(),year=targetDate.getFullYear();return month>11?(year+=1,month-=12):month<0&&(year-=1,month+=12),targetDate.setDate(1),targetDate.setMonth(month),targetDate.setFullYear(year),updateDate(targetDate,day)},week=function(start){var options=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},padding=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],offset=options.hasOwnProperty("offset")?options.offset:0,dayOffset=options.hasOwnProperty("dayOffset")?options.dayOffset:0,addPadding=options.hasOwnProperty("padding")&&options.padding,fromStart=options.hasOwnProperty("fromStart")&&options.fromStart;start=start||(dayOffset>0?0:1);for(var val,weekLength=addPadding?7:7-offset,week=[],i=start;i<start+weekLength;i+=1)if(val=i,addPadding&&(fromStart?val<start+offset:val>start+(6-offset))){if(addPadding){var paddingIndex=fromStart?i-start:i-start-(7-offset);week.push({date:padding.length?padding[paddingIndex]:null,padding:!0})}}else week.push({date:(fromStart&&addPadding?i-offset:i)+dayOffset});return week},padding=function(date){var count=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,fromStart=arguments[2],padding=[];if(!parseDate(date))return padding;for(var targetMonth=updateMonth(date,fromStart?date.getMonth()-1:date.getMonth()+1),monthLength=getMonthLength(targetMonth),i=0;i<count&&(padding.push(fromStart?monthLength-(count-i-1):padding.length+1),fromStart||!(i>=monthLength));i+=1);return padding},month=function(date){var options=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!parseDate(date))return[];for(var startOfWeek=options.startOfWeek||0,monthLength=getMonthLength(date),startOfMonth=getFirstWeekdayOfMonth(date,startOfWeek),endOfMonth=getLastWeekdayOfMonth(date,startOfWeek),offsetStart=startOfMonth,offsetEnd=monthLength-endOfMonth,firstWeek=week(0,{offset:offsetStart,dayOffset:startOfWeek,fromStart:!0,padding:options.padding},options.generatePadding?padding(date,offsetStart,!0):[]),lastWeek=week(offsetEnd,{offset:6-endOfMonth,padding:options.padding},options.generatePadding?padding(date,offsetEnd):[]),wholeWeeks=Math.floor((lastWeek[0].date-firstWeek[firstWeek.length-1].date)/7),weeks=[firstWeek],i=0;i<wholeWeeks;i+=1){var currDate=weeks[i][weeks[i].length-1].date+1;weeks.push(week(currDate))}return weeks.push(lastWeek),weeks},range=function(date,range){var options=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!parseDate(date)||!range||range&&!range.length)return[];var dateRange=[],weekdays=[];return range.forEach(function(value){if(value instanceof Date){var dateValue=(rangeDate=value)instanceof Date&&datesAreEqual([date,rangeDate],["Y","M"])?rangeDate.getDate():null;return!!dateValue&&dateRange.push(dateValue)}var rangeDate;isNaN(parseInt(value,10))||weekdays.push(value)}),weekdays.length&&(dateRange=dateRange.concat(function(targetDate,weekdays,_ref){for(var _ref$startOfWeek=_ref.startOfWeek,offset=getFirstWeekdayOfMonth(date,void 0===_ref$startOfWeek?0:_ref$startOfWeek),monthLength=getMonthLength(date),dateRange=[],i=0;i<monthLength;i+=1)weekdays.indexOf((i+offset)%7)>=0&&dateRange.push(i+1);return dateRange}(0,weekdays,options))),dateRange.reduce(function(acc,curr){return acc.indexOf(curr)>=0?acc:acc.concat(curr)},[]).sort(function(val1,val2){return val1-val2})},DateHelper=function DateHelper(){classCallCheck(this,DateHelper)};DateHelper.addLeadingZero=addLeadingZero,DateHelper.closestDateForRange=closestDateForRange,DateHelper.dateOutOfRange=dateOutOfRange,DateHelper.datesAreEqual=datesAreEqual,DateHelper.dateValuesAreEqual=dateValuesAreEqual,DateHelper.formatDate=formatDate,DateHelper.getFirstWeekdayOfMonth=getFirstWeekdayOfMonth,DateHelper.getLastWeekdayOfMonth=getLastWeekdayOfMonth,DateHelper.getMonthLength=getMonthLength,DateHelper.getWeekday=getWeekday,DateHelper.parseDate=parseDate,DateHelper.updateDate=updateDate,DateHelper.updateMonth=updateMonth;var DateGenerator=function DateGenerator(){classCallCheck(this,DateGenerator)};DateGenerator.generateMonth=month,DateGenerator.generatePadding=padding,DateGenerator.generateRange=range,DateGenerator.generateWeek=week,exports.addLeadingZero=addLeadingZero,exports.closestDateForRange=closestDateForRange,exports.dateOutOfRange=dateOutOfRange,exports.datesAreEqual=datesAreEqual,exports.dateValuesAreEqual=dateValuesAreEqual,exports.formatDate=formatDate,exports.getFirstWeekdayOfMonth=getFirstWeekdayOfMonth,exports.getLastWeekdayOfMonth=getLastWeekdayOfMonth,exports.getMonthLength=getMonthLength,exports.getWeekday=getWeekday,exports.parseDate=parseDate,exports.updateDate=updateDate,exports.updateMonth=updateMonth,exports.generateMonth=month,exports.generatePadding=padding,exports.generateRange=range,exports.generateWeek=week,exports.DEFAULT_FORMATTING_OPTIONS=DEFAULT_FORMATTING_OPTIONS,exports.DateHelper=DateHelper,exports.DateGenerator=DateGenerator; | ||
//# sourceMappingURL=acpaas-ui-js-date-utils.cjs.js.map |
@@ -1,2 +0,2 @@ | ||
var addLeadingZero=function(){var value=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",strValue=String(value);return strValue.length>=2?strValue:0===strValue.length?"00":"0"+strValue},parseDate=function(d){return d instanceof Date?isNaN(d.valueOf())?null:d:isNaN(Date.parse(d))?null:new Date(d)},getMonthLength=function(date){if(!parseDate(date))return-1;var monthStart=new Date(date),monthEnd=new Date(date);return monthStart.setDate(1),monthEnd.setMonth(monthStart.getMonth()+1,1),Math.round((monthEnd-monthStart)/864e5)},closestDateForRange=function(date,range){if(!parseDate(date))return null;if(!range||!Array.isArray(range))return new Date(date);var monthLength=getMonthLength(date),dates=Array.from(Array(monthLength),function(val,index){return index+1}).filter(function(val){return range.indexOf(val)<0}),startDate=date.getDate(),closestDay=dates.reduce(function(prev,curr){return Math.abs(curr-startDate)<Math.abs(prev-startDate)?curr:prev},-1),closestDate=new Date(date);return closestDate.setDate(closestDay),closestDate},dateOutOfRange=function(date,range){return!!parseDate(date)&&(!range||!Array.isArray(range)||range.indexOf(date.getDate())<0)},dateValuesAreEqual=function(){var dates=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],comparator=arguments[1];return comparator in new Date&&dates.map(function(date){return parseDate(date)?date[comparator]():-1}).reduce(function(acc,curr,i){return 0===i?acc=curr:acc>=0&&curr>=0&&acc===curr?acc:-1})>=0},datesAreEqual=function(){var dates=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],specifier=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"value";if(!dates.length)return!1;var compareMethods={Y:"getFullYear",M:"getMonth",D:"getDate",h:"getHours",m:"getMinutes",s:"getSeconds",ms:"getMilliseconds",value:"valueOf"},compareDates=function(d,s){var verifiedSpecifier=compareMethods.hasOwnProperty(s)?compareMethods[s]:compareMethods.value;return dateValuesAreEqual(d,verifiedSpecifier)};if(Array.isArray(specifier)){for(var i=0;i<specifier.length;i+=1)if(!compareDates(dates,specifier[i]))return!1;return!0}return compareDates(dates,specifier)},DEFAULT_FORMATTING_OPTIONS={leadingZero:!1,monthLabels:["January","February","March","April","May","June","July","August","September","October","November","December"],weekdayLabels:["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]},getWeekday=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var weekday=(date.getDay()-startOfWeek)%7;return weekday<0?weekday+7:weekday},formatDate=function(dateString){var format=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",options=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},date=parseDate(dateString);if(!date)return null;var formattingOptions=babelHelpers.extends({},DEFAULT_FORMATTING_OPTIONS,options),formats={YY:function(d){return addLeadingZero(String(d.getFullYear()).substr(2),formattingOptions.leadingZero)},YYYY:function(d){return addLeadingZero(d.getFullYear(),formattingOptions.leadingZero)},MM:function(d){return addLeadingZero(d.getMonth()+1,formattingOptions.leadingZero)},MMMM:function(d){return addLeadingZero(formattingOptions.monthLabels[d.getMonth()],formattingOptions.leadingZero)},DD:function(d){return addLeadingZero(d.getDate(),formattingOptions.leadingZero)},DDDD:function(d){return addLeadingZero(formattingOptions.weekdayLabels[getWeekday(d,options.startOfWeek)],formattingOptions.leadingZero)},hh:function(d){return addLeadingZero(d.getHours(),formattingOptions.leadingZero)},mm:function(d){return addLeadingZero(d.getMinutes(),formattingOptions.leadingZero)},ss:function(d){return addLeadingZero(d.getSeconds(),formattingOptions.leadingZero)},ms:function(d){return addLeadingZero(d.getMilliseconds(),formattingOptions.leadingZero)}};return format.split(/[^YMDhms]/).reduce(function(acc,curr){return formats.hasOwnProperty(curr)?acc.replace(curr,formats[curr](date)):acc},format)},getFirstWeekdayOfMonth=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var providedDate=new Date(date);return providedDate.setDate(1),getWeekday(providedDate,startOfWeek)},getLastWeekdayOfMonth=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var providedDate=new Date(date),monthLength=getMonthLength(providedDate);return providedDate.setDate(monthLength),getWeekday(providedDate,startOfWeek)},updateDate=function(date,day){if(!parseDate(date)||isNaN(parseInt(day,10)))return date;var targetDate=new Date(date),targetMonthLength=getMonthLength(targetDate);return day>targetMonthLength?targetDate.setDate(targetMonthLength):targetDate.setDate(day),targetDate},updateMonth=function(date,month){if(!parseDate(date)||isNaN(parseInt(month,10)))return date;var targetDate=new Date(date),day=targetDate.getDate(),year=targetDate.getFullYear();return month>11?(year+=1,month-=12):month<0&&(year-=1,month+=12),targetDate.setDate(1),targetDate.setMonth(month),targetDate.setFullYear(year),updateDate(targetDate,day)},week=function(start){var options=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},padding=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],offset=options.hasOwnProperty("offset")?options.offset:0,dayOffset=options.hasOwnProperty("dayOffset")?options.dayOffset:0,addPadding=options.hasOwnProperty("padding")&&options.padding,fromStart=options.hasOwnProperty("fromStart")&&options.fromStart;start=start||(dayOffset>0?0:1);for(var val,weekLength=addPadding?7:7-offset,week=[],i=start;i<start+weekLength;i+=1)if(val=i,addPadding&&(fromStart?val<start+offset:val>start+(6-offset))){if(addPadding){var paddingIndex=fromStart?i-start:i-start-(7-offset);week.push({date:padding.length?padding[paddingIndex]:null,padding:!0})}}else week.push({date:(fromStart&&addPadding?i-offset:i)+dayOffset});return week},padding=function(date){var count=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,fromStart=arguments[2],padding=[];if(!parseDate(date))return padding;for(var targetMonth=updateMonth(date,fromStart?date.getMonth()-1:date.getMonth()+1),monthLength=getMonthLength(targetMonth),i=0;i<count&&(padding.push(fromStart?monthLength-(count-i-1):padding.length+1),fromStart||!(i>=monthLength));i+=1);return padding},month=function(date){var options=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!parseDate(date))return[];for(var startOfWeek=options.startOfWeek||0,monthLength=getMonthLength(date),startOfMonth=getFirstWeekdayOfMonth(date,startOfWeek),endOfMonth=getLastWeekdayOfMonth(date,startOfWeek),offsetStart=startOfMonth,offsetEnd=monthLength-endOfMonth,firstWeek=week(0,{offset:offsetStart,dayOffset:startOfWeek,fromStart:!0,padding:options.padding},options.generatePadding?padding(date,offsetStart,!0):[]),lastWeek=week(offsetEnd,{offset:6-endOfMonth,padding:options.padding},options.generatePadding?padding(date,offsetEnd):[]),wholeWeeks=Math.floor((lastWeek[0].date-firstWeek[firstWeek.length-1].date)/7),weeks=[firstWeek],i=0;i<wholeWeeks;i+=1){var currDate=weeks[i][weeks[i].length-1].date+1;weeks.push(week(currDate))}return weeks.push(lastWeek),weeks},range=function(date,range){var options=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!parseDate(date)||!range||range&&!range.length)return[];var dateRange=[],weekdays=[];return range.forEach(function(value){if(value instanceof Date){var dateValue=(rangeDate=value)instanceof Date&&datesAreEqual([date,rangeDate],["Y","M"])?rangeDate.getDate():null;return!!dateValue&&dateRange.push(dateValue)}var rangeDate;isNaN(parseInt(value,10))||weekdays.push(value)}),weekdays.length&&(dateRange=dateRange.concat(function(targetDate,weekdays,_ref){for(var _ref$startOfWeek=_ref.startOfWeek,offset=getFirstWeekdayOfMonth(date,void 0===_ref$startOfWeek?0:_ref$startOfWeek),monthLength=getMonthLength(date),dateRange=[],i=0;i<monthLength;i+=1)weekdays.indexOf((i+offset)%7)>=0&&dateRange.push(i+1);return dateRange}(0,weekdays,options))),dateRange.reduce(function(acc,curr){return acc.indexOf(curr)>=0?acc:acc.concat(curr)},[]).sort(function(val1,val2){return val1-val2})},DateHelper=function DateHelper(){babelHelpers.classCallCheck(this,DateHelper)};DateHelper.addLeadingZero=addLeadingZero,DateHelper.closestDateForRange=closestDateForRange,DateHelper.dateOutOfRange=dateOutOfRange,DateHelper.datesAreEqual=datesAreEqual,DateHelper.dateValuesAreEqual=dateValuesAreEqual,DateHelper.formatDate=formatDate,DateHelper.getFirstWeekdayOfMonth=getFirstWeekdayOfMonth,DateHelper.getLastWeekdayOfMonth=getLastWeekdayOfMonth,DateHelper.getMonthLength=getMonthLength,DateHelper.getWeekday=getWeekday,DateHelper.parseDate=parseDate,DateHelper.updateDate=updateDate,DateHelper.updateMonth=updateMonth;var DateGenerator=function DateGenerator(){babelHelpers.classCallCheck(this,DateGenerator)};DateGenerator.generateMonth=month,DateGenerator.generatePadding=padding,DateGenerator.generateRange=range,DateGenerator.generateWeek=week;export{addLeadingZero,closestDateForRange,dateOutOfRange,datesAreEqual,dateValuesAreEqual,formatDate,getFirstWeekdayOfMonth,getLastWeekdayOfMonth,getMonthLength,getWeekday,parseDate,updateDate,updateMonth,month as generateMonth,padding as generatePadding,range as generateRange,week as generateWeek,DEFAULT_FORMATTING_OPTIONS,DateHelper,DateGenerator}; | ||
var addLeadingZero=function(){var value=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",strValue=String(value);return strValue.length>=2?strValue:0===strValue.length?"00":"0"+strValue},parseDate=function(d){return d instanceof Date?isNaN(d.valueOf())?null:d:isNaN(Date.parse(d))?null:new Date(d)},getMonthLength=function(date){if(!parseDate(date))return-1;var monthStart=new Date(date),monthEnd=new Date(date);return monthStart.setDate(1),monthEnd.setMonth(monthStart.getMonth()+1,1),Math.round((monthEnd-monthStart)/864e5)},closestDateForRange=function(date,range){if(!parseDate(date))return null;if(!range||!Array.isArray(range))return new Date(date);var monthLength=getMonthLength(date),dates=Array.from(Array(monthLength),function(val,index){return index+1}).filter(function(val){return range.indexOf(val)<0}),startDate=date.getDate(),closestDay=dates.reduce(function(prev,curr){return Math.abs(curr-startDate)<Math.abs(prev-startDate)?curr:prev},-1),closestDate=new Date(date);return closestDate.setDate(closestDay),closestDate},dateOutOfRange=function(date,range){return!!parseDate(date)&&(!range||!Array.isArray(range)||range.indexOf(date.getDate())<0)},dateValuesAreEqual=function(){var dates=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],comparator=arguments[1];return comparator in new Date&&dates.map(function(date){return parseDate(date)?date[comparator]():-1}).reduce(function(acc,curr,i){return 0===i?acc=curr:acc>=0&&curr>=0&&acc===curr?acc:-1})>=0},datesAreEqual=function(){var dates=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],specifier=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"value";if(!dates.length)return!1;var compareMethods={Y:"getFullYear",M:"getMonth",D:"getDate",h:"getHours",m:"getMinutes",s:"getSeconds",ms:"getMilliseconds",value:"valueOf"},compareDates=function(d,s){var verifiedSpecifier=compareMethods.hasOwnProperty(s)?compareMethods[s]:compareMethods.value;return dateValuesAreEqual(d,verifiedSpecifier)};if(Array.isArray(specifier)){for(var i=0;i<specifier.length;i+=1)if(!compareDates(dates,specifier[i]))return!1;return!0}return compareDates(dates,specifier)},DEFAULT_FORMATTING_OPTIONS={leadingZero:!1,monthLabels:["January","February","March","April","May","June","July","August","September","October","November","December"],weekdayLabels:["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]},getWeekday=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var weekday=(date.getDay()-startOfWeek)%7;return weekday<0?weekday+7:weekday},classCallCheck=function(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")},_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source)Object.prototype.hasOwnProperty.call(source,key)&&(target[key]=source[key])}return target},formatDate=function(dateString){var format=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",options=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},date=parseDate(dateString);if(!date)return null;var formattingOptions=_extends({},DEFAULT_FORMATTING_OPTIONS,options),formats={YY:function(d){return addLeadingZero(String(d.getFullYear()).substr(2),formattingOptions.leadingZero)},YYYY:function(d){return addLeadingZero(d.getFullYear(),formattingOptions.leadingZero)},MM:function(d){return addLeadingZero(d.getMonth()+1,formattingOptions.leadingZero)},MMMM:function(d){return addLeadingZero(formattingOptions.monthLabels[d.getMonth()],formattingOptions.leadingZero)},DD:function(d){return addLeadingZero(d.getDate(),formattingOptions.leadingZero)},DDDD:function(d){return addLeadingZero(formattingOptions.weekdayLabels[getWeekday(d,options.startOfWeek)],formattingOptions.leadingZero)},hh:function(d){return addLeadingZero(d.getHours(),formattingOptions.leadingZero)},mm:function(d){return addLeadingZero(d.getMinutes(),formattingOptions.leadingZero)},ss:function(d){return addLeadingZero(d.getSeconds(),formattingOptions.leadingZero)},ms:function(d){return addLeadingZero(d.getMilliseconds(),formattingOptions.leadingZero)}};return format.split(/[^YMDhms]/).reduce(function(acc,curr){return formats.hasOwnProperty(curr)?acc.replace(curr,formats[curr](date)):acc},format)},getFirstWeekdayOfMonth=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var providedDate=new Date(date);return providedDate.setDate(1),getWeekday(providedDate,startOfWeek)},getLastWeekdayOfMonth=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var providedDate=new Date(date),monthLength=getMonthLength(providedDate);return providedDate.setDate(monthLength),getWeekday(providedDate,startOfWeek)},updateDate=function(date,day){if(!parseDate(date)||isNaN(parseInt(day,10)))return date;var targetDate=new Date(date),targetMonthLength=getMonthLength(targetDate);return day>targetMonthLength?targetDate.setDate(targetMonthLength):targetDate.setDate(day),targetDate},updateMonth=function(date,month){if(!parseDate(date)||isNaN(parseInt(month,10)))return date;var targetDate=new Date(date),day=targetDate.getDate(),year=targetDate.getFullYear();return month>11?(year+=1,month-=12):month<0&&(year-=1,month+=12),targetDate.setDate(1),targetDate.setMonth(month),targetDate.setFullYear(year),updateDate(targetDate,day)},week=function(start){var options=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},padding=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],offset=options.hasOwnProperty("offset")?options.offset:0,dayOffset=options.hasOwnProperty("dayOffset")?options.dayOffset:0,addPadding=options.hasOwnProperty("padding")&&options.padding,fromStart=options.hasOwnProperty("fromStart")&&options.fromStart;start=start||(dayOffset>0?0:1);for(var val,weekLength=addPadding?7:7-offset,week=[],i=start;i<start+weekLength;i+=1)if(val=i,addPadding&&(fromStart?val<start+offset:val>start+(6-offset))){if(addPadding){var paddingIndex=fromStart?i-start:i-start-(7-offset);week.push({date:padding.length?padding[paddingIndex]:null,padding:!0})}}else week.push({date:(fromStart&&addPadding?i-offset:i)+dayOffset});return week},padding=function(date){var count=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,fromStart=arguments[2],padding=[];if(!parseDate(date))return padding;for(var targetMonth=updateMonth(date,fromStart?date.getMonth()-1:date.getMonth()+1),monthLength=getMonthLength(targetMonth),i=0;i<count&&(padding.push(fromStart?monthLength-(count-i-1):padding.length+1),fromStart||!(i>=monthLength));i+=1);return padding},month=function(date){var options=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!parseDate(date))return[];for(var startOfWeek=options.startOfWeek||0,monthLength=getMonthLength(date),startOfMonth=getFirstWeekdayOfMonth(date,startOfWeek),endOfMonth=getLastWeekdayOfMonth(date,startOfWeek),offsetStart=startOfMonth,offsetEnd=monthLength-endOfMonth,firstWeek=week(0,{offset:offsetStart,dayOffset:startOfWeek,fromStart:!0,padding:options.padding},options.generatePadding?padding(date,offsetStart,!0):[]),lastWeek=week(offsetEnd,{offset:6-endOfMonth,padding:options.padding},options.generatePadding?padding(date,offsetEnd):[]),wholeWeeks=Math.floor((lastWeek[0].date-firstWeek[firstWeek.length-1].date)/7),weeks=[firstWeek],i=0;i<wholeWeeks;i+=1){var currDate=weeks[i][weeks[i].length-1].date+1;weeks.push(week(currDate))}return weeks.push(lastWeek),weeks},range=function(date,range){var options=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!parseDate(date)||!range||range&&!range.length)return[];var dateRange=[],weekdays=[];return range.forEach(function(value){if(value instanceof Date){var dateValue=(rangeDate=value)instanceof Date&&datesAreEqual([date,rangeDate],["Y","M"])?rangeDate.getDate():null;return!!dateValue&&dateRange.push(dateValue)}var rangeDate;isNaN(parseInt(value,10))||weekdays.push(value)}),weekdays.length&&(dateRange=dateRange.concat(function(targetDate,weekdays,_ref){for(var _ref$startOfWeek=_ref.startOfWeek,offset=getFirstWeekdayOfMonth(date,void 0===_ref$startOfWeek?0:_ref$startOfWeek),monthLength=getMonthLength(date),dateRange=[],i=0;i<monthLength;i+=1)weekdays.indexOf((i+offset)%7)>=0&&dateRange.push(i+1);return dateRange}(0,weekdays,options))),dateRange.reduce(function(acc,curr){return acc.indexOf(curr)>=0?acc:acc.concat(curr)},[]).sort(function(val1,val2){return val1-val2})},DateHelper=function DateHelper(){classCallCheck(this,DateHelper)};DateHelper.addLeadingZero=addLeadingZero,DateHelper.closestDateForRange=closestDateForRange,DateHelper.dateOutOfRange=dateOutOfRange,DateHelper.datesAreEqual=datesAreEqual,DateHelper.dateValuesAreEqual=dateValuesAreEqual,DateHelper.formatDate=formatDate,DateHelper.getFirstWeekdayOfMonth=getFirstWeekdayOfMonth,DateHelper.getLastWeekdayOfMonth=getLastWeekdayOfMonth,DateHelper.getMonthLength=getMonthLength,DateHelper.getWeekday=getWeekday,DateHelper.parseDate=parseDate,DateHelper.updateDate=updateDate,DateHelper.updateMonth=updateMonth;var DateGenerator=function DateGenerator(){classCallCheck(this,DateGenerator)};DateGenerator.generateMonth=month,DateGenerator.generatePadding=padding,DateGenerator.generateRange=range,DateGenerator.generateWeek=week;export{addLeadingZero,closestDateForRange,dateOutOfRange,datesAreEqual,dateValuesAreEqual,formatDate,getFirstWeekdayOfMonth,getLastWeekdayOfMonth,getMonthLength,getWeekday,parseDate,updateDate,updateMonth,month as generateMonth,padding as generatePadding,range as generateRange,week as generateWeek,DEFAULT_FORMATTING_OPTIONS,DateHelper,DateGenerator}; | ||
//# sourceMappingURL=acpaas-ui-js-date-utils.es.js.map |
@@ -1,2 +0,2 @@ | ||
!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?factory(exports):"function"==typeof define&&define.amd?define(["exports"],factory):factory(global["@acpaas-ui/js-date-utils"]=global["@acpaas-ui/js-date-utils"]||{})}(this,function(exports){"use strict";var addLeadingZero=function(){var value=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",strValue=String(value);return strValue.length>=2?strValue:0===strValue.length?"00":"0"+strValue},parseDate=function(d){return d instanceof Date?isNaN(d.valueOf())?null:d:isNaN(Date.parse(d))?null:new Date(d)},getMonthLength=function(date){if(!parseDate(date))return-1;var monthStart=new Date(date),monthEnd=new Date(date);return monthStart.setDate(1),monthEnd.setMonth(monthStart.getMonth()+1,1),Math.round((monthEnd-monthStart)/864e5)},closestDateForRange=function(date,range){if(!parseDate(date))return null;if(!range||!Array.isArray(range))return new Date(date);var monthLength=getMonthLength(date),dates=Array.from(Array(monthLength),function(val,index){return index+1}).filter(function(val){return range.indexOf(val)<0}),startDate=date.getDate(),closestDay=dates.reduce(function(prev,curr){return Math.abs(curr-startDate)<Math.abs(prev-startDate)?curr:prev},-1),closestDate=new Date(date);return closestDate.setDate(closestDay),closestDate},dateOutOfRange=function(date,range){return!!parseDate(date)&&(!range||!Array.isArray(range)||range.indexOf(date.getDate())<0)},dateValuesAreEqual=function(){var dates=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],comparator=arguments[1];return comparator in new Date&&dates.map(function(date){return parseDate(date)?date[comparator]():-1}).reduce(function(acc,curr,i){return 0===i?acc=curr:acc>=0&&curr>=0&&acc===curr?acc:-1})>=0},datesAreEqual=function(){var dates=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],specifier=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"value";if(!dates.length)return!1;var compareMethods={Y:"getFullYear",M:"getMonth",D:"getDate",h:"getHours",m:"getMinutes",s:"getSeconds",ms:"getMilliseconds",value:"valueOf"},compareDates=function(d,s){var verifiedSpecifier=compareMethods.hasOwnProperty(s)?compareMethods[s]:compareMethods.value;return dateValuesAreEqual(d,verifiedSpecifier)};if(Array.isArray(specifier)){for(var i=0;i<specifier.length;i+=1)if(!compareDates(dates,specifier[i]))return!1;return!0}return compareDates(dates,specifier)},DEFAULT_FORMATTING_OPTIONS={leadingZero:!1,monthLabels:["January","February","March","April","May","June","July","August","September","October","November","December"],weekdayLabels:["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]},getWeekday=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var weekday=(date.getDay()-startOfWeek)%7;return weekday<0?weekday+7:weekday},formatDate=function(dateString){var format=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",options=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},date=parseDate(dateString);if(!date)return null;var formattingOptions=babelHelpers.extends({},DEFAULT_FORMATTING_OPTIONS,options),formats={YY:function(d){return addLeadingZero(String(d.getFullYear()).substr(2),formattingOptions.leadingZero)},YYYY:function(d){return addLeadingZero(d.getFullYear(),formattingOptions.leadingZero)},MM:function(d){return addLeadingZero(d.getMonth()+1,formattingOptions.leadingZero)},MMMM:function(d){return addLeadingZero(formattingOptions.monthLabels[d.getMonth()],formattingOptions.leadingZero)},DD:function(d){return addLeadingZero(d.getDate(),formattingOptions.leadingZero)},DDDD:function(d){return addLeadingZero(formattingOptions.weekdayLabels[getWeekday(d,options.startOfWeek)],formattingOptions.leadingZero)},hh:function(d){return addLeadingZero(d.getHours(),formattingOptions.leadingZero)},mm:function(d){return addLeadingZero(d.getMinutes(),formattingOptions.leadingZero)},ss:function(d){return addLeadingZero(d.getSeconds(),formattingOptions.leadingZero)},ms:function(d){return addLeadingZero(d.getMilliseconds(),formattingOptions.leadingZero)}};return format.split(/[^YMDhms]/).reduce(function(acc,curr){return formats.hasOwnProperty(curr)?acc.replace(curr,formats[curr](date)):acc},format)},getFirstWeekdayOfMonth=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var providedDate=new Date(date);return providedDate.setDate(1),getWeekday(providedDate,startOfWeek)},getLastWeekdayOfMonth=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var providedDate=new Date(date),monthLength=getMonthLength(providedDate);return providedDate.setDate(monthLength),getWeekday(providedDate,startOfWeek)},updateDate=function(date,day){if(!parseDate(date)||isNaN(parseInt(day,10)))return date;var targetDate=new Date(date),targetMonthLength=getMonthLength(targetDate);return day>targetMonthLength?targetDate.setDate(targetMonthLength):targetDate.setDate(day),targetDate},updateMonth=function(date,month){if(!parseDate(date)||isNaN(parseInt(month,10)))return date;var targetDate=new Date(date),day=targetDate.getDate(),year=targetDate.getFullYear();return month>11?(year+=1,month-=12):month<0&&(year-=1,month+=12),targetDate.setDate(1),targetDate.setMonth(month),targetDate.setFullYear(year),updateDate(targetDate,day)},week=function(start){var options=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},padding=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],offset=options.hasOwnProperty("offset")?options.offset:0,dayOffset=options.hasOwnProperty("dayOffset")?options.dayOffset:0,addPadding=options.hasOwnProperty("padding")&&options.padding,fromStart=options.hasOwnProperty("fromStart")&&options.fromStart;start=start||(dayOffset>0?0:1);for(var val,weekLength=addPadding?7:7-offset,week=[],i=start;i<start+weekLength;i+=1)if(val=i,addPadding&&(fromStart?val<start+offset:val>start+(6-offset))){if(addPadding){var paddingIndex=fromStart?i-start:i-start-(7-offset);week.push({date:padding.length?padding[paddingIndex]:null,padding:!0})}}else week.push({date:(fromStart&&addPadding?i-offset:i)+dayOffset});return week},padding=function(date){var count=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,fromStart=arguments[2],padding=[];if(!parseDate(date))return padding;for(var targetMonth=updateMonth(date,fromStart?date.getMonth()-1:date.getMonth()+1),monthLength=getMonthLength(targetMonth),i=0;i<count&&(padding.push(fromStart?monthLength-(count-i-1):padding.length+1),fromStart||!(i>=monthLength));i+=1);return padding},month=function(date){var options=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!parseDate(date))return[];for(var startOfWeek=options.startOfWeek||0,monthLength=getMonthLength(date),startOfMonth=getFirstWeekdayOfMonth(date,startOfWeek),endOfMonth=getLastWeekdayOfMonth(date,startOfWeek),offsetStart=startOfMonth,offsetEnd=monthLength-endOfMonth,firstWeek=week(0,{offset:offsetStart,dayOffset:startOfWeek,fromStart:!0,padding:options.padding},options.generatePadding?padding(date,offsetStart,!0):[]),lastWeek=week(offsetEnd,{offset:6-endOfMonth,padding:options.padding},options.generatePadding?padding(date,offsetEnd):[]),wholeWeeks=Math.floor((lastWeek[0].date-firstWeek[firstWeek.length-1].date)/7),weeks=[firstWeek],i=0;i<wholeWeeks;i+=1){var currDate=weeks[i][weeks[i].length-1].date+1;weeks.push(week(currDate))}return weeks.push(lastWeek),weeks},range=function(date,range){var options=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!parseDate(date)||!range||range&&!range.length)return[];var dateRange=[],weekdays=[];return range.forEach(function(value){if(value instanceof Date){var dateValue=(rangeDate=value)instanceof Date&&datesAreEqual([date,rangeDate],["Y","M"])?rangeDate.getDate():null;return!!dateValue&&dateRange.push(dateValue)}var rangeDate;isNaN(parseInt(value,10))||weekdays.push(value)}),weekdays.length&&(dateRange=dateRange.concat(function(targetDate,weekdays,_ref){for(var _ref$startOfWeek=_ref.startOfWeek,offset=getFirstWeekdayOfMonth(date,void 0===_ref$startOfWeek?0:_ref$startOfWeek),monthLength=getMonthLength(date),dateRange=[],i=0;i<monthLength;i+=1)weekdays.indexOf((i+offset)%7)>=0&&dateRange.push(i+1);return dateRange}(0,weekdays,options))),dateRange.reduce(function(acc,curr){return acc.indexOf(curr)>=0?acc:acc.concat(curr)},[]).sort(function(val1,val2){return val1-val2})},DateHelper=function DateHelper(){babelHelpers.classCallCheck(this,DateHelper)};DateHelper.addLeadingZero=addLeadingZero,DateHelper.closestDateForRange=closestDateForRange,DateHelper.dateOutOfRange=dateOutOfRange,DateHelper.datesAreEqual=datesAreEqual,DateHelper.dateValuesAreEqual=dateValuesAreEqual,DateHelper.formatDate=formatDate,DateHelper.getFirstWeekdayOfMonth=getFirstWeekdayOfMonth,DateHelper.getLastWeekdayOfMonth=getLastWeekdayOfMonth,DateHelper.getMonthLength=getMonthLength,DateHelper.getWeekday=getWeekday,DateHelper.parseDate=parseDate,DateHelper.updateDate=updateDate,DateHelper.updateMonth=updateMonth;var DateGenerator=function DateGenerator(){babelHelpers.classCallCheck(this,DateGenerator)};DateGenerator.generateMonth=month,DateGenerator.generatePadding=padding,DateGenerator.generateRange=range,DateGenerator.generateWeek=week,exports.addLeadingZero=addLeadingZero,exports.closestDateForRange=closestDateForRange,exports.dateOutOfRange=dateOutOfRange,exports.datesAreEqual=datesAreEqual,exports.dateValuesAreEqual=dateValuesAreEqual,exports.formatDate=formatDate,exports.getFirstWeekdayOfMonth=getFirstWeekdayOfMonth,exports.getLastWeekdayOfMonth=getLastWeekdayOfMonth,exports.getMonthLength=getMonthLength,exports.getWeekday=getWeekday,exports.parseDate=parseDate,exports.updateDate=updateDate,exports.updateMonth=updateMonth,exports.generateMonth=month,exports.generatePadding=padding,exports.generateRange=range,exports.generateWeek=week,exports.DEFAULT_FORMATTING_OPTIONS=DEFAULT_FORMATTING_OPTIONS,exports.DateHelper=DateHelper,exports.DateGenerator=DateGenerator,Object.defineProperty(exports,"__esModule",{value:!0})}); | ||
!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?factory(exports):"function"==typeof define&&define.amd?define(["exports"],factory):factory(global["@acpaas-ui/js-date-utils"]=global["@acpaas-ui/js-date-utils"]||{})}(this,function(exports){"use strict";var addLeadingZero=function(){var value=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",strValue=String(value);return strValue.length>=2?strValue:0===strValue.length?"00":"0"+strValue},parseDate=function(d){return d instanceof Date?isNaN(d.valueOf())?null:d:isNaN(Date.parse(d))?null:new Date(d)},getMonthLength=function(date){if(!parseDate(date))return-1;var monthStart=new Date(date),monthEnd=new Date(date);return monthStart.setDate(1),monthEnd.setMonth(monthStart.getMonth()+1,1),Math.round((monthEnd-monthStart)/864e5)},closestDateForRange=function(date,range){if(!parseDate(date))return null;if(!range||!Array.isArray(range))return new Date(date);var monthLength=getMonthLength(date),dates=Array.from(Array(monthLength),function(val,index){return index+1}).filter(function(val){return range.indexOf(val)<0}),startDate=date.getDate(),closestDay=dates.reduce(function(prev,curr){return Math.abs(curr-startDate)<Math.abs(prev-startDate)?curr:prev},-1),closestDate=new Date(date);return closestDate.setDate(closestDay),closestDate},dateOutOfRange=function(date,range){return!!parseDate(date)&&(!range||!Array.isArray(range)||range.indexOf(date.getDate())<0)},dateValuesAreEqual=function(){var dates=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],comparator=arguments[1];return comparator in new Date&&dates.map(function(date){return parseDate(date)?date[comparator]():-1}).reduce(function(acc,curr,i){return 0===i?acc=curr:acc>=0&&curr>=0&&acc===curr?acc:-1})>=0},datesAreEqual=function(){var dates=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],specifier=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"value";if(!dates.length)return!1;var compareMethods={Y:"getFullYear",M:"getMonth",D:"getDate",h:"getHours",m:"getMinutes",s:"getSeconds",ms:"getMilliseconds",value:"valueOf"},compareDates=function(d,s){var verifiedSpecifier=compareMethods.hasOwnProperty(s)?compareMethods[s]:compareMethods.value;return dateValuesAreEqual(d,verifiedSpecifier)};if(Array.isArray(specifier)){for(var i=0;i<specifier.length;i+=1)if(!compareDates(dates,specifier[i]))return!1;return!0}return compareDates(dates,specifier)},DEFAULT_FORMATTING_OPTIONS={leadingZero:!1,monthLabels:["January","February","March","April","May","June","July","August","September","October","November","December"],weekdayLabels:["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]},getWeekday=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var weekday=(date.getDay()-startOfWeek)%7;return weekday<0?weekday+7:weekday},classCallCheck=function(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")},_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source)Object.prototype.hasOwnProperty.call(source,key)&&(target[key]=source[key])}return target},formatDate=function(dateString){var format=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",options=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},date=parseDate(dateString);if(!date)return null;var formattingOptions=_extends({},DEFAULT_FORMATTING_OPTIONS,options),formats={YY:function(d){return addLeadingZero(String(d.getFullYear()).substr(2),formattingOptions.leadingZero)},YYYY:function(d){return addLeadingZero(d.getFullYear(),formattingOptions.leadingZero)},MM:function(d){return addLeadingZero(d.getMonth()+1,formattingOptions.leadingZero)},MMMM:function(d){return addLeadingZero(formattingOptions.monthLabels[d.getMonth()],formattingOptions.leadingZero)},DD:function(d){return addLeadingZero(d.getDate(),formattingOptions.leadingZero)},DDDD:function(d){return addLeadingZero(formattingOptions.weekdayLabels[getWeekday(d,options.startOfWeek)],formattingOptions.leadingZero)},hh:function(d){return addLeadingZero(d.getHours(),formattingOptions.leadingZero)},mm:function(d){return addLeadingZero(d.getMinutes(),formattingOptions.leadingZero)},ss:function(d){return addLeadingZero(d.getSeconds(),formattingOptions.leadingZero)},ms:function(d){return addLeadingZero(d.getMilliseconds(),formattingOptions.leadingZero)}};return format.split(/[^YMDhms]/).reduce(function(acc,curr){return formats.hasOwnProperty(curr)?acc.replace(curr,formats[curr](date)):acc},format)},getFirstWeekdayOfMonth=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var providedDate=new Date(date);return providedDate.setDate(1),getWeekday(providedDate,startOfWeek)},getLastWeekdayOfMonth=function(date){var startOfWeek=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!parseDate(date))return-1;var providedDate=new Date(date),monthLength=getMonthLength(providedDate);return providedDate.setDate(monthLength),getWeekday(providedDate,startOfWeek)},updateDate=function(date,day){if(!parseDate(date)||isNaN(parseInt(day,10)))return date;var targetDate=new Date(date),targetMonthLength=getMonthLength(targetDate);return day>targetMonthLength?targetDate.setDate(targetMonthLength):targetDate.setDate(day),targetDate},updateMonth=function(date,month){if(!parseDate(date)||isNaN(parseInt(month,10)))return date;var targetDate=new Date(date),day=targetDate.getDate(),year=targetDate.getFullYear();return month>11?(year+=1,month-=12):month<0&&(year-=1,month+=12),targetDate.setDate(1),targetDate.setMonth(month),targetDate.setFullYear(year),updateDate(targetDate,day)},week=function(start){var options=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},padding=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],offset=options.hasOwnProperty("offset")?options.offset:0,dayOffset=options.hasOwnProperty("dayOffset")?options.dayOffset:0,addPadding=options.hasOwnProperty("padding")&&options.padding,fromStart=options.hasOwnProperty("fromStart")&&options.fromStart;start=start||(dayOffset>0?0:1);for(var val,weekLength=addPadding?7:7-offset,week=[],i=start;i<start+weekLength;i+=1)if(val=i,addPadding&&(fromStart?val<start+offset:val>start+(6-offset))){if(addPadding){var paddingIndex=fromStart?i-start:i-start-(7-offset);week.push({date:padding.length?padding[paddingIndex]:null,padding:!0})}}else week.push({date:(fromStart&&addPadding?i-offset:i)+dayOffset});return week},padding=function(date){var count=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,fromStart=arguments[2],padding=[];if(!parseDate(date))return padding;for(var targetMonth=updateMonth(date,fromStart?date.getMonth()-1:date.getMonth()+1),monthLength=getMonthLength(targetMonth),i=0;i<count&&(padding.push(fromStart?monthLength-(count-i-1):padding.length+1),fromStart||!(i>=monthLength));i+=1);return padding},month=function(date){var options=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!parseDate(date))return[];for(var startOfWeek=options.startOfWeek||0,monthLength=getMonthLength(date),startOfMonth=getFirstWeekdayOfMonth(date,startOfWeek),endOfMonth=getLastWeekdayOfMonth(date,startOfWeek),offsetStart=startOfMonth,offsetEnd=monthLength-endOfMonth,firstWeek=week(0,{offset:offsetStart,dayOffset:startOfWeek,fromStart:!0,padding:options.padding},options.generatePadding?padding(date,offsetStart,!0):[]),lastWeek=week(offsetEnd,{offset:6-endOfMonth,padding:options.padding},options.generatePadding?padding(date,offsetEnd):[]),wholeWeeks=Math.floor((lastWeek[0].date-firstWeek[firstWeek.length-1].date)/7),weeks=[firstWeek],i=0;i<wholeWeeks;i+=1){var currDate=weeks[i][weeks[i].length-1].date+1;weeks.push(week(currDate))}return weeks.push(lastWeek),weeks},range=function(date,range){var options=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!parseDate(date)||!range||range&&!range.length)return[];var dateRange=[],weekdays=[];return range.forEach(function(value){if(value instanceof Date){var dateValue=(rangeDate=value)instanceof Date&&datesAreEqual([date,rangeDate],["Y","M"])?rangeDate.getDate():null;return!!dateValue&&dateRange.push(dateValue)}var rangeDate;isNaN(parseInt(value,10))||weekdays.push(value)}),weekdays.length&&(dateRange=dateRange.concat(function(targetDate,weekdays,_ref){for(var _ref$startOfWeek=_ref.startOfWeek,offset=getFirstWeekdayOfMonth(date,void 0===_ref$startOfWeek?0:_ref$startOfWeek),monthLength=getMonthLength(date),dateRange=[],i=0;i<monthLength;i+=1)weekdays.indexOf((i+offset)%7)>=0&&dateRange.push(i+1);return dateRange}(0,weekdays,options))),dateRange.reduce(function(acc,curr){return acc.indexOf(curr)>=0?acc:acc.concat(curr)},[]).sort(function(val1,val2){return val1-val2})},DateHelper=function DateHelper(){classCallCheck(this,DateHelper)};DateHelper.addLeadingZero=addLeadingZero,DateHelper.closestDateForRange=closestDateForRange,DateHelper.dateOutOfRange=dateOutOfRange,DateHelper.datesAreEqual=datesAreEqual,DateHelper.dateValuesAreEqual=dateValuesAreEqual,DateHelper.formatDate=formatDate,DateHelper.getFirstWeekdayOfMonth=getFirstWeekdayOfMonth,DateHelper.getLastWeekdayOfMonth=getLastWeekdayOfMonth,DateHelper.getMonthLength=getMonthLength,DateHelper.getWeekday=getWeekday,DateHelper.parseDate=parseDate,DateHelper.updateDate=updateDate,DateHelper.updateMonth=updateMonth;var DateGenerator=function DateGenerator(){classCallCheck(this,DateGenerator)};DateGenerator.generateMonth=month,DateGenerator.generatePadding=padding,DateGenerator.generateRange=range,DateGenerator.generateWeek=week,exports.addLeadingZero=addLeadingZero,exports.closestDateForRange=closestDateForRange,exports.dateOutOfRange=dateOutOfRange,exports.datesAreEqual=datesAreEqual,exports.dateValuesAreEqual=dateValuesAreEqual,exports.formatDate=formatDate,exports.getFirstWeekdayOfMonth=getFirstWeekdayOfMonth,exports.getLastWeekdayOfMonth=getLastWeekdayOfMonth,exports.getMonthLength=getMonthLength,exports.getWeekday=getWeekday,exports.parseDate=parseDate,exports.updateDate=updateDate,exports.updateMonth=updateMonth,exports.generateMonth=month,exports.generatePadding=padding,exports.generateRange=range,exports.generateWeek=week,exports.DEFAULT_FORMATTING_OPTIONS=DEFAULT_FORMATTING_OPTIONS,exports.DateHelper=DateHelper,exports.DateGenerator=DateGenerator,Object.defineProperty(exports,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=acpaas-ui-js-date-utils.umd.js.map |
{ | ||
"name": "@acpaas-ui/js-date-utils", | ||
"version": "1.0.1-alpha.2", | ||
"version": "1.0.1-alpha.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "acpaas-ui-js-date-utils.umd.js", |
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
139738
208
1