Dear All,
I was looking for a simple way to determine whether if a time is formatted correctly or not. My program uses a time picker, but also can be accessed remotely where a time needs to be entered manually in a prompt, and that´s where I need it.
So I found this thread:
https://www.b4x.com/android/forum/threads/verify-a-valid-date.92274/#content
And made this, just an example to show the problem:
In the log this gives me:
11:49:06
false
09:49:06
true
11:49:06
So, if I don´t parse a valid time after an invalid one, the timezone offset changes!
I just fixed it by modifying the code so that it always automatically will pass a valid time afterwards, and it works fine for me that way but I highly doubt that this is intentional.
I was looking for a simple way to determine whether if a time is formatted correctly or not. My program uses a time picker, but also can be accessed remotely where a time needs to be entered manually in a prompt, and that´s where I need it.
So I found this thread:
https://www.b4x.com/android/forum/threads/verify-a-valid-date.92274/#content
And made this, just an example to show the problem:
B4X:
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
End Sub
Sub istimevalid (mtime As String)
Try
DateTime.TimeParse(mtime)
Catch
Return False
End Try
'Log (DateTime.DateTimeParse(DateTime.Date(DateTime.Now),DateTime.Time(DateTime.Now)))
Return True
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
MainForm.Show
Log (DateTime.Time(DateTime.Now))
Log (istimevalid("blah"))
Log (DateTime.Time(DateTime.Now))
Log (istimevalid("02:17:30"))
Log (DateTime.Time(DateTime.Now))
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
In the log this gives me:
11:49:06
false
09:49:06
true
11:49:06
So, if I don´t parse a valid time after an invalid one, the timezone offset changes!
I just fixed it by modifying the code so that it always automatically will pass a valid time afterwards, and it works fine for me that way but I highly doubt that this is intentional.
Last edited: