timetable-app

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

getSchoolYear.ts (418B)


      1 import { set, isFuture } from 'date-fns';
      2 
      3 /** 現在の年度を取得 */
      4 const getSchoolYear = (): number => {
      5 	const march31thisYear = set(new Date(), { month: 2, date: 31 }); // 3月は month: 2
      6 
      7 	if (isFuture(march31thisYear)) {
      8 		// 1月~3月の場合
      9 		return march31thisYear.getFullYear() - 1;
     10 	} else {
     11 		// 4月~12月の場合
     12 		return march31thisYear.getFullYear();
     13 	}
     14 };
     15 
     16 export default getSchoolYear;