#property script_show_inputs input int InpYear = 0; // Année input int InpMonth = 0; // Mois input int InpDay = 0; // Jour input int InpHour = 0; // Heures input int InpMin = 0; // Minutes input int InpSec = 0; // Secondes //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- ajuste les valeurs entrées et les affecte aux variables int year = (InpYear<1970 ? 1970 : InpYear); // Si l'année saisie est inférieure à 1970, alors 1970 est utilisée int month= (InpMonth<1 ? 1 : InpMonth > 12 ? 12 : InpMonth); int day = (InpDay <1 ? 1 : InpDay > 31 ? 31 : InpDay); int hour = (InpHour <0 ? 0 : InpHour > 23 ? 23 : InpHour); int min = (InpMin <0 ? 0 : InpMin > 59 ? 59 : InpMin); int sec = (InpSec <0 ? 0 : InpSec > 59 ? 59 : InpSec); //--- affiche dans le journal les valeurs saisies PrintFormat("Entered date and time: %04u.%02u.%02u %02u:%02u:%02u", InpYear, InpMonth, InpDay, InpHour, InpMin, InpSec); //--- affiche dans le journal les valeurs ajustées PrintFormat("Corrected date and time: %04u.%02u.%02u %02u:%02u:%02u", year, month, day, hour, min, sec); //--- écrit les valeurs saisies dans les champs correspondants de la structure MqlDateTime time_struct={}; time_struct.year= year; time_struct.mon = month; time_struct.day = day; time_struct.hour= hour; time_struct.min = min; time_struct.sec = sec; //--- convertit la date et l'heure de la structure dans une variable de type datetime et datetime time = StructToTime(time_struct); //--- affiche le résultat de la conversion de la variable de type MqlDateTime dans la valeur de type datetime Print("Converted date and time: ",TimeToString(time,TIME_DATE|TIME_MINUTES|TIME_SECONDS)); /* résultats si les valeurs par défaut sont saisies : Entered date and time: 0000.00.00 00:00:00 Corrected date and time: 1970.01.01 00:00:00 Converted date and time: 1970.01.01 00:00:00 résultats si le mauvais jour du mois de février de l'année est saisi : Entered date and time: 2024.02.31 00:00:00 Corrected date and time: 2024.02.31 00:00:00 Converted date and time: 2024.03.02 00:00:00 */ } |