diff --git a/js/swad.js b/js/swad.js index 4862d8740..cda4f786f 100644 --- a/js/swad.js +++ b/js/swad.js @@ -24,7 +24,7 @@ // Global variable used in refreshConnected() var ActionAJAX; -// Global variables used in writeLocalTime() +// Global variables used in writeLocalClock() var secondsSince1970UTC; // Global variables used in writeClockConnected() @@ -88,93 +88,166 @@ function writeLocalDateTimeFromUTC(id,secsSince1970UTC,separator) { // Set local date-time form fields from UTC time function setLocalDateTimeFormFromUTC(id,secsSince1970UTC) { - var d = new Date; - var YearForm = document.getElementById(id+'Year'); + var FormYea = document.getElementById(id+'Year'); + var FormMon = document.getElementById(id+'Month'); + var FormDay = document.getElementById(id+'Day'); + var FormHou = document.getElementById(id+'Hour'); + var FormMin = document.getElementById(id+'Minute'); + var FormSec = document.getElementById(id+'Second'); + var d; var Year; + var YearIsValid = false; - d.setTime(secsSince1970UTC * 1000); + if (secsSince1970UTC) { + d = new Date; + d.setTime(secsSince1970UTC * 1000); + Year = d.getFullYear(); + for (var i=0; i Days) - DayForm.options[Days].selected = true; - - for (var i=DayForm.options.length; i<=Days ; i++) { // Create new days - var x = String (i); - DayForm.options[i] = new Option(x,x); + if (FormYea.selectedIndex > 0) { + if (FormMon.options[0].selected) { // No month selected, set to january + FormMon.options[1].selected = true; + Days = 31; + } + else if (FormMon.options[2].selected) // Adjust days of february + Days = ((((Yea % 4) == 0) && ((Yea % 100) != 0)) || ((Yea % 400) == 0)) ? 29 : 28; + else if (FormMon.options[ 4].selected || + FormMon.options[ 6].selected || + FormMon.options[ 9].selected || + FormMon.options[11].selected) + Days = 30; + else + Days = 31; + + if (FormDay.options[0].selected) // No day selected, set to 1 + FormDay.options[1].selected = true; + else if (FormDay.selectedIndex > Days) + FormDay.options[Days].selected = true; + + for (var i=FormDay.options.length; i<=Days ; i++) { // Create new days + var x = String (i); + FormDay.options[i] = new Option(x,x); + } + for (var i=FormDay.options.length-1; i>Days; i--) // Remove days + FormDay.options[i] = null; } - for (var i=DayForm.options.length-1; i>Days; i--) // Remove days - DayForm.options[i] = null; } // Set a the date in a date form to a specified date -function setDateTo (Day,Month,Year) { - document.getElementById('StartYear' ).options[Year ].selected = true; - document.getElementById('StartMonth' ).options[Month].selected = true; +function setDateTo (Day,Mon,Yea) { + document.getElementById('StartYear' ).options[Yea].selected = true; + document.getElementById('StartMonth' ).options[Mon].selected = true; adjustDateForm ('Start') - document.getElementById('StartDay' ).options[Day ].selected = true; - document.getElementById('StartHour' ).options[0 ].selected = true; - document.getElementById('StartMinute').options[0 ].selected = true; - document.getElementById('StartSecond').options[0 ].selected = true; + document.getElementById('StartDay' ).options[Day].selected = true; + document.getElementById('StartHour' ).options[0 ].selected = true; + document.getElementById('StartMinute').options[0 ].selected = true; + document.getElementById('StartSecond').options[0 ].selected = true; setUTCFromLocalDateTimeForm('Start'); - document.getElementById('EndYear' ).options[Year ].selected = true; - document.getElementById('EndMonth' ).options[Month].selected = true; + document.getElementById('EndYear' ).options[Yea].selected = true; + document.getElementById('EndMonth' ).options[Mon].selected = true; adjustDateForm ('End') - document.getElementById('EndDay' ).options[Day ].selected = true; - document.getElementById('EndHour' ).options[23 ].selected = true; - document.getElementById('EndMinute' ).options[59 ].selected = true; - document.getElementById('EndSecond' ).options[59 ].selected = true; + document.getElementById('EndDay' ).options[Day].selected = true; + document.getElementById('EndHour' ).options[23 ].selected = true; + document.getElementById('EndMinute' ).options[59 ].selected = true; + document.getElementById('EndSecond' ).options[59 ].selected = true; setUTCFromLocalDateTimeForm('End'); } @@ -186,7 +259,7 @@ function writeLocalClock() { var StrH; var StrM; - setTimeout('writeLocalTime()',60000); + setTimeout('writeLocalClock()',60000); d.setTime(secondsSince1970UTC * 1000); secondsSince1970UTC += 60; // For next call diff --git a/swad_changelog.h b/swad_changelog.h index 8e0d9e6bf..f88617cf2 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -108,11 +108,13 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 15.22.1 (2015/10/26)" +#define Log_PLATFORM_VERSION "SWAD 15.24 (2015/10/26)" // 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 15.24: Oct 26, 2015 Lot of changes in swad.js related to date-times. (186336 lines) + Version 15.23: Oct 26, 2015 Date-times to open groups are displayed in client local date-time. (186259 lines) Version 15.22.1: Oct 26, 2015 Date-times in notices are displayed in client local date-time. (186344 lines) Version 15.22: Oct 26, 2015 First click time in users' profiles is displayed in client local date-time. (186328 lines) Version 15.21.3: Oct 26, 2015 Changes in date-times of test exams. (186325 lines) diff --git a/swad_date.c b/swad_date.c index fdb1bde86..bfe579739 100644 --- a/swad_date.c +++ b/swad_date.c @@ -63,11 +63,6 @@ const unsigned Dat_NumDaysMonth[1+12] = /***************************** Private prototypes ****************************/ /*****************************************************************************/ -static void Dat_WriteFormClientLocalDateTimeFromTimeUTC (const char *Id, - time_t TimeUTC, - unsigned FirstYear,unsigned LastYear, - bool SubmitFormOnChange,bool Disabled); - /*****************************************************************************/ /***************************** Get current time ******************************/ /*****************************************************************************/ @@ -145,36 +140,6 @@ bool Dat_GetDateFromYYYYMMDD (struct Date *Date,const char *YYYYMMDD) } } -/*****************************************************************************/ -/******* Get a struct DateTime from a string in YYYYMMDDHHMMSS format ********/ -/*****************************************************************************/ - -bool Dat_GetDateTimeFromYYYYMMDDHHMMSS (struct DateTime *DateTime,const char *YYYYMMDDHHMMSS) - { - if (sscanf (YYYYMMDDHHMMSS,"%04u%02u%02u%02u%02u%02u", - &(DateTime->Date.Year),&(DateTime->Date.Month),&(DateTime->Date.Day), - &(DateTime->Time.Hour),&(DateTime->Time.Minute),&(DateTime->Time.Second)) == 6) - { - strncpy (DateTime->Date.YYYYMMDD,YYYYMMDDHHMMSS,4+2+2); - DateTime->YYYYMMDDHHMMSS[4+2+2] = '\0'; - - strncpy (DateTime->YYYYMMDDHHMMSS,YYYYMMDDHHMMSS,4+2+2+2+2+2); - DateTime->YYYYMMDDHHMMSS[4+2+2+2+2+2] = '\0'; - - return true; - } - else - { - DateTime->Date.Year = DateTime->Date.Month = DateTime->Date.Day = 0; - DateTime->Date.YYYYMMDD[0] = '\0'; - - DateTime->Time.Hour = DateTime->Time.Minute = DateTime->Time.Second = 0; - DateTime->YYYYMMDDHHMMSS[0] = '\0'; - - return false; - } - } - /*****************************************************************************/ /******************** Write div for client local time ************************/ /*****************************************************************************/ @@ -241,6 +206,7 @@ void Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday (void) Txt_Start_date); /* Date-time */ Dat_WriteFormClientLocalDateTimeFromTimeUTC ("Start", + "Start", Gbl.DateRange.TimeUTC[0], Cfg_LOG_START_YEAR, Gbl.Now.Date.Year, @@ -274,6 +240,7 @@ void Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday (void) Txt_End_date); /* Date-time */ Dat_WriteFormClientLocalDateTimeFromTimeUTC ("End", + "End", Gbl.DateRange.TimeUTC[1], Cfg_LOG_START_YEAR, Gbl.Now.Date.Year, @@ -321,6 +288,7 @@ void Dat_PutFormStartEndClientLocalDateTimes (time_t TimeUTC[2]) /* Date-time */ Dat_WriteFormClientLocalDateTimeFromTimeUTC (Id[StartOrEndTime], + Id[StartOrEndTime], TimeUTC[StartOrEndTime], Gbl.Now.Date.Year - 1, Gbl.Now.Date.Year + 1, @@ -338,10 +306,11 @@ void Dat_PutFormStartEndClientLocalDateTimes (time_t TimeUTC[2]) /************************* Show a form to enter a date ***********************/ /*****************************************************************************/ -static void Dat_WriteFormClientLocalDateTimeFromTimeUTC (const char *Id, - time_t TimeUTC, - unsigned FirstYear,unsigned LastYear, - bool SubmitFormOnChange,bool Disabled) +void Dat_WriteFormClientLocalDateTimeFromTimeUTC (const char *Id, + const char *ParamName, + time_t TimeUTC, + unsigned FirstYear,unsigned LastYear, + bool SubmitFormOnChange,bool Disabled) { extern const char *Txt_MONTHS_SMALL[12]; unsigned Day; @@ -356,12 +325,12 @@ static void Dat_WriteFormClientLocalDateTimeFromTimeUTC (const char *Id, ""); /***** Year *****/ - fprintf (Gbl.F.Out,"" + fprintf (Gbl.F.Out,"" "" - ""); + ""); for (Day = 1; Day <= 31; Day++) @@ -421,10 +390,10 @@ static void Dat_WriteFormClientLocalDateTimeFromTimeUTC (const char *Id, ""); /***** Hour *****/ - fprintf (Gbl.F.Out,", " + fprintf (Gbl.F.Out,"" "" "