Task

Given the date string "March 7 2009 7:30pm EST", 

output the time 12 hours later in any human-readable format.

As extra credit, display the resulting time in a time zone different from your own.




' FB 1.05.0 Win64
 
#include "vbcompat.bi"
 
Sub split (s As String, sepList As String, result() As String, removeEmpty As Boolean = False)
  If s = "" OrElse sepList = "" Then 
     Redim result(0)
     result(0) = s
     Return
  End If
  Dim As Integer i, j, count = 0, empty = 0, length
  Dim As Integer position(Len(s) + 1)
  position(0) = 0
 
  For i = 0 To len(s) - 1
    For j = 0 to Len(sepList) - 1
      If s[i] = sepList[j] Then 
        count += 1
        position(count) = i + 1       
      End If
    Next j
  Next i
 
  Redim result(count)
  If count  = 0 Then
    result(0) = s
    Return
  End If
 
  position(count + 1) = len(s) + 1
 
  For i = 1 To count + 1  
    length = position(i) - position(i - 1) - 1 
    result(i - 1 - empty) = Mid(s, position(i - 1) + 1, length)
    If removeEmpty Andalso CBool(length = 0) Then empty += 1
  Next
 
  If empty > 0 Then Redim Preserve result(count - empty)
End Sub
 
Function parseDate(dt As String, zone As String) As Double
  Dim result() As String
  split dt, " ", result(), True
  Dim As Long m, d, y, h, mn
  Dim am As Boolean
  Dim index As Integer 
  Select Case Lcase(result(0))
    Case "january"    : m = 1
    Case "february"   : m = 2
    Case "march"      : m = 3
    Case "april"      : m = 4
    Case "may"        : m = 5
    Case "june"       : m = 6
    Case "july"       : m = 7
    Case "august"     : m = 8
    Case "september"  : m = 9
    Case "october"    : m = 10
    Case "november"   : m = 11
    Case "december"   : m = 12
  End Select
  d = ValInt(result(1))
  y = ValInt(result(2))
  result(3) = LCase(result(3))
  am = (Right(result(3), 2) = "am")
  index = Instr(result(3), ":")
  h = ValInt(Left(result(3), index - 1))
  If Not am Then 
    h = h + 12
    If h = 24 Then h = 12
  End If 
  mn = ValInt(Mid(result(3), index + 1, 2))
  zone = result(4)
  Return DateSerial(y, m, d) + TimeSerial(h, mn, 0)
End Function
 
Dim zone As String
Dim ds As Double = parseDate("March 7 2009 7:30pm EST", zone)
Print "Original Date/Time  : "; Format(ds, "mmmm d yyyy h:nnam/pm ") + "  " + zone 
ds = DateAdd("h", 12, ds)
Print "12 hours later      : "; Format(ds, "mmmm d yyyy h:nnam/pm ") + "  " + zone
' add 5 hours to convert EST to UTC
ds = DateAdd("h", 5, ds) 
Print "Equiv to Date/Time  : "; Format(ds, "mmmm d yyyy h:nnam/pm ") + " UTC"
Print
Print "Press any key to quit"
Sleep