Summertime / Wintertime problem

thewavemaster

Member
Licensed User
Longtime User
I*m making an app for shift workers...the apps is including an alarm to wake up.

So here is how it should work:
There s a service modul running in the background with service startforeground. its calculating the next awakening time, calls itself again and if datetime.now = alarm time then plays an awakening sound.
so far so good. The only problem is: its an app for german shiftworkers, so i have a little problem with the wintertime, summertime issue.

i tried to fix it with the following code:
B4X:
Dim so As Long
so = DateTime.Now
Dim varx As Int

If DateTime.GetMonth(DateTime.Now) = 10 Then
  For p = 0 To 6
   so = DateTime.Add(DateTime.Now,0,0,p)
   If DateTime.GetDayOfWeek(so) = 1 Then
    varx = DateTime.GetDayOfMonth(so) + 7
    If (varx > 31) Then
     datumdiff = datumdiff - (3600 * 1000)
    End If
   End If
  Next
End If

startserviceat(....datetime.now + datumdiff....)
This lines should check if the last sunday in october is between the time now and the sheduled alarm time.

Could you do me a favour and look over it with your b4a professional eyes? Because its hard to test if it works....
 

thewavemaster

Member
Licensed User
Longtime User
What exactly is the purpose of this code (which value are you trying to find)?

Hmm I try to explain it again (my english knowledge is my only limitation....)


the app shedules an alarm with startserviceat (datetime.now + datumdiff).
The problem is if i do the startserviceat command e.g. in summertime but the alarm is sheduled for a date in wintertime it will be one hour to early.

So with the lines above i want to find out if in the time between the command startserviceat and the sheduled alarmtime is a change from summertime to wintertime or the other way round.

the change is always on last sunday in march and the last sunday in october
 
Upvote 0

thewavemaster

Member
Licensed User
Longtime User
I*m making an app for shift workers...the apps is including an alarm to wake up.

So here is how it should work:
There s a service modul running in the background with service startforeground. its calculating the next awakening time, calls itself again and if datetime.now = alarm time then plays an awakening sound.
so far so good. The only problem is: its an app for german shiftworkers, so i have a little problem with the wintertime, summertime issue.

i tried to fix it with the following code:
B4X:
Dim so As Long
so = DateTime.Now
Dim varx As Int

If DateTime.GetMonth(DateTime.Now) = 10 Then ' Checks if month = october
  For p = 0 To 6 ' One Week =  7 days
   so = DateTime.Add(DateTime.Now,0,0,p) ' Check every day in the following seven days
   If DateTime.GetDayOfWeek(so) = 1 Then ' check if/when the next sunday comes
    varx = DateTime.GetDayOfMonth(so) + 7
    If (varx > 31) Then 'checks if this is the last sunday in the month
     datumdiff = datumdiff - (3600 * 1000) ' - 1 hour
    End If
   End If
  Next
End If

startserviceat(....datetime.now + datumdiff....)
This lines should check if the last sunday in october is between the time now and the sheduled alarm time.

Could you do me a favour and look over it with your b4a professional eyes? Because its hard to test if it works....

So here with comments
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I don't quite get it. isn't the time changed based on regional settings? why to force a calculation?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Ans why is it Not working? I didnt notice any Problem till now...
Existing scheduled services will be ignored after the phone is rebooted. So you cannot use StartServiceAt to schedule a service start for such a long period.

You should instead save the target date in a file, start your service every day and check whether today is a relevant date.
 
Upvote 0

thewavemaster

Member
Licensed User
Longtime User
Yes of course... Thats what im already doing!
I make a start at boot and then shedule again with startserviceat!

I have One more question erel:
I do calculations with datetime so for this calculations i have to Set timezone 0. before i do this i ask what the timezone is and then After the calculations i set timezone back to the original timezone before. What happens to the timezone in the App when the System timezones changes? Do i have to restart the App or is it automatically updated?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm sorry but I don't really understand what you are trying to do. You ask one question and then you say that you are doing something else.

You do not need to calculate the time between the target date and the current date. You can directly pass the target date to ServiceStartAt.

The timezone will not be automatically updated.

You can add an intent filter to: android.intent.action.TIMEZONE_CHANGED if you need to intercept this event.
 
Upvote 0
Top