Problem: Create two DateTimes from two arrays that hold only the number of minutes into each day. One for the current day and one for the next day. No dates are created yet, just minutes into each day.
The first array holds the start time in minutes into the first day and the second array holds the finish time in minutes into the next day.
The idea is to turn on a device from a stored minute integer value and have it turn off the next day from another stored integer minute value.
I’m a little confused about the code after looking at the multitude of examples.
I’m working on that at the moment but I’m looking for a method to convert 1221 minutes to hours and minutes. Other words I need to divide by 60 but how do I leave the remainder off to yield the minutes.
OK, I do not tested that (I trashed API2 Xojo IDE and downloaded 2020r1 but I do not had time to check).
But, in the API1, when you place seconds, minutes, hours, days, the Class do that job for you:
If I passed 45 days to a Date object, it add them to the Day property (to fill it) and compute the new month by itself. That is why I do say: Pass your number of minutes to the Constructor. OK, I do not explain it will fill/change the DateTime Class to the correct Day / Month.
Did you tried that ?
For the math, do you know how to use them ?
MOD for example; read the See Also part for other Math functions (you also can ask for Math in the search field).
I attempted to add a large number of minutes over 60 in:
Var SkylightTimeOff As New DateTime(d.year,d.month,d.day+1,Hours,Minutes)
and it did not like it.
What is strange to me now is if I use this code:
If SkylightFanStatus = False Then
Var OffTime As Integer = Arrays.VentilationPrefsArray(d.DayOfWeek,4)*5 // Calculate minutes on
Var Hours As Integer = OffTime \ 60
Var Minutes As Integer = OffTime Mod 60
Var SkylightTimeOff As New DateTime(d.year,d.month,d.day+1,Hours,Minutes)
End
SkylightTimeOff is Nil even though SkylightFanStatus is False. If I remove the "If Then code it works. Not sure what that is all about.
d.day+1 is to accommodate the turnoff time which is always on the next day. I’m not sure if adding a day to the end of the month will roll the month if needed.
Var TotalMin As Integer = (Arrays.VentilationPrefsArray(d.DayOfWeek,4))*5
Var interval As New DateInterval(0, 0, 1, 0, TotalMin)
Var SkylightTimeOff As New DateTime(d.year,d.month,d.day,0,0)
SkylightTimeOff = SkylightTimeOff + interval
A least for now!
A little more code:
If the controlled fan is on, this routine is bypassed so “d.day” will not be updated or the fan would never turn off.
I know two meanings for fan, but in the context, I do not understand.
Nota: there is a difference from API1 and API2 here. If the number of minutes is larger than 60 (I think), Xojo issue an Exception:
Exception Message: Minute out of range
API2 is easier.
So, Clifford, you are right, you have to compute the number of minutes and pass the remainder into the minutes and Mod to the number of days…
Var MinutesToGo As Integer
Var myMinutes As Integer
Var myDays As Integer
MinutesToGo = 1490
myMinutes = MinutesToGo Mod 1440
myDays = (MinutesToGo-myMinutes) \ 1440
With the code above, you will get 1 for myDays and 50 for myMinutes.
This software for a home automation system. The fan in this case is to bring in fresh air and pressurize above closable skylight shades. The skylights would normally condensate water in a bedroom. The fan must turn on in the late evening and turn off the next morning.