Thursday, July 12, 2007

Wow, so my last post had a glaring logic error.
It seems I forgot that the dateadd needed the conversion figure, r, not the modified version, c + r.
I've cleaned it up and added another function here so that I can still get the modified component with a function call.

Private Shared Function GetClosest15(ByVal t As Date)
Dim c As Int32 =
RoundTo15GetPlusMinusComponent(t.Minute)
Return DateAdd(DateInterval.Second,
-t.Second, DateAdd(DateInterval.Minute, c, t))
End Function


Private Shared
Function RoundTo15GetPlusMinusComponent(ByVal c As Int32)
Dim r As Int32 = c
Mod 15
If r <= 7 Then r *= -1 Else r = 15 - r
Return r
End
Function


Private Shared Function RoundTo15(ByVal c As Int32)
Dim r As
Int32 = RoundTo15GetPlusMinusComponent(c)
Return c + r
End Function

No comments: