修改月周期,当月指当天所在的月周期
This commit is contained in:
		
							
								
								
									
										72
									
								
								main.js
									
									
									
									
									
								
							
							
						
						
									
										72
									
								
								main.js
									
									
									
									
									
								
							| @@ -14755,24 +14755,62 @@ | |||||||
|     function getCustomMonthRange(monthsAgo) { |     function getCustomMonthRange(monthsAgo) { | ||||||
|         const now = new Date(); |         const now = new Date(); | ||||||
|         let year = now.getFullYear(); |         let year = now.getFullYear(); | ||||||
|         let month = now.getMonth() - monthsAgo; |         let month = now.getMonth(); | ||||||
|         while (month < 0) { |         let day = now.getDate(); | ||||||
|             month += 12; |  | ||||||
|             year--; |         // 如果今天是21号及以后,当前周期是本月21到下月20 | ||||||
|  |         // 否则,周期是上月21到本月20 | ||||||
|  |         if (day >= 21) { | ||||||
|  |             month = month - monthsAgo; | ||||||
|  |             let startYear = year, startMonth = month; | ||||||
|  |             while (startMonth < 0) { | ||||||
|  |                 startMonth += 12; | ||||||
|  |                 startYear--; | ||||||
|  |             } | ||||||
|  |             let endYear = startYear, endMonth = startMonth + 1; | ||||||
|  |             if (endMonth > 11) { | ||||||
|  |                 endMonth -= 12; | ||||||
|  |                 endYear++; | ||||||
|  |             } | ||||||
|  |             const firstDay = new Date(startYear, startMonth, 21); | ||||||
|  |             const lastDay = new Date(endYear, endMonth, 20); | ||||||
|  |             const formatLocal = (date) => { | ||||||
|  |                 return date.toLocaleDateString('en-CA', {  | ||||||
|  |                     year: 'numeric',  | ||||||
|  |                     month: '2-digit',  | ||||||
|  |                     day: '2-digit'  | ||||||
|  |                 }).replace(/\//g, '-'); | ||||||
|  |             }; | ||||||
|  |             return { | ||||||
|  |                 firstDay: formatLocal(firstDay), | ||||||
|  |                 lastDay: formatLocal(lastDay) | ||||||
|  |             }; | ||||||
|  |         } else { | ||||||
|  |             month = month - monthsAgo - 1; | ||||||
|  |             let startYear = year, startMonth = month; | ||||||
|  |             while (startMonth < 0) { | ||||||
|  |                 startMonth += 12; | ||||||
|  |                 startYear--; | ||||||
|  |             } | ||||||
|  |             let endYear = startYear, endMonth = startMonth + 1; | ||||||
|  |             if (endMonth > 11) { | ||||||
|  |                 endMonth -= 12; | ||||||
|  |                 endYear++; | ||||||
|  |             } | ||||||
|  |             const firstDay = new Date(startYear, startMonth, 21); | ||||||
|  |             const lastDay = new Date(endYear, endMonth, 20); | ||||||
|  |             const formatLocal = (date) => { | ||||||
|  |                 return date.toLocaleDateString('en-CA', {  | ||||||
|  |                     year: 'numeric',  | ||||||
|  |                     month: '2-digit',  | ||||||
|  |                     day: '2-digit'  | ||||||
|  |                 }).replace(/\//g, '-'); | ||||||
|  |             }; | ||||||
|  |             return { | ||||||
|  |                 firstDay: formatLocal(firstDay), | ||||||
|  |                 lastDay: formatLocal(lastDay) | ||||||
|  |             }; | ||||||
|         } |         } | ||||||
|         const firstDay = new Date(year, month - 1, 21); |  | ||||||
|         const lastDay = new Date(year, month, 20); |  | ||||||
|         const formatLocal = (date) => { |  | ||||||
|             return date.toLocaleDateString('en-CA', {  |  | ||||||
|                 year: 'numeric',  |  | ||||||
|                 month: '2-digit',  |  | ||||||
|                 day: '2-digit'  |  | ||||||
|             }).replace(/\//g, '-'); |  | ||||||
|         }; |  | ||||||
|         return { |  | ||||||
|             firstDay: formatLocal(firstDay), |  | ||||||
|             lastDay: formatLocal(lastDay) |  | ||||||
|         }; |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // 创建菜单按钮 |     // 创建菜单按钮 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user