The primary purpose of my ND+ is acting as a scheduler that controls various relays. It also hosts a small HTTP site that allows for configuration of these schedules as well as manual on/off of the relays.
Right now, the ND+ starts up and queries NTP servers to set it's clock (using code found on the forums, I forget exactly where). One parameter of this though is hardcoded - the timezone offset.
This has bitten me a couple times due to daylight savings. This results in schedules running earlier or later than they normally would. It also gives strange results on my website UI (when I perform a manual activation, that activation is set for 15 minutes duration). The ND+ gets the activation request, calculates what the end time is (Now + 15 minutes) and that resulting end time is part of what gets sent back to the UI. But, depending on daylight savings, that end time can appear to be in the past. So instead of looking like it is going to run for 15 minutes, it looks like it is going to run for -45 minutes.
I was just wondering what others have done in similar situations to address this (without recompiling the code periodically with a different timezone offset - my current solution).
Thanks
Working around lack of timezone on ND+
Started by Cabadam, Apr 11 2012 07:38 PM
4 replies to this topic
#1
Posted 11 April 2012 - 07:38 PM
#2
Posted 11 April 2012 - 07:45 PM
Maybe this http://tinyclr.com/forum/23/6474/ will work for you.
- Cabadam likes this
#3
Posted 11 April 2012 - 07:50 PM
Maybe this http://tinyclr.com/forum/23/6474/ will work for you.
That looks like it may be exactly what I need.
Thanks,
#4
Posted 11 April 2012 - 08:18 PM
Depending on where you are in the world, you might be able to code a DST adjusting routine. For example here in the UK, BST always changes on the last Sunday in March and October (25 March 2012-28 October 2012 this year). Here is what I use:
So as long as you can grab an accurate date/time, you are good to go.
Private Function setBST(rawTime As DateTime) As DateTime Dim BSTstart As DateTime Dim BSTstop As DateTime Dim lastDateOfMonth As DateTime 'find the last sunday of march lastDateOfMonth = New Date(rawTime.Year, 3, Date.DaysInMonth(rawTime.Year, 3), 1, 0, 0) For i As Integer = 0 To 6 If lastDateOfMonth.AddDays(-1 * i).DayOfWeek = DayOfWeek.Sunday Then BSTstart = New DateTime(lastDateOfMonth.AddDays(-1 * i).Ticks) Exit For End If Next 'find the last sunday of october lastDateOfMonth = New Date(rawTime.Year, 10, Date.DaysInMonth(rawTime.Year, 10), 1, 0, 0) For i As Integer = 0 To 6 If lastDateOfMonth.AddDays(-1 * i).DayOfWeek = DayOfWeek.Sunday Then BSTstop = New DateTime(lastDateOfMonth.AddDays(-1 * i).Ticks) Exit For End If Next If (rawTime.Ticks >= BSTstart.Ticks) AndAlso (rawTime.Ticks <= BSTstop.Ticks) Then Return rawTime.AddHours(1) Else Return rawTime End If End Function
So as long as you can grab an accurate date/time, you are good to go.
#5
Posted 08 June 2012 - 12:11 AM
It also hosts a small HTTP site that allows for configuration of these schedules as well as manual on/off of the relays.
Do you mind sharing how you implemented the HTTP site, so I can use the same approach in my Sprinkler system project? (Code snipped/zip is always welcome)
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users