Android Question Bug in DateTimeParse in Android 7? [Resolved]

GuyBooth

Active Member
Licensed User
Longtime User
My app has a function to translate HH:MM:SS strings to milliseconds (and another one to reverse the process). It was working fine until my tablet was updated to Android 7.0.
It now throws an error at this line:

B4X:
' HoursMinsSecs format is "##:##:##"
ls1 = DateTime.DateTimeParse("01/01/01", HoursMinsSecs)
Here are the first three lines of the error log:
B4X:
java.text.ParseException: Unparseable date: "00:03:05"
     at java.text.DateFormat.parse(DateFormat.java:358)
     at anywheresoftware.b4a.keywords.DateTime.DateTimeParse(DateTime.java:191)

I tried changing this to eliminate the date - I don't need the date itself. My modified code is
B4X:
ls1 = DateTime.TimeParse(HoursMinsSecs)
It, too, throws an error:
B4X:
java.text.ParseException: Unparseable date: "00:03:05"
    at java.text.DateFormat.parse(DateFormat.java:358)
    at anywheresoftware.b4a.keywords.DateTime.TimeParse(DateTime.java:171)
Note that in all cases - even with "TimeParse" - the error says Unparseable Date

Is this a bug? Or is it something I'm doing wrong that was forgiven in versions before 7.0 but not any more?
 

JordiCP

Expert
Licensed User
Longtime User
Try to Log the expected date&Time format
B4X:
Log(DateTime.DateFormat)
Log(DateTime.TimeFormat)
 
Upvote 0

GuyBooth

Active Member
Licensed User
Longtime User
Try to Log the expected date&Time format
Code:
Log(DateTime.DateFormat)Log(DateTime.TimeFormat)

JordiCP, Today at 11:26 AM
A log of the Date Format and the Time format produces:
B4X:
dateformat dd/MM/yy, timeformat hh:mm:ss
Which is as expected.

Yes, this is done in a routine that is called from the Starter Service. Also remember, this was working in Android at least up to 4.4.2
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
ls1 = DateTime.DateTimeParse("01/01/01", HoursMinsSecs)
As written by you the Timeformat is hh:mm:ss
But you did not answered @JordiCP question in post #2

The answer is missing for your DATEFORMAT

Unparseable date: "00:03:05"

Seems like you are giving the TIME-Value (should be 2nd parameter) into the DATE Parameter (1st parameter) of DateTimeParse?
 
Upvote 0

GuyBooth

Active Member
Licensed User
Longtime User
As written by you the Timeformat is hh:mm:ss
So it can not work using "/" where a ":" is expected.
If you read this carefully, you will see that for DateTimeParse I am supplying the Date in the expected format (##/##/##) and the Time also in the expected format (##:##:##)
For TimeParse I am supplying the Time in the expected format (##:##:##).
 
Upvote 0

GuyBooth

Active Member
Licensed User
Longtime User
As written by you the Timeformat is hh:mm:ss
But you did not answered @JordiCP question in post #2

The answer is missing for your DATEFORMAT



Seems like you are giving the TIME-Value (should be 2nd parameter) into the DATE Parameter (1st parameter) of DateTimeParse?
Yes I did - my answer is posted right in my first reply.
 
Upvote 0

GuyBooth

Active Member
Licensed User
Longtime User
Let's make this as simple as I can. I have a piece of code that works in Android 4.4.2.
The identical code in Android 7.0 throws an error.

B4X:
' HoursMinsSecs format is "##:##:##"
ls1 = DateTime.TimeParse(HoursMinsSecs)
Throws this error:
B4X:
java.text.ParseException: Unparseable date: "00:03:05"
    at java.text.DateFormat.parse(DateFormat.java:358)
    at anywheresoftware.b4a.keywords.DateTime.TimeParse(DateTime.java:171)

Note that the error says Unparseable DATE - even though this is a "TimeParse" function, as confirmed in the third line of the error log.

A log of the Time format in effect shows
B4X:
timeformat is hh:mm:ss
 
Upvote 0

GuyBooth

Active Member
Licensed User
Longtime User
Have you tried setting the time format to HH:mm:ss instead of hh:mm:ss
Great catch, fixit30! That did it.
Interesting - it answers the question I posed in the last line of my original post:
"Is it something I'm doing wrong that was forgiven in versions before 7.0 but not any more?"
Yes - previous versions were working fine even with the "hh:mm:ss" format.
Thank you!
 
Upvote 0
Top