Date.m_koyomi = [ { "NENGONO":"1", "NAME1":"明治", "NAME2":"明", "NAME3":"M", "FROMBI":"18680908", "TOBI":"19120729" }, { "NENGONO":"2", "NAME1":"大正", "NAME2":"大", "NAME3":"T", "FROMBI":"19120730", "TOBI":"19261224" }, { "NENGONO":"3", "NAME1":"昭和", "NAME2":"昭", "NAME3":"S", "FROMBI":"19261225", "TOBI":"19890107" }, { "NENGONO":"4", "NAME1":"平成", "NAME2":"平", "NAME3":"H", "FROMBI":"19890108", "TOBI":"20871231" } ]; Date.m_holiday = [ { "HOLICD":"1", "HOLINAME":"元日", "FROMNEN":"1948", "TONEN":"9999", "HOLITSUKI":"01", "HOLIHOU":"01", "HOLIBI":"01", "HOLISHU":"", "HOLIYOUBI":"", "YUKOFLG":"1" }, { "HOLICD":"2", "HOLINAME":"成人の日", "FROMNEN":"2000", "TONEN":"9999", "HOLITSUKI":"01", "HOLIHOU":"02", "HOLIBI":"", "HOLISHU":"2", "HOLIYOUBI":"2", "YUKOFLG":"1" }, { "HOLICD":"3", "HOLINAME":"成人の日", "FROMNEN":"1948", "TONEN":"1999", "HOLITSUKI":"01", "HOLIHOU":"01", "HOLIBI":"15", "HOLISHU":"", "HOLIYOUBI":"", "YUKOFLG":"1" }, { "HOLICD":"4", "HOLINAME":"建国記念日", "FROMNEN":"1966", "TONEN":"9999", "HOLITSUKI":"02", "HOLIHOU":"01", "HOLIBI":"11", "HOLISHU":"", "HOLIYOUBI":"", "YUKOFLG":"1" }, { "HOLICD":"5", "HOLINAME":"春分の日", "FROMNEN":"1948", "TONEN":"9999", "HOLITSUKI":"03", "HOLIHOU":"91", "HOLIBI":"", "HOLISHU":"", "HOLIYOUBI":"", "YUKOFLG":"1" }, { "HOLICD":"6", "HOLINAME":"天皇誕生日", "FROMNEN":"1948", "TONEN":"1988", "HOLITSUKI":"04", "HOLIHOU":"01", "HOLIBI":"29", "HOLISHU":"", "HOLIYOUBI":"", "YUKOFLG":"1" }, { "HOLICD":"7", "HOLINAME":"みどりの日", "FROMNEN":"1989", "TONEN":"2006", "HOLITSUKI":"04", "HOLIHOU":"01", "HOLIBI":"29", "HOLISHU":"", "HOLIYOUBI":"", "YUKOFLG":"1" }, { "HOLICD":"8", "HOLINAME":"昭和の日", "FROMNEN":"2007", "TONEN":"9999", "HOLITSUKI":"04", "HOLIHOU":"01", "HOLIBI":"29", "HOLISHU":"", "HOLIYOUBI":"", "YUKOFLG":"1" }, { "HOLICD":"9", "HOLINAME":"憲法記念日", "FROMNEN":"1948", "TONEN":"9999", "HOLITSUKI":"05", "HOLIHOU":"01", "HOLIBI":"03", "HOLISHU":"", "HOLIYOUBI":"", "YUKOFLG":"1" }, { "HOLICD":"10", "HOLINAME":"みどりの日", "FROMNEN":"2007", "TONEN":"9999", "HOLITSUKI":"05", "HOLIHOU":"01", "HOLIBI":"04", "HOLISHU":"", "HOLIYOUBI":"", "YUKOFLG":"1" }, { "HOLICD":"11", "HOLINAME":"こどもの日", "FROMNEN":"1948", "TONEN":"9999", "HOLITSUKI":"05", "HOLIHOU":"01", "HOLIBI":"05", "HOLISHU":"", "HOLIYOUBI":"", "YUKOFLG":"1" }, { "HOLICD":"12", "HOLINAME":"海の日", "FROMNEN":"1995", "TONEN":"2018", "HOLITSUKI":"07", "HOLIHOU":"01", "HOLIBI":"20", "HOLISHU":"", "HOLIYOUBI":"", "YUKOFLG":"1" }, { "HOLICD":"13", "HOLINAME":"海の日", "FROMNEN":"2003", "TONEN":"2099", "HOLITSUKI":"07", "HOLIHOU":"02", "HOLIBI":"", "HOLISHU":"3", "HOLIYOUBI":"2", "YUKOFLG":"1" }, { "HOLICD":"14", "HOLINAME":"敬老の日", "FROMNEN":"1966", "TONEN":"2002", "HOLITSUKI":"09", "HOLIHOU":"01", "HOLIBI":"15", "HOLISHU":"", "HOLIYOUBI":"", "YUKOFLG":"1" }, { "HOLICD":"15", "HOLINAME":"敬老の日", "FROMNEN":"2003", "TONEN":"9999", "HOLITSUKI":"09", "HOLIHOU":"02", "HOLIBI":"", "HOLISHU":"3", "HOLIYOUBI":"2", "YUKOFLG":"1" }, { "HOLICD":"16", "HOLINAME":"秋分の日", "FROMNEN":"1948", "TONEN":"9999", "HOLITSUKI":"09", "HOLIHOU":"92", "HOLIBI":"", "HOLISHU":"", "HOLIYOUBI":"", "YUKOFLG":"1" }, { "HOLICD":"17", "HOLINAME":"体育の日", "FROMNEN":"1966", "TONEN":"1999", "HOLITSUKI":"10", "HOLIHOU":"01", "HOLIBI":"10", "HOLISHU":"", "HOLIYOUBI":"", "YUKOFLG":"1" }, { "HOLICD":"18", "HOLINAME":"体育の日", "FROMNEN":"2000", "TONEN":"9999", "HOLITSUKI":"10", "HOLIHOU":"02", "HOLIBI":"", "HOLISHU":"2", "HOLIYOUBI":"2", "YUKOFLG":"1" }, { "HOLICD":"19", "HOLINAME":"文化の日", "FROMNEN":"1948", "TONEN":"9999", "HOLITSUKI":"11", "HOLIHOU":"01", "HOLIBI":"03", "HOLISHU":"", "HOLIYOUBI":"", "YUKOFLG":"1" }, { "HOLICD":"20", "HOLINAME":"勤労感謝の日", "FROMNEN":"1948", "TONEN":"9999", "HOLITSUKI":"11", "HOLIHOU":"01", "HOLIBI":"23", "HOLISHU":"", "HOLIYOUBI":"", "YUKOFLG":"1" }, { "HOLICD":"21", "HOLINAME":"天皇誕生日", "FROMNEN":"1989", "TONEN":"9999", "HOLITSUKI":"12", "HOLIHOU":"01", "HOLIBI":"23", "HOLISHU":"", "HOLIYOUBI":"", "YUKOFLG":"1" } ]; Date.getFirstDay = function(_year,_month) { return new Date(_year,_month - 1,1).getDay(); } Date.getHolidayFromMonth = function(_year,_month) { var _array = new Array(); var _count = 0; var _day = 0; for(var _index = 0;_index < Date.m_holiday.length;_index++) { var _holiday = Date.m_holiday[_index]; if(_year < _holiday.FROMNEN || _year > _holiday.TONEN) continue; if(_month != _holiday.HOLITSUKI) continue; var _element = new Object(); _element.name = _holiday.HOLINAME; _element.year = _year; _element.month = _month; switch(_holiday.HOLIHOU) { case "01": _day = parseInt(_holiday.HOLIBI,10); break; case "02": var _first_day = Date.getFirstDay(_year,_month); _day = parseInt(_holiday.HOLIYOUBI,10) - 1 - _first_day; if(_day < 0) _day += 8; else _day += 1; _day = _day + 7 * (parseInt(_holiday.HOLISHU,10) - 1); break; case "91": _day = Math.floor(20.8431 + 0.242194 * (_year - 1980) - Math.floor((_year - 1980) / 4)); break; case "92": _day = Math.floor(23.2488 + 0.242194 * (_year - 1980) - Math.floor((_year - 1980) / 4)); break; default: throw "定義外の計算方法です。"; } _element.day = _day; _element.division = 1; _element.date = new Date(_element.year,_element.month-1,_element.day); _element.weekday = _element.date.getDay(); _array[_day] = _element; } for(_day = 1; _day < 32; _day++) { var _date = new Date(_year,_month-1,_day); var _weekday = _date.getDay(); var _is_holiday = false; if(_year > 2006 && _month == 5 && _day == 6 && (_weekday == 2 || _weekday == 3)) { _is_holiday = true; } else if(_array[_day-1] && _array[_day-1].weekday == 0) { _is_holiday = true; } if(!_is_holiday) continue; var _element = new Object(); _element.name = "振替休日"; _element.year = _year; _element.month = _month; _element.day = _day; _element.division = 2; _element.date = _date; _element.weekday = _weekday; _array[_day] = _element; } return _array; } Date.prototype.isJpHoliday = function() { var _calendar = Date.getHolidayFromMonth(this.getFullYear(),this.getMonth()+1); var _holiday = _calendar[this.getDate()]; if(_holiday) { this.jp_hol_name = _holiday.name; return true; } return false; } Date.prototype.getDateNumber = function() { return this.getFullYear() * 10000 + (this.getMonth()+1) * 100 + this.getDate(); } Date.getKoyomiFromNengoNo = function(_nengo_no) { for(var _index = 0;_index < Date.m_koyomi.length;_index++) { var _koyomi = Date.m_koyomi[_index]; if(_koyomi.NENGONO != _nengo_no) continue; return _koyomi; } throw "未登録の年号番号が指定されました。"; } Date.getKoyomiFromName3 = function(_name3) { for(var _index = 0;_index < Date.m_koyomi.length;_index++) { var _koyomi = Date.m_koyomi[_index]; if(_koyomi.NAME3 != _name3) continue; return _koyomi; } throw "未登録の年号名が指定されました。"; } Date.prototype.getJapaneseYear = function () { var _date_number = this.getDateNumber(); for(var _index = 0;_index < Date.m_koyomi.length;_index++) { var _koyomi = Date.m_koyomi[_index]; if(_date_number < _koyomi.FROMBI || _date_number > _koyomi.TOBI) continue; var _wareki_year = this.getFullYear() - Math.floor(_koyomi.FROMBI / 10000) + 1; return _koyomi.NAME3 + ("00" + _wareki_year).slice(-2); } throw "暦情報を取得できません。"; } Date.prototype.toJapaneseDateString = function () { return this.getJapaneseYear() + '.' + ('00' + (this.getMonth() + 1)).slice(-2) + '.' + ('00' + this.getDate()).slice(-2); } Date.prototype.toSeirekiDateString = function () { return this.getFullYear() + '/' + ('00' + (this.getMonth() + 1)).slice(-2) + '/' + ('00' + this.getDate()).slice(-2); } Date.fksParse = function (_text) { var _match = null; var _year = 0; var _month = 0; var _day = 0; var _koyomi; if (_match = _text.match(/^(\d{4})(\d{2})$/)) { _year = _match[1]; _month = _match[2]; _day = 1; } else if (_match = _text.match(/^(\d{4})[\/\.](\d{1,2})$/)) { _year = _match[1]; _month = _match[2]; _day = 1; } else if (_match = _text.match(/^(\d{1})(\d{2})(\d{2})$/)) { _koyomi = Date.getKoyomiFromNengoNo(_match[1]); _year = parseInt(_match[2],10) + Math.floor(_koyomi.FROMBI / 10000) - 1; _month = _match[3]; _day = 1; } else if (_match = _text.match(/^([A-Z])(\d{2})(\d{2})$/i)) { _koyomi = Date.getKoyomiFromName3(_match[1].toUpperCase()); _year = parseInt(_match[2],10) + Math.floor(_koyomi.FROMBI / 10000) - 1; _month = _match[3]; _day = 1; } else if (_match = _text.match(/^([A-Z])(\d{1,2})[\/\.](\d{1,2})$/i)) { _koyomi = Date.getKoyomiFromName3(_match[1].toUpperCase()); _year = parseInt(_match[2],10) + Math.floor(_koyomi.FROMBI / 10000) - 1; _month = _match[3]; _day = 1; } else if (_match = _text.match(/^(\d{4})(\d{2})(\d{2})$/)) { _year = _match[1]; _month = _match[2]; _day = _match[3]; } else if (_match = _text.match(/^(\d{4})[\/\.](\d{1,2})[\/\.](\d{1,2})$/)) { _year = _match[1]; _month = _match[2]; _day = _match[3]; } else if (_match = _text.match(/^(\d{1})(\d{2})(\d{2})(\d{2})$/)) { _koyomi = Date.getKoyomiFromNengoNo(_match[1]); _year = parseInt(_match[2],10) + Math.floor(_koyomi.FROMBI / 10000) - 1; _month = _match[3]; _day = _match[4]; } else if (_match = _text.match(/^([A-Z])(\d{2})(\d{2})(\d{2})$/i)) { _koyomi = Date.getKoyomiFromName3(_match[1].toUpperCase()); _year = parseInt(_match[2],10) + Math.floor(_koyomi.FROMBI / 10000) - 1; _month = _match[3]; _day = _match[4]; } else if (_match = _text.match(/^([A-Z])(\d{1,2})[\/\.](\d{1,2})[\/\.](\d{1,2})$/i)) { _koyomi = Date.getKoyomiFromName3(_match[1].toUpperCase()); _year = parseInt(_match[2],10) + Math.floor(_koyomi.FROMBI / 10000) - 1; _month = _match[3]; _day = _match[4]; } else { return null; } return new Date(_year, _month - 1, _day); }