1 line
18 KiB
JSON
1 line
18 KiB
JSON
|
{"ast":null,"code":"export var WEEK_DAY_COUNT = 7;\n\n/**\n * Wrap the compare logic.\n * This will compare the each of value is empty first.\n * 1. All is empty, return true.\n * 2. One is empty, return false.\n * 3. return customize compare logic.\n */\nfunction nullableCompare(value1, value2, oriCompareFn) {\n if (!value1 && !value2 || value1 === value2) {\n return true;\n }\n if (!value1 || !value2) {\n return false;\n }\n return oriCompareFn();\n}\nexport function isSameDecade(generateConfig, decade1, decade2) {\n return nullableCompare(decade1, decade2, function () {\n var num1 = Math.floor(generateConfig.getYear(decade1) / 10);\n var num2 = Math.floor(generateConfig.getYear(decade2) / 10);\n return num1 === num2;\n });\n}\nexport function isSameYear(generateConfig, year1, year2) {\n return nullableCompare(year1, year2, function () {\n return generateConfig.getYear(year1) === generateConfig.getYear(year2);\n });\n}\nexport function getQuarter(generateConfig, date) {\n var quota = Math.floor(generateConfig.getMonth(date) / 3);\n return quota + 1;\n}\nexport function isSameQuarter(generateConfig, quarter1, quarter2) {\n return nullableCompare(quarter1, quarter2, function () {\n return isSameYear(generateConfig, quarter1, quarter2) && getQuarter(generateConfig, quarter1) === getQuarter(generateConfig, quarter2);\n });\n}\nexport function isSameMonth(generateConfig, month1, month2) {\n return nullableCompare(month1, month2, function () {\n return isSameYear(generateConfig, month1, month2) && generateConfig.getMonth(month1) === generateConfig.getMonth(month2);\n });\n}\nexport function isSameDate(generateConfig, date1, date2) {\n return nullableCompare(date1, date2, function () {\n return isSameYear(generateConfig, date1, date2) && isSameMonth(generateConfig, date1, date2) && generateConfig.getDate(date1) === generateConfig.getDate(date2);\n });\n}\nexport function isSameTime(generateConfig, time1, time2) {\n return nullableCompare(time1, time2, function () {\n return generateConfig.getHour(time1) === generateConfig.getHour(time2) && generateConfig.getMinute(time1) === generateConfig.getMinute(time2) && generateConfig.getSecond(time1) === generateConfig.getSecond(time2);\n });\n}\n\n/**\n * Check if the Date is all the same of timestamp\n */\nexport function isSameTimestamp(generateConfig, time1, time2) {\n return nullableCompare(time1, time2, function () {\n return isSameDate(generateConfig, time1, time2) && isSameTime(generateConfig, time1, time2) && generateConfig.getMillisecond(time1) === generateConfig.getMillisecond(time2);\n });\n}\nexport function isSameWeek(generateConfig, locale, date1, date2) {\n return nullableCompare(date1, date2, function () {\n var weekStartDate1 = generateConfig.locale.getWeekFirstDate(locale, date1);\n var weekStartDate2 = generateConfig.locale.getWeekFirstDate(locale, date2);\n return isSameYear(generateConfig, weekStartDate1, weekStartDate2) && generateConfig.locale.getWeek(locale, date1) === generateConfig.locale.getWeek(locale, date2);\n });\n}\nexport function isSame(generateConfig, locale, source, target, type) {\n switch (type) {\n case 'date':\n return isSameDate(generateConfig, source, target);\n case 'week':\n return isSameWeek(generateConfig, locale.locale, source, target);\n case 'month':\n return isSameMonth(generateConfig, source, target);\n case 'quarter':\n return isSameQuarter(generateConfig, source, target);\n case 'year':\n return isSameYear(generateConfig, source, target);\n case 'decade':\n return isSameDecade(generateConfig, source, target);\n case 'time':\n return isSameTime(generateConfig, source, target);\n default:\n return isSameTimestamp(generateConfig, source, target);\n }\n}\n\n/** Between in date but not equal of date */\nexport function isInRange(generateConfig, startDate, endDate, current) {\n if (!startDate || !endDate || !current) {\n return false;\n }\n return generateConfig.isAfter(current, startDate) && generateCo
|