I'm trying to implement a 15/7/8 Minute Rule.
Personally I think my code sucks for this, but I'm doing the best that I can at the moment, which is why I'm here asking for help:
Code:
Public Function RoundMe1(dte As Date) As Double
Dim mins As Integer
Dim hours As Integer
hours = Hour(dte)
mins = Minute(dte)
'If mins >= 53 And mins <= 0 Then ' 7:53 to 8:07
' Round up
' RoundMe1 = RoundFromZero(dte, #12:15:00 AM#)
'ElseIf mins >= 1 And mins <= 7 Then ' 7:53 to 8:07
' Round down
' RoundMe1 = TimeSerial(hours, (mins \ 15) * 15, 0)
If mins >= 8 And mins <= 15 Then ' 8:08 to 8:22
' Round up
RoundMe1 = RoundFromZero(CDbl(dte), #12:15:00 AM#)
ElseIf mins >= 16 And mins <= 22 Then ' 8:08 to 8:22
' Round down
RoundMe1 = TimeSerial(hours, (mins \ 15) * 15, 0)
ElseIf mins >= 23 And mins <= 31 Then ' 8:23 to 8:37
' Round up
RoundMe1 = RoundFromZero(CDbl(dte), #12:15:00 AM#)
ElseIf mins >= 32 And mins <= 37 Then ' 8:32 to 8:37
' Round down
RoundMe1 = TimeSerial(hours, (mins \ 15) * 15, 0)
ElseIf mins >= 38 And mins <= 45 Then ' 8:38 to 8:52
' Round up
RoundMe1 = RoundFromZero(CDbl(dte), #12:15:00 AM#)
ElseIf mins >= 46 And mins <= 52 Then ' 8:53 to 8:52
' Round down
RoundMe1 = TimeSerial(hours, (mins \ 15) * 15, 0)
End If
End Function
I have two functions, for rounding the times up/down to the nearest 15 minutes. Now that those appear to work correctly (and I use this term loosely, considering one returns a time and the other returns a time and a date...but the correct rounded time and date), now I'm trying to determine when to round down and when to round up.
My code above takes into account when to round up and when to round down based on the information in the 15/7/8 minute rule article, but I am still at a loss as to what to do when faced with a day changing. I also realize that my code sucks because it uses many if statements instead of relying on some sort of math. So please, send me all the criticism you have, I'd really like to learn how this works.