[bug] DateTime.TimeParse

nico78

Active Member
Licensed User
Longtime User
ret=DateTime.TimeParse("16:13:00")
Log(DateTime.Time(ret))

The result is 17:13:00 ?????
 

Djembefola

Active Member
Licensed User
Longtime User
You need to add the timezone.

Try this:

B4X:
Dim timezone As Long
Dim ret as long

timezone = DateTime.DateParse("01/01/1970 00:00:00")
ret = DateTime.TimeParse("16:13:00") + timezone
Log (DateTime.Time(ret))
 

nico78

Active Member
Licensed User
Longtime User
It's not logic:

ret = DateTime.DateParse( "12/13/1982")
Log (DateTime.date(ret))

the result is good,

if there is no problem with the date, it should not be a problem with the time

Erel, can you confirm the bug ?
 

Djembefola

Active Member
Licensed User
Longtime User
It's not logic:

if there is no problem with the date, it should not be a problem with the time

What about the logic in your post? ;)

When you call DateParse (with a time value) or TimeParse the value returned considers the local time zone.

For a date without any time value, the time zone information is obviously needless.
 

nico78

Active Member
Licensed User
Longtime User
you are off topic, I never talk about date with a time value!

I begin again:

if i want a specific date, i do:
ret=DateTime.DateParse ("13/12/1982")

I check:
Log (datetime.date (ret)) , it's ok


if i want a specific time, i do:
ret=DateTime.TimeParse ("13:10:07")

I check:
Log (datetime.time (ret)) , it's no ok, return 14:10:07

why the time is incorrect ??? : BangHead:
 

thedesolatesoul

Expert
Licensed User
Longtime User
It is wrong because you live in France.
Use the Search function. Many people have been confused because of time zones.

When you do:
ret=DateTime.TimeParse("16:13:00")

The time you have passed to it i.e. "16:13:00" is UTC/GMT time.
The time that TimeParse returns includes the timezone changes.
 

kolbe

Active Member
Licensed User
Longtime User
It is a bug and it will be fixed in the next version. TimeParse should consider the time zone.

There may still be a small related problem here. Early this morning Tue. at 12:08am datetime.timeparse returned the right time but if you do a datetime.date on the ticks result it gives you Mon. and not Tue. This morning it works fine.
 

kolbe

Active Member
Licensed User
Longtime User
Maybe the problem related here is the same.

After doing a bit of troubleshooting...

With a timezone of GMT+2 the wrong date is returned (via ticks) when the device time is b/w 12:00am and 2:00am. If I change timezone to GMT all is fine.

Seems to me it is all related... my problem, the above bug and the link you provided.
 

bobsimoneau

Member
Licensed User
Longtime User
It is a bug and it will be fixed in the next version. TimeParse should consider the time zone.

It appears to still be broken in the 2.0 beta. Eastern time (-4) is off by a day between 8pm and 12am.
 
Last edited:

kolbe

Active Member
Licensed User
Longtime User
Can you post the code that demonstrates this issue?

The code is straightforward.

B4X:
Dim fulldatetime As Long
Dim date as String

fulldatetime=DateTime.TimeParse("06:00:00")
date=DateTime.Date(fulldatetime)

The test case a bit more involved.

The problem is that the ticks returned by datetime.timeparse are incorrect when the device time is within the timezone correction. Incorrect because the date is incorrect, the time on the contrary is correct.

For example. If code above is run on 6/14/12 the date above should always be 6/14/12. However if your device is set for the timezone GMT+2 then when the device time is in between 12:00am and 2:00am the date returned is not 6/14/12 but 6/13/12. As bobsimoneau mentioned, he is in timezone GMT-4 and he sees this behavior between 8pm and 12am.

Looking at the value of fulldatetime you can see the problem is with datetime.timeparse()

Hope this is clear.
 
Last edited:
Top