UNPKG

@nutui/nutui-react

Version:

京东风格的轻量级移动端 React 组件库,支持一套代码生成 H5 和小程序

81 lines (80 loc) 2.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function _export(target, all) { for(var name in all)Object.defineProperty(target, name, { enumerable: true, get: all[name] }); } _export(exports, { convertDateToDay: function() { return convertDateToDay; }, convertDayToDate: function() { return convertDayToDate; }, getCurrentMonthDays: function() { return getCurrentMonthDays; }, getCurrentWeekDays: function() { return getCurrentWeekDays; }, getPrevMonthDays: function() { return getPrevMonthDays; } }); var _date = require("../../utils/date"); var convertDateToDay = function convertDateToDay(date) { return date ? { year: date.getFullYear(), month: date.getMonth() + 1, date: date.getDate() } : null; }; var convertDayToDate = function convertDayToDate(day) { return day ? new Date(day.year, day.month - 1, day.date) : null; }; var getPrevMonthDays = function getPrevMonthDays(year, month, firstDayOfWeek) { var prevMonth = month - 1; var prevYear = year; if (prevMonth <= 0) { prevMonth = 12; prevYear -= 1; } var days = _date.Utils.getMonthPreDay(year, month); days -= firstDayOfWeek; if (days >= 7) { days -= 7; } var preDates = _date.Utils.getMonthDays("".concat(prevYear), "".concat(prevMonth)); var months = Array.from(Array(preDates), function(_, k) { return { type: 'prev', year: prevYear, month: prevMonth, date: k + 1 }; }); return months.slice(preDates - days); }; var getCurrentMonthDays = function getCurrentMonthDays(year, month) { var days = _date.Utils.getMonthDays("".concat(year), "".concat(month)); return Array.from(Array(days), function(_, k) { return { type: 'current', year: year, month: month, date: k + 1 }; }); }; var getCurrentWeekDays = function getCurrentWeekDays(day, firstDayOfWeek) { var current = new Date(day.year, day.month - 1, day.date); var count = (current.getDay() + 7 - firstDayOfWeek) % 7; return [ convertDateToDay(new Date(current.getTime() - 24 * 60 * 60 * 1000 * count)), convertDateToDay(new Date(current.getTime() + 24 * 60 * 60 * 1000 * (6 - count))) ]; };