Version 16.114

This commit is contained in:
Antonio Cañas Vargas 2017-01-14 23:47:21 +01:00
parent 4395183825
commit 11d3c9c235
3 changed files with 46 additions and 59 deletions

View File

@ -234,32 +234,49 @@ function setTZname (id) {
FormTZname.value = tz.name(); // Returns the name of the time zone eg "Europe/Berlin"
}
// Adjust a date form correcting days in the month
// Get number of days in a month
function daysInMonth (month, year) { //Month is 1 based
return new Date(year, month, 0).getDate(); // 0 is the last day of previous month
}
// Adjust a date form correcting selector days in the month
// The selector of days can start by 1, 2, 3... or by -, 1, 2, 3...
function adjustDateForm (id) {
var FormYea = document.getElementById(id+'Year' );
var FormMon = document.getElementById(id+'Month');
var FormDay = document.getElementById(id+'Day' );
var Yea = FormYea.options[FormYea.selectedIndex].value;
var Days;
if (FormMon.options[1].selected) // February
Days = ((((Yea % 4) == 0) && ((Yea % 100) != 0)) || ((Yea % 400) == 0)) ? 29 : 28;
else if (FormMon.options[ 3].selected || // April
FormMon.options[ 5].selected || // June
FormMon.options[ 8].selected || // September
FormMon.options[10].selected) // November
Days = 30;
else
Days = 31;
if (FormDay.selectedIndex >= Days)
FormDay.options[Days-1].selected = true; // Select last day in month
for (var i=FormDay.options.length; i<Days; i++) { // Create new days at the end
FormDay.options[i] = new Option(String(i+1),i+1);
var Yea = Number(FormYea.options[FormYea.selectedIndex].value);
var Mon = Number(FormMon.options[FormMon.selectedIndex].value);
if (Yea != 0 && Mon != 0) {
var LastDayIndex = FormDay.options.length - 1;
var LastDayValue = Number(FormDay.options[LastDayIndex].value);
var SelectedDay = Number(FormDay.options[FormDay.selectedIndex].value);
var Days = daysInMonth (Mon,Yea);
// If current selected day is out of range...
if (SelectedDay > Days)
// Select last day in month
for (var i=LastDayIndex; i>=0; i--)
if (FormDay.options[i].value == Days) {
FormDay.options[i].selected = true;
break;
}
// Create new days at the end if necessary
for (var Day=Number(LastDayValue)+1; Day<=Days; Day++) {
var opt = document.createElement('option');
opt.value = opt.text = Day;
FormDay.add(opt);
}
// Remove days from the end if necessary
for (var i=LastDayIndex; i>=0; i--)
if (FormDay.options[i].value > Days)
FormDay.options[i] = null;
else
break;
}
for (var i=FormDay.options.length-1; i>=Days; i--) // Remove days from the end
FormDay.options[i] = null;
}
// Set a date range form to yesterday
@ -1002,21 +1019,6 @@ function DrawCurrentMonth (id,FirstDayOfWeek,TimeUTC,CurrentPlcCod,
function DrawMonth (id,FirstDayOfWeek,YearToDraw,MonthToDraw,CurrentMonth,CurrentDay,
CurrentPlcCod,DrawingCalendar,PrintView,
CGI,FormGoToCalendarParams,FormEventParams) {
var NumDaysMonth = [
0,
31, // 1: January
28, // 2: February
31, // 3: Mars
30, // 4: April
31, // 5: May
30, // 6: June
31, // 7: July
31, // 8: Agoust
30, // 9: September
31, // 10: October
30, // 11: November
31, // 12: December
];
var Hld_HOLIDAY = 0;
var Hld_NON_SCHOOL_PERIOD = 1;
var Yea = YearToDraw;
@ -1058,8 +1060,7 @@ function DrawMonth (id,FirstDayOfWeek,YearToDraw,MonthToDraw,CurrentMonth,Curren
Yea--;
} else
Mon--;
NumDaysInMonth = (Mon == 2) ? GetNumDaysFebruary(Yea) :
NumDaysMonth[Mon];
NumDaysInMonth = daysInMonth (Mon,Yea);
Day = NumDaysInMonth - DayOfWeek + 1;
}
@ -1210,8 +1211,7 @@ function DrawMonth (id,FirstDayOfWeek,YearToDraw,MonthToDraw,CurrentMonth,Curren
Gbl_HTMLContent += '</td>';
/***** Set the next day *****/
NumDaysInMonth = (Mon == 2) ? GetNumDaysFebruary (Yea) :
NumDaysMonth[Mon];
NumDaysInMonth = daysInMonth (Mon,Yea);
if (++Day > NumDaysInMonth) {
if (++Mon > 12) {
Yea++;
@ -1247,22 +1247,6 @@ function GetDayOfWeekMondayFirst (Year,Month,Day) {
2) % 7) + 5) % 7;
}
/*****************************************************************************/
/****************** Return the number of days of february ********************/
/*****************************************************************************/
function GetNumDaysFebruary (Year) {
return (GetIfLeapYear (Year) ? 29 : 28);
}
/*****************************************************************************/
/************************* Return true if year is leap ***********************/
/*****************************************************************************/
function GetIfLeapYear (Year) {
return (Year % 4 == 0) && ((Year % 100 != 0) || (Year % 400 == 0));
}
/*****************************************************************************/
/************* Copy message subject and content to hidden fields *************/
/*****************************************************************************/

View File

@ -189,13 +189,15 @@
/****************************** Public constants *****************************/
/*****************************************************************************/
#define Log_PLATFORM_VERSION "SWAD 16.113 (2017-01-13)"
#define Log_PLATFORM_VERSION "SWAD 16.114 (2017-01-14)"
#define CSS_FILE "swad16.111.5.css"
#define JS_FILE "swad16.101.js"
#define JS_FILE "swad16.114.js"
// Number of lines (includes comments but not blank lines) has been got with the following command:
// nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*?.h sql/swad*.sql | tail -1
/*
Version 16.114: Jan 14, 2017 Fixed bug in dates, reported by José Luis Bernier Villamor.
Javascript code refactoring related to dates. (211490 lines)
Version 16.113: Jan 13, 2017 Some strcpy changed to strncpy. (211497 lines)
Version 16.112: Jan 13, 2017 Some strcpy changed to strncpy. (211415 lines)
Version 16.111.16:Dec 30, 2016 Fixed minor bug in user's ID, reported by Coverity. (211185 lines)

View File

@ -616,7 +616,8 @@ void Dat_WriteFormDate (unsigned FirstYear,unsigned LastYear,
fprintf (Gbl.F.Out,"\"");
if (Disabled)
fprintf (Gbl.F.Out," disabled=\"disabled\"");
fprintf (Gbl.F.Out,"><option value=\"0\">-</option>");
fprintf (Gbl.F.Out,">"
"<option value=\"0\">-</option>");
for (Year = FirstYear;
Year <= LastYear;
Year++)