0
I’m trying to see if a schedule exists within a range of initial and final hours, but I’m having a problem setting the condition.
Example
Parameter time: 07:00:00
Initial time: 06:00:00
Final time: 23:00:00
Only by my code this parameter does not enter the range, and what really happens is that it reverses the entries in the condition, when it should enter, it leaves and vice versa.
Follows code:
DateTime dtImportacao = new DateTime(2019,07,01,07,00,00);
TimeSpan[] datasInicias = new TimeSpan[]
{
new TimeSpan(06,00,00),
new TimeSpan(00,00,00),
new TimeSpan(23,00,00),
new TimeSpan(06,00,00),
new TimeSpan(19,00,01),
new TimeSpan(06,00,00),
new TimeSpan(23,00,00),
new TimeSpan(08,00,00),
new TimeSpan(19,00,00),
new TimeSpan(19,00,00),
new TimeSpan(06,00,00),
new TimeSpan(22,00,00),
new TimeSpan(23,00,00),
new TimeSpan(06,00,01)
};
TimeSpan[] datasFinais = new TimeSpan[]
{
new TimeSpan(23,00,00),
new TimeSpan(23,59,59),
new TimeSpan(06,00,00),
new TimeSpan(19,00,00),
new TimeSpan(05,59,59),
new TimeSpan(23,00,00),
new TimeSpan(06,00,00),
new TimeSpan(20,00,00),
new TimeSpan(06,00,00),
new TimeSpan(05,45,59),
new TimeSpan(22,00,00),
new TimeSpan(06,00,00),
new TimeSpan(06,00,00),
new TimeSpan(22,59,59)
};
for (int i = 0; i < datasInicias.Length; i++)
{
if ((TimeSpan.Compare(dtImportacao.TimeOfDay, datasInicias[i]) == -1 || TimeSpan.Compare(dtImportacao.TimeOfDay, datasInicias[i]) == 0) || (TimeSpan.Compare(dtImportacao.TimeOfDay, datasFinais[i]) == 0 || TimeSpan.Compare(dtImportacao.TimeOfDay, datasFinais[i]) == 1))
{
Console.WriteLine("Parametro de Comparação: {0} | {1} Até {2} Dentro do Range", dtImportacao.ToString("HH:mm:ss"), datasInicias[i], datasFinais[i]);
}
else
{
Console.WriteLine("Parametro de Comparação: {0} | {1} Até {2} Fora do Range", dtImportacao.ToString("HH:mm:ss"), datasInicias[i], datasFinais[i]);
}
}
However I do not know should put in my decision all parameters of Timespan.Compare() to validate.