As per thiagoralves suggestions, code simplification and few bugs fixed in the original date and time management. Also added the leap year management directly into the MonthDays[1..12] array, otherwise it was causing issues on the February 29th of a leap year.
Also, as promised, I included the SunClock as a function block for the benefit of everyone. I spent many hours/days to get it working properly because of PLCOpenEditor being very picky about variable types (can't work with different types in a same equation). It was still a nice challenge and I'm happy to provide it to you; I really hope it will help someone...
For the SunClock, inside the function block, there's few constants to set such as timezone, latitude and longitude of your specific location. I picked a small town in Quebec, Canada to test it and compared to a simple google search of current sunset, sunrise, etc. and it is mostly within a minute of difference. Two reasons to this:
1 - Google search doesn't know the exact location of the computer when making a search for this type of information and approximate up to 60 miles (100km) around. In either direction, it impacts the solar time of day
2 - The formula used is a simple version of the real which is very complicated to implement in this type of controller and it would be over killed as we don't want to send a rocket in space, don't we?
2a - Exact formula, good luck : https://www.nrel.gov/docs/fy08osti/34302.pdf.
2b - If you want to trigger some events in regard to sun (e.g.: turn ON a light at sunset), it will work perfectly. If you want to use it as a sun tracker for solar panels, this is NOT the algorithm you need.
As you can see from below image in the Radzio modbus nodes
10-12 Date : 2018/11/3
13-15 Time : 22h49m15s
16 So I was also getting 2249 as military time
17 We're Saturday, so day of week is 6,
18 The 1 is for DST active (consequently, it will turn to zero in few hours)
19 The 0 is for leap year (would be 1 if it we were in a leap year).SunClock information as per the little town north in Quebec, Canada
20 Dawn time : 7h06
21 Sunrise time : 7h39
22 Solar noon time : 12h32
23 Sunset time : 17h26
24 Dusk time : 17h59
25 Solar midnight time : 00h32