// $RCSfile: datefunctions.js,v $ $Revision: 1.2 $ //************************************************************************ // Function: getFullYear // Purpose: Get the four digit year given a two digit year. // Input: date - date to get the four digit year for. // Output: Four digit year. // // Function required because NE 3.01 does not support date.getFullYear. // Code copied from O'Reilly - JavaScript The Definitive Guide //************************************************************************ function getFullYear (date) { var year = date.getYear (); if (year < 1000) year += 1900; return (year); } //************************************************************************ // Function: getDayOfWeek // Purpose: Get the day of the week for a given date. // Input: date - date to get the four digit year for. // Output: String containing the Day of the Week (Monday, Tuesday, etc). //************************************************************************ function getDayOfWeek (crsDate) { var myDate = new Date (crsDate.substring (0, 4), parseInt(crsDate.substring (4, 6), 10) - 1, parseInt(crsDate.substring (6, 8), 10)); return (dayName [myDate.getDay ()]); } //************************************************************************ // Function: getDayOfWeek // Purpose: Get the day of the week for a given date. // Input: year, month, day // Output: String containing the Day of the Week (Monday, Tuesday, etc). //************************************************************************ function getDayOfWeek2 (year, month, day) { var myDate = new Date (year, parseInt(month, 10) - 1, parseInt(day, 10)); return (dayName [myDate.getDay ()]); } //************************************************************************ // Function: getMonth // Purpose: Get the month description for a given date. // Input: month - month to get the description for. // Output: String containing the month (January, February, etc). //************************************************************************ function getMonth (month) { return (monthName [month - 1]); } //************************************************************************ // Function: formatDateDisplay // Purpose: Format a date in the form of January 1, 1999 Tuesday // Input: crsDate - date to format // language - language used by the WEB page. // locale - locale used by the WEB page. // Output: String containing the formatted date. //************************************************************************ function formatDisplayDate (crsDate, language, locale) { var monthStr = getMonth (parseInt (crsDate.substring (4, 6), 10)); return (monthStr + " " + crsDate.substring (6, 8) + ", " + crsDate.substring (0, 4) + " " + getDayOfWeek (crsDate)); } //************************************************************************ // Function: formatDateDisplay // Purpose: Format a date in the form of January 1, 1999 Tuesday // Input: year // month // day // language - language used by the WEB page. // locale - locale used by the WEB page. // Output: String containing the formatted date. //************************************************************************ function formatDisplayDate2 (year, month, day, language, locale) { var monthStr = getMonth (parseInt (month, 10)); return (monthStr + " " + day + ", " + year + " " + getDayOfWeek2 (year, month, day)); } //************************************************************************ // Function: formatDateDisplayShort // Purpose: Format a date in the form of January 1 // Input: crsDate - date to format // language - language used by the WEB page. // locale - locale used by the WEB page. // Output: String containing the formatted date. //************************************************************************ function formatDisplayDateShort (crsDate, language, locale) { monthStr = getMonth (parseInt (crsDate.substring (4, 6), 10)); return (monthStr + " " + crsDate.substring (6, 8)); } //************************************************************************ // Function: buildCRSDate // Purpose: Format a date in the form YYYYMMDD // Input: year // month // day // Output: String containing the formatted date. //************************************************************************ function buildCRSDate (year, month, day) { if (day < 10) { dayString = "0" + day; } else { dayString = new String (day); } if (month < 10) { monthString = "0" + month; } else { monthString = new String(month); } return (year + monthString + dayString); } //************************************************************************ // Function: isLeapYear // Purpose: Determine if a year is a leap year. // Input: yrStr - year to determine leapness.. // Output: true - if the year is a leap year. // false - otherwise. //************************************************************************ function isLeapYear(yrStr) { var leapYear=false; // every fourth year is a leap year if ((parseInt(yrStr, 10)%4) == 0) { leapYear=true; } return leapYear; } //************************************************************************ // Function: getDaysInMonth // Purpose: Determine the number of days in a month. // Input: mthIdx - month // yrStr - year // Output: true - if the year is a leap year. // false - otherwise. //************************************************************************ function getDaysInMonth(mthIdx, YrStr) { // all the rest have 31 var maxDays = 31 // expect Feb. (of course) if (mthIdx==2) { if (isLeapYear(YrStr)) { maxDays=29; } else { maxDays=28; } } // thirty days hath... if (mthIdx==4 || mthIdx==6 || mthIdx==9 || mthIdx==11) { maxDays=30; } return maxDays; }