I have a situation where I want to add a clock to a date and add a new date on a business day. I created a function to determine this new date, but I want to make sure that I don't forget anything.
The clock to be added is called a βdelayβ. This can be an easy parameter for a function.
Please post any suggestions. [VB.NET Warning]
Private Function GetDateRequired() As Date ''// A decimal representation of the current hour Dim hours As Decimal = Decimal.Parse(Date.Now.Hour) + (Decimal.Parse(Date.Now.Minute) / 60.0) Dim delay As Decimal = 3.0 ''// delay in hours Dim endOfDay As Decimal = 12.0 + 5.0 ''// end of day, in hours Dim startOfDay As Decimal = 8.0 ''// start of day, in hours Dim newHour As Integer Dim newMinute As Integer Dim dateRequired As Date = Now Dim delta As Decimal = hours + delay ''// Wrap around to the next day, if necessary If delta > endOfDay Then delta = delta - endOfDay dateRequired = dateRequired.AddDays(1) newHour = Integer.Parse(Decimal.Truncate(delta)) newMinute = Integer.Parse(Decimal.Truncate((delta - newHour) * 60)) newHour = startOfDay + newHour Else newHour = Integer.Parse(Decimal.Truncate(delta)) newMinute = Integer.Parse(Decimal.Truncate((delta - newHour) * 60)) End If dateRequired = New Date(dateRequired.Year, dateRequired.Month, dateRequired.Day, newHour, newMinute, 0) Return dateRequired End Sub
Note This probably will not work if the delay is more than 9 hours. It should never change from 3 to.
EDIT: The goal is to find the date and time that you get as a result of adding a few hours to the current time. This is used to determine the default value for the filing date. I want to add 3 hours to the current time to get the time. However, I do not want to set dates that go beyond 5 pm on the current day. So, I tried to divide the hours between (today, until 5pm) and (tomorrow, from 8am), so adding 3 hours to 4pm will give you 19 hours, because 1 hour is added to the end of today and 2 hours are added to start tomorrow.
source share