amis-rpc-design/node_modules/rc-picker/lib/utils/timeUtil.js
2023-10-07 19:42:30 +08:00

45 lines
1.8 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getLastDay = getLastDay;
exports.getLowerBoundTime = getLowerBoundTime;
exports.setDateTime = setDateTime;
exports.setTime = setTime;
function setTime(generateConfig, date, hour, minute, second) {
var nextTime = generateConfig.setHour(date, hour);
nextTime = generateConfig.setMinute(nextTime, minute);
nextTime = generateConfig.setSecond(nextTime, second);
return nextTime;
}
function setDateTime(generateConfig, date, defaultDate) {
if (!defaultDate) {
return date;
}
var newDate = date;
newDate = generateConfig.setHour(newDate, generateConfig.getHour(defaultDate));
newDate = generateConfig.setMinute(newDate, generateConfig.getMinute(defaultDate));
newDate = generateConfig.setSecond(newDate, generateConfig.getSecond(defaultDate));
return newDate;
}
function getLowerBoundTime(hour, minute, second, hourStep, minuteStep, secondStep) {
var lowerBoundHour = Math.floor(hour / hourStep) * hourStep;
if (lowerBoundHour < hour) {
return [lowerBoundHour, 60 - minuteStep, 60 - secondStep];
}
var lowerBoundMinute = Math.floor(minute / minuteStep) * minuteStep;
if (lowerBoundMinute < minute) {
return [lowerBoundHour, lowerBoundMinute, 60 - secondStep];
}
var lowerBoundSecond = Math.floor(second / secondStep) * secondStep;
return [lowerBoundHour, lowerBoundMinute, lowerBoundSecond];
}
function getLastDay(generateConfig, date) {
var year = generateConfig.getYear(date);
var month = generateConfig.getMonth(date) + 1;
var endDate = generateConfig.getEndDate(generateConfig.getFixedDate("".concat(year, "-").concat(month, "-01")));
var lastDay = generateConfig.getDate(endDate);
var monthShow = month < 10 ? "0".concat(month) : "".concat(month);
return "".concat(year, "-").concat(monthShow, "-").concat(lastDay);
}