Android Question The same sum up (two hours) give two different results in two different mobiles

Espinosa4

Active Member
Licensed User
Longtime User
Hi,

I've a problem with a procedure. I've different results in two different mobiles
This is the code

B4X:
Private Sub DimeHoraConducirOtraVez(hdescanso As Int) As String
    Dim Hr1,Hr2, Hf As Long
    Dim sh As String
    DateTime.TimeFormat = "HH:mm"
    Hr1 = DateTime.TimeParse(EdtFinal.Text)
    Hr2 = DateTime.TimeParse("00:"&hdescanso)
    Hf = Hr1 + Hr2
'    Log(DateTime.GetHour(Hr1)&" + "&DateTime.GetHour(Hr2))
'    Log("Hora suma hr1 + hr2: "&DateTime.Time(Hf))
    Dim HoraArreglada, MinutoArreglado As String
    HoraArreglada = DateTime.GetHour(Hf)
    MinutoArreglado = DateTime.GetMinute(Hf)
    If HoraArreglada.Length = 1 Then HoraArreglada = "0"&DateTime.GetHour(Hf)
    If MinutoArreglado.Length = 1 Then MinutoArreglado = "0"&DateTime.GetMinute(Hf)
    sh = HoraArreglada &":"& MinutoArreglado
    Return sh
End Sub


I'm adding minutos into an hour.
20:52 + 17 minutes (hdescanso) in my Xiaomi gives = 21:09 and the same numbers in an Oppo the result is = 20:09.


Any idea?
Thank you very much indeed in advance for your help.
Cheers
 

Espinosa4

Active Member
Licensed User
Longtime User
Here the pics
 

Attachments

  • IMG-20240225-WA0014.jpg
    IMG-20240225-WA0014.jpg
    38.8 KB · Views: 87
  • Screenshot_2024-02-25-20-04-28-270_SIF.InfoSIF.jpg
    Screenshot_2024-02-25-20-04-28-270_SIF.InfoSIF.jpg
    264.5 KB · Views: 90
Upvote 1

MbedAndroid

Well-Known Member
Licensed User
Longtime User
if i try your code in b4j the result is 21:09
i should debug step by step with logging the code on Oppo and Xiaomi and compare the results.
 
Upvote 0

Espinosa4

Active Member
Licensed User
Longtime User
Here another rare sum
Adding 15 minutes
 

Attachments

  • IMG-20240225-WA0015.jpg
    IMG-20240225-WA0015.jpg
    38.8 KB · Views: 89
  • Screenshot_2024-02-25-20-29-55-199_SIF.InfoSIF.jpg
    Screenshot_2024-02-25-20-29-55-199_SIF.InfoSIF.jpg
    264.3 KB · Views: 87
Upvote 0

emexes

Expert
Licensed User
Here the pics
The issue is probably that Hr1 and Hr2 are not just milliseconds since midnight: they are milliseconds since 00:00 of start of 1970.

So you are not just adding on 17 minutes: you are adding on (lots of days + 17 minutes) and ending up at a date-time 53 years in the future which falls in the other half of the daylight-savings cycle.

The two phones likely have different timezone settings, or one has daylight savings enabled and the other does not

Append " HH:mm" to the DateTime.DateFormat, and log Hr1 Hr2 Hf using DateTime.Date, for a clearer view of what's happening.
 
Upvote 0

Espinosa4

Active Member
Licensed User
Longtime User
The issue is probably that Hr1 and Hr2 are not just milliseconds since midnight: they are milliseconds since 00:00 of start of 1970.

So you are not just adding on 17 minutes: you are adding on (lots of days + 17 minutes) and ending up at a date-time 53 years in the future which falls in the other half of the daylight-savings cycle.

The two phones likely have different timezone settings, or one has daylight savings enabled and the other does not

Append " HH:mm" to the DateTime.DateFormat, and log Hr1 Hr2 Hf using DateTime.Date, for a clearer view of what's happening.

Yessss, something is wrong here.

OPPO
---------------------------
Hr1 -> 25/02/2024
Hr2 -> 25/02/2024
Hf -> 20/04/2078


XIAOMI
---------------------
Hr1 -> 25/02/2024
Hr2 -> 25/02/2024
Hf -> 20/04/2078
 
Upvote 0

emexes

Expert
Licensed User
You can still use .ParseTime .GetHours and .GetMinutes to parse the "00:17" into 0 hours and 17 minutes, as long as you don't wrap-around into the next day on a daylight savings changeover ?

but it is probably better to split the HH:mm strings into hour and minute values "manually" using either Regex.Split or similar, or String.IndexOf and .Substring2 ?
 
Upvote 0
Top