ivue-material-plus
Version:
A high quality UI components Library with Vue.js
25 lines (22 loc) • 491 B
text/typescript
import Pad from './pad';
/**
* @param {String} value YYYY-MM format
* @param {Number} sign -1 or +1
*/
export default (value: string, sign: number) => {
const [year, month] = String(value)
.split('-')
.map((v: any) => 1 * v);
// 月尾
if (month + sign === 0) {
return `${year - 1}-12`;
}
// 下一年
else if (month + sign === 13) {
return `${year + 1}-01`;
}
// 年份
else {
return `${year}-${Pad(month + sign)}`;
}
};