github.com/minio/console@v1.4.1/web-app/src/screens/Console/Common/FormComponents/DateSelector/utils.ts (about) 1 // This file is part of MinIO Console Server 2 // Copyright (c) 2021 MinIO, Inc. 3 // 4 // This program is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Affero General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Affero General Public License for more details. 13 // 14 // You should have received a copy of the GNU Affero General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17 export const months = [ 18 { value: "01", label: "January" }, 19 { value: "02", label: "February" }, 20 { value: "03", label: "March" }, 21 { value: "04", label: "April" }, 22 { value: "05", label: "May" }, 23 { value: "06", label: "June" }, 24 { value: "07", label: "July" }, 25 { value: "08", label: "August" }, 26 { value: "09", label: "September" }, 27 { value: "10", label: "October" }, 28 { value: "11", label: "November" }, 29 { value: "12", label: "December" }, 30 ]; 31 32 export const days = Array.from(Array(31), (_, num) => ({ 33 value: (num + 1).toString(), 34 label: (num + 1).toString(), 35 })); 36 37 const currentYear = new Date().getFullYear(); 38 39 export const years = Array.from(Array(50), (_, numYear) => ({ 40 value: (numYear + currentYear).toString(), 41 label: (numYear + currentYear).toString(), 42 })); 43 44 export const validDate = (year: string, month: string, day: string): any[] => { 45 const currentDate = Date.parse(`${year}-${month}-${day}`); 46 47 if (isNaN(currentDate)) { 48 return [false, ""]; 49 } 50 51 const parsedMonth = parseInt(month); 52 const parsedDay = parseInt(day); 53 54 const monthForString = parsedMonth < 10 ? `0${parsedMonth}` : parsedMonth; 55 const dayForString = parsedDay < 10 ? `0${parsedDay}` : parsedDay; 56 57 const parsedDate = new Date(currentDate).toISOString().split("T")[0]; 58 const dateString = `${year}-${monthForString}-${dayForString}`; 59 60 return [parsedDate === dateString, dateString]; 61 }; 62 63 // twoDigitDate gets a two digit string number used for months or days 64 // returns "NaN" if number is NaN 65 export const twoDigitDate = (num: number): string => { 66 return num < 10 ? `0${num}` : `${num}`; 67 };