From 3de9ae209af000d253657adc69d14c52a83f7d56 Mon Sep 17 00:00:00 2001 From: leebj Date: Wed, 21 Aug 2024 19:02:25 +0900 Subject: [PATCH] =?UTF-8?q?=EB=82=A0=EC=A7=9C=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=9E=90=EB=B0=94=EC=8A=A4=ED=81=AC=EB=A6=BD=ED=8A=B8=20?= =?UTF-8?q?=EC=86=8C=EC=8A=A4=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/applib/js/cmmnDateUtil.js | 624 ------------------ .../resources/applib/js/date-support.js | 541 +++++++++++++++ 2 files changed, 541 insertions(+), 624 deletions(-) delete mode 100644 src/main/webapp/resources/applib/js/cmmnDateUtil.js create mode 100644 src/main/webapp/resources/applib/js/date-support.js diff --git a/src/main/webapp/resources/applib/js/cmmnDateUtil.js b/src/main/webapp/resources/applib/js/cmmnDateUtil.js deleted file mode 100644 index b6c012a..0000000 --- a/src/main/webapp/resources/applib/js/cmmnDateUtil.js +++ /dev/null @@ -1,624 +0,0 @@ -/* - * 현재날짜를 YYYY-MM-DD 포맷으로 반환 - */ -function TODAY(){ - return dateFormat.format(new Date()); -} - -function inputDateComparison(sndngYmd, sndngEndYmd) { - let startDate = inputDateSplit(sndngYmd); // 시작일 - let endDate = inputDateSplit(sndngEndYmd); // 종료일 - - if (typeof startDate == "undefined" || startDate == null || startDate == "") { - alert("시작일이 입력되지 않았습니다.\n시작일을 입력해주세요."); - $("#sndngYmd").focus(); - - return false; - } - if (typeof endDate == "undefined" || endDate == null || endDate == "") { - alert("종료일이 입력되지 않았습니다.\n종료일을 입력해주세요."); - $("#sndngEndYmd").focus(); - - return false; - } - // 입력일을 확인하는 이유는 현재 작성한 일자가 시작일인지 종료일인지 확인하기 위해서이다. - if (startDate > endDate) { - alert("시작일이 종료일보다 이 후 일수는 없습니다.\n다시 선택하여 주시기 바랍니다."); - $("#sndngYmd").focus(); - - return false; - } - - return true; -} - -// 날짜형식에 "-"이 사용된 경우에 한하여 날짜값에서 "-" 기호를 제거한다. -function inputDateSplit(obj) { - if (obj == "") { - return obj; - } else { - let dateArray = obj.split("-"); - - return dateArray[0] + dateArray[1] + dateArray[2]; - } -} - -var DateUtil = { - /*============================ - * 현재날짜로부터 월 단위로 계산된 날짜(yyyymmdd) 반환 - * -addMonth가 0 이면 현재월 - * -음의 숫자면 전월 (ex: -1 전월, -2 전전월, -3 ...) - * -양의 숫자면 차월 (ex: 1 차월, 2 차차월, 3 ...) - ============================*/ - getDate : function(){ - var result = new Object(); - switch (arguments.length) { - case 1: - result = calcDate(arguments[0]); - break; - case 2: - result = calcDate(arguments[0], arguments[1]); - break; - default: - result = calcDate(); - break; - } - return result; - - //날짜 계산 - function calcDate(addMonth, stdDay){ - if(addMonth!=undefined) - addMonth = addMonth + 1; - addMonth = addMonth==undefined?1:addMonth; - - - /* - * 필수값 설정 - * -날짜 설정 - * -ago OR after 여부 설정 - */ - var date = new Date(); - var yyyy = date.getFullYear(); - var mm = ( date.getMonth() + (addMonth) ); - var dd = date.getDate(); - if(stdDay!=undefined){ - stdDay = stdDay.replace(/[^0-9]/gi,''); - yyyy = stdDay.substring(0,4); - mm = stdDay.substring(4,6); - dd = stdDay.substring(6,8); - - if(addMonth==13) - yyyy = Number(yyyy)+1; - } - - var isAfter = false; - if((addMonth*1)>0) - isAfter = true; - - /* - * 유효성 처리 - * -해(year) 넘김 처리 - * -말일(last day) 처리 - */ - var newYear = DateUtil.getNewYear(isAfter, yyyy, mm); - yyyy = newYear.yyyy; - mm = newYear.mm; - var ago_last_dd = DateUtil.getEndOfMonthDay(yyyy, mm); - dd = dd>ago_last_dd?ago_last_dd:dd; - - - /* - * format 설정 - */ - if( (''+dd).length == 1 ) - dd = "0"+ dd; - - - /* - * 결과 반환 - */ - var obj = new Object(); - obj.date = ""+yyyy+mm+dd; - obj.yyyy = ""+yyyy; - obj.mm = ""+mm; - obj.dd = ""+dd; - return obj; - } - }, - - //+ 한달 후 말일 계산 - getAddMonth : function(stdDay){ - //날짜 계산 - - var rtnVal = calcDate(0,stdDay); - return rtnVal; - - - function calcDate(addMonth, stdDay){ - if(addMonth!=undefined) - addMonth = addMonth + 1; - addMonth = addMonth==undefined?1:addMonth; - - - /* - * 필수값 설정 - * -날짜 설정 - * -ago OR after 여부 설정 - */ - stdDay = stdDay.replace(/[^0-9]/gi,''); - var yyyy = stdDay.substring(0,4); - var mm = stdDay.substring(4,6); - var dd = stdDay.substring(6,8); - mm = Number(mm)+addMonth; - if(addMonth==13) - yyyy = Number(yyyy)+1; - - var isAfter = false; - if((addMonth*1)>0) - isAfter = true; - - /* - * 유효성 처리 - * -해(year) 넘김 처리 - * -말일(last day) 처리 - */ - var newYear = DateUtil.getNewYear(isAfter, yyyy, mm); - yyyy = newYear.yyyy; - mm = newYear.mm; - var ago_last_dd = DateUtil.getEndOfMonthDay(yyyy, mm); - dd = ago_last_dd; - - - /* - * format 설정 - */ - if( (''+dd).length == 1 ) - dd = "0"+ dd; - - - /* - * 결과 반환 - */ - var obj = new Object(); - obj.date = ""+yyyy+mm+dd; - obj.yyyy = ""+yyyy; - obj.mm = ""+mm; - obj.dd = ""+dd; - return obj; - } - }, - - /*============================ - * 현재날짜(or 기준일)로부터 일 단위로 계산된 날짜(yyyymmdd) 반환 - * -addDay가 0 이면 금일 - * -음의 숫자면 전일 (ex: -1 작일, -2 재작일, -3 ...) - * -양의 숫자면 차일 (ex: 1 명일, 2 재명일, 3 ...) - ============================*/ - getDateDay: function(addDay){ - var result = new Object(); - switch (arguments.length) { - case 1: - result = calcDate(arguments[0], DateUtil.getDate().date); - break; - default: - result = calcDate(0, DateUtil.getDate().date); - break; - } - return result; - - - //날짜 계산 - function calcDate(addDay, stdDay){ - addDay = addDay==undefined||addDay==null?0:addDay*1; - - /* - * 필수값 설정 - * -날짜 설정 - * -ago OR after 여부 설정 - */ - var yyyy = stdDay.substring(0,4); - var mm = stdDay.substring(4,6); - var dd = stdDay.substring(6,8); - var dateObj = new Date(yyyy, (mm-1)*1, dd*1); - dateObj.setDate(dateObj.getDate()+(addDay)); - - yyyy = dateObj.getFullYear(); - mm = dateObj.getMonth()+1; - dd = dateObj.getDate(); - - if( (''+mm).length == 1 ) - mm = "0"+ mm; - if( (''+dd).length == 1 ) - dd = "0"+ dd; - - /* - * 결과 반환 - */ - var obj = new Object(); - obj.date = ""+yyyy+"-"+mm+"-"+dd; - obj.yyyy = yyyy; - obj.mm = mm; - obj.dd = dd; - return obj; - } - }, - /*============================ - * 달의 마지막 날짜(dd) 반환 - ============================*/ - getEndOfMonthDay : function(yy, mm){ - var max_days=0; - if(mm == 1 || mm == '01') { - max_days = 31 ; - } else if(mm == 2 || mm == '02') { - if ((( yy % 4 == 0) && (yy % 100 != 0)) || (yy % 400 == 0)) - max_days = 29; - else - max_days = 28; - } - else if (mm == 3 || mm == '03') max_days = 31; - else if (mm == 4 || mm == '04') max_days = 30; - else if (mm == 5 || mm == '05') max_days = 31; - else if (mm == 6 || mm == '06') max_days = 30; - else if (mm == 7 || mm == '07') max_days = 31; - else if (mm == 8 || mm == '08') max_days = 31; - else if (mm == 9 || mm == '09') max_days = 30; - else if (mm == 10 || mm == '10') max_days = 31; - else if (mm == 11 || mm == '11') max_days = 30; - else if (mm == 12 || mm == '12') max_days = 31; - else return ''; - return max_days; - }, - - /*============================ - * 해(year) 넘김 처리 - ============================*/ - getNewYear : function(isAfter, yyyy, mm){ - /* - * 해(year) 넘김 처리 - */ - if(isAfter){ - if(mm>12){ - var formula = Math.floor(mm/12); - yyyy = Number(yyyy)+(formula); - mm = mm - ((formula)*12); - } - }else{ - if(mm<1){ - var formula = Math.floor((mm*(-1))/12)+1; - yyyy = yyyy-(formula); - mm = mm + ((formula)*12); - } - } - - /* - * 포맷 설정 - * -월(month) 두자리 설정 - */ - if( (''+mm).length == 1 ) - mm = "0"+ mm; - - /* - * 결과 반환 - */ - var obj = new Object(); - obj.yyyy = ''+yyyy; - obj.mm = ''+mm; - return obj; - } -} - - -function getDateObject(dateStr){ - var year = dateStr.substr(0,4); - var month = dateStr.substr(4,2) - 1; - var day = dateStr.substr(6,2); - - return new Date(year,month,day); -} - -function getDateString(dateObj) { - var result = ""; - - var dateFormat = "YYYYMMDD"; - - for (var i = 0; i < dateFormat.length; i++) { - result += dateFormat.indexOf("YYYY", i) == i ? (i+=3, dateObj.getFullYear() ) : - dateFormat.indexOf("MM", i) == i ? (i+=1, to2(dateObj.getMonth()+1) ) : - dateFormat.indexOf("DD", i) == i ? (i+=1, to2(dateObj.getDate()) ) : - (dateFormat.charAt(i) ); - } - return result; -}; - -function to2(numberObj) { - return (numberObj > 9 ? "" : "0") + numberObj; -}; - -/** - * 입력일의 이전일 계산 - */ -function getPrevDay(datestr, days) { - if ( days == "0") - return datestr; - datestr = datestr.replace(/-/g, ""); - if (datestr == "") - return ""; - - var dateObj = window.getDateObject(datestr); - - dateObj.setDate(dateObj.getDate() - parseInt(days, 10)); - - return window.getDateString(dateObj); -}; - -/** - * 입력일의 다음일 계산 - */ -function getNextDay(datestr, days) { - if ( days == "0") return datestr; - datestr = datestr.replace(/-/g, ""); - if (datestr == "") return ""; - var dateObj = window.getDateObject(datestr); - - dateObj.setDate(dateObj.getDate()+ parseInt(days, 10)); - - return window.getDateString(dateObj); -}; - -/** - * 해당월의 마지막날 - */ -function getLastDay(datestr) { - datestr = datestr.replace(/-/g, ""); - if (datestr == "") return ""; - var strNextMonth = window.addMonth(datestr, 1); - strNextMonth = strNextMonth.replace(/-/g, ""); - datestr = strNextMonth.substring(0, 6) + '01'; - var strLastDay = window.addDate(datestr, -1); - strLastDay = strLastDay.replace(/-/g, ""); - var dateObj = window.getDateObject(strLastDay); - return dateObj.getDate(); -}; - -/** - * 년, 월, 일을 입력 받아 Date String으로 변환 - */ -function getDatetime(nYear, nMonth, nDate){ - var dateObj = null; - - if (nYear.toString().trim().length >= 5) { - var sDate = new String(nYear); - var nYear = sDate.substr(0,4); - var nMonth = sDate.substr(4,2); - var nDate = ((sDate.substr(6,2) == "") ? 1 : sDate.substr(6,2)); - var nHours = ((sDate.substr(8,2) == "") ? 0 : sDate.substr(8,2)); - var nMinutes = ((sDate.substr(10,2) == "") ? 0 : sDate.substr(10,2)); - var nSeconds = ((sDate.substr(12,2) == "") ? 0 : sDate.substr(12,2)); - - dateObj = new Date(parseInt(nYear), parseInt(nMonth)-1, parseInt(nDate), parseInt(nHours), parseInt(nMinutes), parseInt(nSeconds)); - } else { - dateObj = new Date(parseInt(nYear), parseInt(nMonth)-1, parseInt(((nDate == null) ? 1 : nDate))); - } - - var strYear = dateObj.getFullYear().toString(); - var strMonth = (dateObj.getMonth() + 1).toString(); - var strDate = dateObj.getDate().toString(); - if (strMonth.length == 1) strMonth = "0" + strMonth; - if (strDate.length == 1) strDate = "0" + strDate; - return strYear + "-" + strMonth + "-" + strDate; -}; - -/** - * 년 계산 - */ -function addYear(date, nOffSet){ - date = date.replace(/-/g, ""); - var nYear = parseInt(date.substr(0, 4), 10) + nOffSet; - var nMonth = parseInt(date.substr(4, 2), 10); - var nDate = parseInt(date.substr(6, 2), 10); - return window.getDatetime(nYear, nMonth, nDate); -}; - -/** - * 월 계산 - */ -function addMonth(date, nOffSet) { - date = date.replace(/-/g, ""); - var nYear = parseInt(date.substr(0, 4), 10); - var nMonth = parseInt(date.substr(4, 2), 10) + nOffSet; - var nDate = parseInt(date.substr(6, 2), 10); - return window.getDatetime(nYear, nMonth, nDate); -}; - -/** - * 일 계산 - */ -function addDate(date, nOffSet) { - date = date.replace(/-/g, ""); - var nYear = parseInt(date.substr(0, 4), 10); - var nMonth = parseInt(date.substr(4, 2), 10); - var nDate = parseInt(date.substr(6, 2), 10) + nOffSet; - return window.getDatetime(nYear, nMonth, nDate); -}; - -/** - * 이전해 계산 - */ -function getPrevYear(datestr, year) { - if ( year == "0") return datestr; - datestr = datestr.replace(/-/g, ""); - if (datestr == "") return ""; - var dateObj = window.getDateObject(datestr); - - dateObj.setYear(dateObj.getFullYear() - year); - - return window.getDateString(dateObj); -}; - -/** - * 다음해 계산 - */ -function getNextYear(datestr, year) { - if ( year == "0") return datestr; - datestr = datestr.replace(/-/g, ""); - if (datestr == "") return ""; - var dateObj = window.getDateObject(datestr); - - dateObj.setYear(dateObj.getFullYear() + year); - - return window.getDateString(dateObj); -}; - -/** - * select 연도 - */ -function setYearCombo(id,isAll,isSelect,range){ - var now = new Date(); - var dayYear = now.getFullYear(); - var str = ""; - if(range == null || range <= 0){ - range = 5; - } - if(isAll){ - str += ""; - } - for(var year=dayYear-range; year"+year+""; - - } - - $("#"+id).append(str); - - if(isSelect){ - $("#"+id).val(dayYear).attr("selected", "selected"); - } -}; - -/** - * select 연도(올해이후) - */ -function setYearComboNext(id,isAll,isSelect,range){ - var now = new Date(); - var dayYear = now.getFullYear(); - var str = ""; - if(range == null || range <= 0){ - range = 5; - } - if(isAll){ - str += ""; - } - for(var year=dayYear; year"+year+""; - - } - - $("#"+id).append(str); - - if(isSelect){ - $("#"+id).val(dayYear).attr("selected", "selected"); - } -}; - - -/** - * select 년월 - */ -function setYearMonCombo(id,isAll,isSelect){ - var day = new Date(); - var dayYear = day.getFullYear().toString(); - var now = day.getMonth()+1; - now = dayYear + (now < 10 ? "0" : "") + now; - var month = ""; - var str = ""; - - if(isAll){ - str += ""; - } - for(var i = 1; i <13 ; i++){ - month = i < 10 ? "0" + i : "" + i; - str += ""; - } - $("#"+id).append(str); - if(isSelect){ - $("#"+id).val(now).attr("selected", "selected"); - } -}; - - -/** - * 두 일자간의 일수 계산 - * @param1 day1 : 일자 8자리 - 'YYYYMMDD', 'YYYY-MM-DD', 'YYYY/MM/DD', etc - * @param2 day2 : 일자 8자리 - 'YYYYMMDD', 'YYYY-MM-DD', 'YYYY/MM/DD', etc - * @return 두 일자간의 일수 - */ -function calcDayCount(day1, day2) { - day1 = day1.replace(/-/g, ""); - day2 = day2.replace(/-/g, ""); - if (day1 == "" || day2 == "") return ""; - var date1 = window.getDateObject(day1); - var date2 = window.getDateObject(day2); - - if(date1 > date2) return ((date1.getTime() - date2.getTime()) / 1000 / 60 / 60 / 24) + 1; - else return ((date2.getTime() - date1.getTime()) / 1000 / 60 / 60 / 24) + 1; -}; - -/** - * Get 요일 - */ -function getWeek(datestr, isConvert){ - datestr = datestr.replace(/-/g, ""); - var dateObj = window.getDateObject(datestr); - var week = dateObj.getDay() + 1; - - if(!isConvert) return week; - - if(week == 1) week = '일'; - else if(week == 2) week = '월'; - else if(week == 3) week = '화'; - else if(week == 4) week = '수'; - else if(week == 5) week = '목'; - else if(week == 6) week = '금'; - else if(week == 7) week = '토'; - return week; -}; - - -/** - * 날짜형식이 올바른지 검사 - * - * @param astrValue 날짜포맷(yyyymmdd, yyyy/mm/dd, yyyy-mm-dd) - * @param astrNotNull: nn:not null, "": null 허용 - * @return true/false - **/ -function blnOkDate(astrValue, astrNotNull) { - var arrDate; - - if (astrValue==''){ - if (astrNotNull == "nn") - return false; - else - return true; - } - - if (astrValue.indexOf("-") != -1){ - arrDate = astrValue.split("-"); - } else if (astrValue.indexOf("/") != -1){ - arrDate = astrValue.split("/"); - } else { - if (astrValue.length != 8) return false; - astrValue = astrValue.substring(0,4)+"/"+astrValue.substring(4,6)+"/" +astrValue.substring(6,8); - arrDate = astrValue.split("/"); - } - - if (arrDate.length != 3) return false; - - var chkDate = new Date(arrDate[0] + "/" + arrDate[1] + "/" + arrDate[2]); - if (isNaN(chkDate) == true - || (arrDate[1] != chkDate.getMonth() + 1 || arrDate[2] != chkDate.getDate())) { - return false; - } - - return true; -} - - diff --git a/src/main/webapp/resources/applib/js/date-support.js b/src/main/webapp/resources/applib/js/date-support.js new file mode 100644 index 0000000..df742e8 --- /dev/null +++ b/src/main/webapp/resources/applib/js/date-support.js @@ -0,0 +1,541 @@ +/************************************************************************** +* 전역함수 +**************************************************************************/ +/* + * 현재날짜를 YYYY-MM-DD 포맷으로 반환 + */ +function TODAY(){ + return dateFormat.format(new Date()); +} + + +/************************************************************************** +* DateSupport +**************************************************************************/ +class DateSupport { + + static help(){ + console.log("inputDateComparison(시작일,종료일) : 시작일과 종료일 입력 검증 후 결과(bool) 반환"); + + } + + static inputDateComparison(sndngYmd, sndngEndYmd){ + let startDate = DateSupport.inputDateSplit(sndngYmd); // 시작일 + let endDate = DateSupport.inputDateSplit(sndngEndYmd); // 종료일 + + if (typeof startDate == "undefined" || startDate == null || startDate == "") { + alert("시작일이 입력되지 않았습니다.\n시작일을 입력해주세요."); + $("#sndngYmd").focus(); + + return false; + } + if (typeof endDate == "undefined" || endDate == null || endDate == "") { + alert("종료일이 입력되지 않았습니다.\n종료일을 입력해주세요."); + $("#sndngEndYmd").focus(); + + return false; + } + // 입력일을 확인하는 이유는 현재 작성한 일자가 시작일인지 종료일인지 확인하기 위해서이다. + if (startDate > endDate) { + alert("시작일이 종료일보다 이 후 일수는 없습니다.\n다시 선택하여 주시기 바랍니다."); + $("#sndngYmd").focus(); + + return false; + } + + return true; + } + + static inputDateSplit(str){ + if (str == "") { + return str; + } else { + let dateArray = str.split("-"); + + return dateArray[0] + dateArray[1] + dateArray[2]; + } + } + + static getDateObject(dateStr){ + var year = dateStr.substr(0,4); + var month = dateStr.substr(4,2) - 1; + var day = dateStr.substr(6,2); + + return new Date(year,month,day); + } + + static getDateString(dateObj) { + var result = ""; + + var YYYYMMDDFormat = "YYYYMMDD"; + + for (var i = 0; i < YYYYMMDDFormat.length; i++) { + result += YYYYMMDDFormat.indexOf("YYYY", i) == i ? (i+=3, dateObj.getFullYear() ) : + YYYYMMDDFormat.indexOf("MM", i) == i ? (i+=1, DateSupport.to2(dateObj.getMonth()+1) ) : + YYYYMMDDFormat.indexOf("DD", i) == i ? (i+=1, DateSupport.to2(dateObj.getDate()) ) : (YYYYMMDDFormat.charAt(i) ); + } + return result; + } + + static to2(numberObj) { + return (numberObj > 9 ? "" : "0") + numberObj; + } + + /** + * 입력일의 이전일 계산 + */ + static getPrevDay(datestr, days) { + if(days == "0") { + return datestr; + } + datestr = datestr.replace(/-/g, ""); + if (datestr == "") { + return ""; + } + var dateObj = DateSupport.getDateObject(datestr); + + dateObj.setDate(dateObj.getDate() - parseInt(days, 10)); + + return DateSupport.getDateString(dateObj); + } + + /** + * 입력일의 다음일 계산 + */ + static getNextDay(datestr, days) { + if ( days == "0") return datestr; + datestr = datestr.replace(/-/g, ""); + if (datestr == "") return ""; + var dateObj = DateSupport.getDateObject(datestr); + + dateObj.setDate(dateObj.getDate()+ parseInt(days, 10)); + + return DateSupport.getDateString(dateObj); + } + + /** + * 해당월의 마지막날 + */ + static getLastDay(datestr) { + datestr = datestr.replace(/-/g, ""); + if (datestr == "") return ""; + var strNextMonth = DateSupport.addMonth(datestr, 1); + strNextMonth = strNextMonth.replace(/-/g, ""); + datestr = strNextMonth.substring(0, 6) + '01'; + var strLastDay = DateSupport.addDay(datestr, -1); + strLastDay = strLastDay.replace(/-/g, ""); + var dateObj = DateSupport.getDateObject(strLastDay); + return dateObj.getDate(); + } + + /** + * 년, 월, 일을 입력 받아 Date String으로 변환 + */ + static getDatetime(nYear, nMonth, nDate){ + var dateObj = null; + + if (nYear.toString().trim().length >= 5) { + var sDate = new String(nYear); + var nYear = sDate.substr(0,4); + var nMonth = sDate.substr(4,2); + var nDate = ((sDate.substr(6,2) == "") ? 1 : sDate.substr(6,2)); + var nHours = ((sDate.substr(8,2) == "") ? 0 : sDate.substr(8,2)); + var nMinutes = ((sDate.substr(10,2) == "") ? 0 : sDate.substr(10,2)); + var nSeconds = ((sDate.substr(12,2) == "") ? 0 : sDate.substr(12,2)); + + dateObj = new Date(parseInt(nYear), parseInt(nMonth)-1, parseInt(nDate), parseInt(nHours), parseInt(nMinutes), parseInt(nSeconds)); + } else { + dateObj = new Date(parseInt(nYear), parseInt(nMonth)-1, parseInt(((nDate == null) ? 1 : nDate))); + } + + var strYear = dateObj.getFullYear().toString(); + var strMonth = (dateObj.getMonth() + 1).toString(); + var strDate = dateObj.getDate().toString(); + if (strMonth.length == 1) strMonth = "0" + strMonth; + if (strDate.length == 1) strDate = "0" + strDate; + return ""+strYear + "-" + strMonth + "-" + strDate; + } + + /** + * 년 계산 + */ + static addYear(date, nOffSet){ + date = date.replace(/-/g, ""); + var nYear = parseInt(date.substr(0, 4), 10) + nOffSet; + var nMonth = parseInt(date.substr(4, 2), 10); + var nDate = parseInt(date.substr(6, 2), 10); + return DateSupport.getDatetime(nYear, nMonth, nDate); + } + + + /** + * 월 계산 + */ + static addMonth(date, nOffSet) { + date = date.replace(/-/g, ""); + var nYear = parseInt(date.substr(0, 4), 10); + var nMonth = parseInt(date.substr(4, 2), 10) + nOffSet; + var nDate = parseInt(date.substr(6, 2), 10); + return DateSupport.getDatetime(nYear, nMonth, nDate); + } + + /** + * 일 계산 + */ + static addDay(date, nOffSet) { + date = date.replace(/-/g, ""); + var nYear = parseInt(date.substr(0, 4), 10); + var nMonth = parseInt(date.substr(4, 2), 10); + var nDate = parseInt(date.substr(6, 2), 10) + nOffSet; + return DateSupport.getDatetime(nYear, nMonth, nDate); + } + + + /** + * 이전해 계산 + */ + static getPrevYear(datestr, year) { + if ( year == "0") return datestr; + datestr = datestr.replace(/-/g, ""); + if (datestr == "") return ""; + var dateObj = DateSupport.getDateObject(datestr); + + dateObj.setYear(dateObj.getFullYear() - year); + + return DateSupport.getDateString(dateObj); + } + + /** + * 다음해 계산 + */ + static getNextYear(datestr, year) { + if ( year == "0") return datestr; + datestr = datestr.replace(/-/g, ""); + if (datestr == "") return ""; + var dateObj = DateSupport.getDateObject(datestr); + + dateObj.setYear(dateObj.getFullYear() + year); + + return DateSupport.getDateString(dateObj); + } + + /** + * select 연도 + */ + static setYearCombo(el,isAll,isSelect,range){ + var now = new Date(); + var dayYear = now.getFullYear(); + var str = ""; + if(range == null || range <= 0){ + range = 5; + } + if(isAll){ + str += ""; + } + for(var year=dayYear-range; year"+year+""; + + } + + $(el).append(str); + + if(isSelect){ + $(el).val(dayYear).attr("selected", "selected"); + } + } + + /** + * select 연도(올해이후) + */ + static setYearComboNext(el,isAll,isSelect,range){ + var now = new Date(); + var dayYear = now.getFullYear(); + var str = ""; + if(range == null || range <= 0){ + range = 5; + } + if(isAll){ + str += ""; + } + for(var year=dayYear; year"+year+""; + + } + + $(el).append(str); + + if(isSelect){ + $(el).val(dayYear).attr("selected", "selected"); + } + } + + + /** + * select 년월 + */ + static setYearMonCombo(el,isAll,isSelect){ + var day = new Date(); + var dayYear = day.getFullYear().toString(); + var now = day.getMonth()+1; + now = dayYear + (now < 10 ? "0" : "") + now; + var month = ""; + var str = ""; + + if(isAll){ + str += ""; + } + for(var i = 1; i <13 ; i++){ + month = i < 10 ? "0" + i : "" + i; + str += ""; + } + $(el).append(str); + if(isSelect){ + $(el).val(now).attr("selected", "selected"); + } + } + + /** + * 두 일자간의 일수 계산 + * @param1 day1 : 일자 8자리 - 'YYYYMMDD', 'YYYY-MM-DD', 'YYYY/MM/DD', etc + * @param2 day2 : 일자 8자리 - 'YYYYMMDD', 'YYYY-MM-DD', 'YYYY/MM/DD', etc + * @return 두 일자간의 일수 + */ + static calcDayCount(day1, day2) { + day1 = day1.replace(/-/g, ""); + day2 = day2.replace(/-/g, ""); + if (day1 == "" || day2 == "") return ""; + var date1 = DateSupport.getDateObject(day1); + var date2 = DateSupport.getDateObject(day2); + + if(date1 > date2) return ((date1.getTime() - date2.getTime()) / 1000 / 60 / 60 / 24) + 1; + else return ((date2.getTime() - date1.getTime()) / 1000 / 60 / 60 / 24) + 1; + } + + + /** + * Get 요일 + */ + static getWeek(datestr, isConvert){ + datestr = datestr.replace(/-/g, ""); + var dateObj = DateSupport.getDateObject(datestr); + var week = dateObj.getDay() + 1; + + if(!isConvert) return week; + + if(week == 1) week = '일'; + else if(week == 2) week = '월'; + else if(week == 3) week = '화'; + else if(week == 4) week = '수'; + else if(week == 5) week = '목'; + else if(week == 6) week = '금'; + else if(week == 7) week = '토'; + return week; + } + + + /** + * 날짜형식이 올바른지 검사 + * + * @param astrValue 날짜포맷(yyyymmdd, yyyy/mm/dd, yyyy-mm-dd) + * @param astrNotNull: nn:not null, "": null 허용 + * @return true/false + **/ + static blnOkDate(astrValue, astrNotNull) { + var arrDate; + + if (astrValue==''){ + if (astrNotNull == "nn") + return false; + else + return true; + } + + if (astrValue.indexOf("-") != -1){ + arrDate = astrValue.split("-"); + } else if (astrValue.indexOf("/") != -1){ + arrDate = astrValue.split("/"); + } else { + if (astrValue.length != 8) return false; + astrValue = astrValue.substring(0,4)+"/"+astrValue.substring(4,6)+"/" +astrValue.substring(6,8); + arrDate = astrValue.split("/"); + } + + if (arrDate.length != 3) return false; + + var chkDate = new Date(arrDate[0] + "/" + arrDate[1] + "/" + arrDate[2]); + if (isNaN(chkDate) == true + || (arrDate[1] != chkDate.getMonth() + 1 || arrDate[2] != chkDate.getDate())) { + return false; + } + + return true; + } + + /*============================ + * 현재날짜(or 기준일)로부터 n일 단위로 계산된 날짜(yyyymmdd) 반환 + * -n이 0 이면 금일 + * -음의 숫자면 전일 (ex: -1 작일, -2 재작일, -3 ...) + * -양의 숫자면 차일 (ex: 1 명일, 2 재명일, 3 ...) + ============================*/ + static getAddDay(){ + var result = new Object(); + switch (arguments.length) { + case 1: + result = DateSupport.addDay(TODAY().replaceAll("-",""), arguments[0]); + break; + case 2: + result = DateSupport.addDay(arguments[0], arguments[1]); + break; + default: + result = DateSupport.addDay(TODAY().replaceAll("-",""), 0); + break; + } + return result; + } + + /*============================ + * 현재날짜로(or 기준일)로부터 n월 단위로 계산된 날짜(yyyymmdd) 반환 + * -n이 0 이면 금월 + * -음의 숫자면 전월 (ex: -1 전월, -2 전전월, -3 ...) + * -양의 숫자면 차월 (ex: 1 차월, 2 차차월, 3 ...) + ============================*/ + static getAddMonth(){ + var result = new Object(); + switch (arguments.length) { + case 1: + result = DateSupport.addMonth(TODAY().replaceAll("-",""), arguments[0]); + break; + case 2: + result = DateSupport.addMonth(arguments[0], arguments[1]); + break; + default: + result = DateSupport.addMonth(TODAY().replaceAll("-",""), 0); + break; + } + return result; + } + + /*============================ + * 현재날짜(or 기준일)로부터 n달 후 말일 날짜(yyyymmdd) 반환 + * -n이 0 이면 금월 + * -음의 숫자면 전월 (ex: -1 전월, -2 전전월, -3 ...) + * -양의 숫자면 차월 (ex: 1 차월, 2 차차월, 3 ...) + ============================*/ + static getAddMonthAndLast(){ + + //날짜 계산 + var result = new Object(); + switch (arguments.length) { + case 1: + result = DateSupport.addMonthAndLast(TODAY().replaceAll("-",""), arguments[0]); + break; + case 2: + result = DateSupport.addMonthAndLast(arguments[0], arguments[1]); + break; + default: + result = DateSupport.addMonthAndLast(TODAY().replaceAll("-",""), 0); + break; + } + return result; + } + + + /*============================ + * 달의 마지막 날짜(dd) 반환 + ============================*/ + static getEndOfMonthDay(yy, mm){ + var max_days=0; + if(mm == 1 || mm == '01') { + max_days = 31 ; + } else if(mm == 2 || mm == '02') { + if ((( yy % 4 == 0) && (yy % 100 != 0)) || (yy % 400 == 0)) + max_days = 29; + else + max_days = 28; + } + else if (mm == 3 || mm == '03') max_days = 31; + else if (mm == 4 || mm == '04') max_days = 30; + else if (mm == 5 || mm == '05') max_days = 31; + else if (mm == 6 || mm == '06') max_days = 30; + else if (mm == 7 || mm == '07') max_days = 31; + else if (mm == 8 || mm == '08') max_days = 31; + else if (mm == 9 || mm == '09') max_days = 30; + else if (mm == 10 || mm == '10') max_days = 31; + else if (mm == 11 || mm == '11') max_days = 30; + else if (mm == 12 || mm == '12') max_days = 31; + else return ''; + return max_days; + } + + /*============================ + * 해(year) 넘김 처리 + ============================*/ + static getNewYear(yyyy, mm){ + /* + * 해(year) 넘김 처리 + */ + if(mm>12){ + var formula = Math.floor(mm/12); + yyyy = Number(yyyy)+(formula); + mm = mm - ((formula)*12); + } else if(mm<1){ + var formula = Math.floor((mm*(-1))/12)+1; + yyyy = yyyy-(formula); + mm = mm + ((formula)*12); + } + + /* + * 포맷 설정 + * -월(month) 두자리 설정 + */ + if((''+mm).length == 1) + mm = "0"+ mm; + + /* + * 결과 반환 + */ + var obj = new Object(); + obj.yyyy = ''+yyyy; + obj.mm = ''+mm; + return obj; + } + + static addMonthAndLast(stdDay, addMonth){ + + /* + * 필수값 설정 + * -날짜 설정 + * -ago OR after 여부 설정 + */ + stdDay = stdDay.replace(/[^0-9]/gi,''); + var yyyy = stdDay.substring(0,4); + var mm = stdDay.substring(4,6); + var dd = stdDay.substring(6,8); + mm = Number(mm)+addMonth; + + + /* + * 유효성 처리 + * -해(year) 넘김 처리 + * -말일(last day) 처리 + */ + var newYear = DateSupport.getNewYear(yyyy, mm); + yyyy = newYear.yyyy; + mm = newYear.mm; + var ago_last_dd = DateSupport.getEndOfMonthDay(yyyy, mm); + dd = ago_last_dd; + + /* + * format 설정 + */ + if((''+dd).length == 1 ){ + dd = "0"+ dd; + } + + /* + * 결과 반환 + */ + var r = ""+yyyy+"-"+mm+"-"+dd; + return r; + } +} \ No newline at end of file