The White Flag
by Ellis Morning
in CodeSOD
on 2012-10-17
Handling dates is hard. Kevin sends us this attempt at building it from scratch, found in a third-party library. It was shaped with a Tab key that wishes nightly for death.
Protected Shared Function dateTimeFromJavaXml(ByVal dt As String) As DateTime
Dim datetime1 As DateTime = DateTime.get_Now()
If (dt.EndsWith(" GMT-12:00")) Then
dt = dt.Replace(" GMT-12:00", "-12:00")
ElseIf (dt.EndsWith(" GMT-11:00")) Then
dt = dt.Replace(" GMT-11:00", "-11:00")
GoTo label1
If (dt.EndsWith(" WSST")) Then
dt = dt.Replace(" WSST", "-11:00")
ElseIf (dt.EndsWith(" SDT")) Then
dt = dt.Replace(" SDT", "-11:00")
GoTo label2
If (dt.EndsWith(" NUST")) Then
dt = dt.Replace(" NUST", "-11:00")
ElseIf (dt.EndsWith(" GMT-10:00")) Then
dt = dt.Replace(" GMT-10:00", "-10:00")
GoTo label3
'SNIP: Let's skip ahead, retaining the indenting… scroll that way -> -> keep going -> and going oh, there it is!
If (Else.EndsWith(" TOST")) Then
dt = dt.Replace(" TOST", "+13:00")
ElseIf (dt.EndsWith(" GMT+14:00")) Then
dt = dt.Replace(" GMT+14:00", "+14:00")
GoTo label88
If (Else.EndsWith(" LINST")) Then
dt = dt.Replace(" LINST", "+14:00")
Else
dt = dt.Substring(0, (dt.LastIndexOf(" ") - 1))
End If
End If
'SNIP: we'll just skip past the sea of End Ifs and hope to find shore
End If
Try
label1:
label2:
label3:
label4:
label5:
label6:
label7:
label8:
label9:
'SNIP
label88:
datetime1 = DateTime.Parse(dt)
Catch exception As Exception
exception
End Try
Return datetime1
End Function