Android Question Time alarm

hookshy

Well-Known Member
Licensed User
Longtime User
It took me 30 minute to compose the folowing question ..so be gentle :)

Exemple:
time1 measured in ticks = tree days ago at time x measured in hours

How can I see if the time x is in given scheduled ?

9.00 am < time x < 12.00 am ?
now the clock is 10.30 am

and more precise 90 minutes timespan from now
 

hookshy

Well-Known Member
Licensed User
Longtime User
no need to parse date because I allready have the ticks and i can easy get hour with datetme.gethour
I will try to reformulate :
I press button and records the time ticks . Ex : I press button at 9 o clock ...date not mather

Then I will press button again after some days ...I what to see if this time it was in same time span with the earlier record .
Translating the sentence above:
I press button after some days after the first event ...if this time is in hours between 8 and 10 ..then Bang!!!!

It is hard ...sory ...
hope you understand now
 
Upvote 0

hookshy

Well-Known Member
Licensed User
Longtime User
I realy bealive that if you don't put questions you won't find answers ...I am certain to find a solution ....in some datetime:)))
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
First day, you press the button:
FirstPressTimeTicks = DateTime.Now - NowDayTicks
save this somewhere

thrid day you press the button, get new ticks
SecondPressTimeTicks = DateTime.Now - NowDayTicks

Now compare with earlier record:
if SecondPressTimeTicks > (FirstPressTimeTicks - (1 x DateTime.TicksPerHour) AND SecondPressTimeTicks < (FirstPressTimeTicks + (1 x DateTime.TicksPerHour)

so if FirstPressTimeTicks = 9

then it checks if Second > (9 - 1) and Second < (9 + 1)
 
Upvote 0

hookshy

Well-Known Member
Licensed User
Longtime User
Help me a bit.
FirstPressTimeticks - would be the time elapsed measured in ticks since the day began ?
What is the meaning of Nowdayticks ?

I hapy to find new track ...I will start work upon your example ..first to understand it.
Thanks ;)
 
Upvote 0

hookshy

Well-Known Member
Licensed User
Longtime User
I think of the folowing example
Frist time . yesterday x hour 23
Second time . today y hour 2

PeriodBetween = 0 days, 3 hours , 0 minutes ,0 seconds

How can I use hours,minutes and seconds field to see if the second time 2 o'clock is a timespan of 10 minutes from 23 a 'clock
23 o'clock-10 minutes < 2 o'clock < 23 o'clock +10 minute ??
first time(hour) -10minutes < second time(hour) < first time(hour)+10 minutes
 
Upvote 0

hookshy

Well-Known Member
Licensed User
Longtime User
I wrote the code below , now i have to test it ...does it look ok ?

B4X:
Sub intime (lasttime As Long,span_minutes As Int) As Boolean

Dim tfx As Long
tfx=lasttime-DateTime.GetHour(lasttime)*DateTime.TicksPerHour ' calculates ticks elapsed from 0 o'clock lasttime date
Dim tfy As Long
tfy=DateTime.Now-DateTime.GetHour(DateTime.Now)*DateTime.TicksPerHour ' calculates ticks elapsed from 0 o'clock now date

' now brings last time to present minus hours diference
Dim lasttime_present As Long
lasttime_present= lasttime+(tfy-tfx) ' lasttime ticks + date diference


'checks the normal expire time routine as lastime is happens now but at diferent hour clock
If DateTime.Now < lasttime_present + span_minutes*DateTime.TicksPerMinute AND DateTime.Now> lasttime_present - span_minutes*DateTime.TicksPerMinute Then
Return True
end sub
End If
 
Upvote 0

hookshy

Well-Known Member
Licensed User
Longtime User
I have made some ajustments
B4X:
Sub intime (lasttimex As Long,span_minute As Int) As Boolean

Dim tfx As Long
tfx=lasttimex-DateTime.GetHour(lasttimex)*DateTime.TicksPerHour - DateTime.GetMinute(lasttimex)*DateTime.TicksPerMinute-DateTime.GetSecond(lasttimex)*DateTime.TicksPerSecond ' calculates ticks elapsed from 0 o'clock lasttime date
Log("tfx:"&tfx)
Log("orax"&DateTime.GetHour(lasttimex))
Log("minx"&DateTime.GetMinute(lasttimex))
Log("secx"&DateTime.GetSecond(lasttimex))

Dim tfy As Long
tfy=DateTime.Now-DateTime.GetHour(DateTime.Now)*DateTime.TicksPerHour-DateTime.GetMinute(DateTime.Now)*DateTime.TicksPerMinute-DateTime.GetSecond(DateTime.Now)*DateTime.TicksPerSecond ' calculates ticks elapsed from 0 o'clock now date
Log("tfy:"&tfy)
Log("ora_now"&DateTime.GetHour(DateTime.Now))
Log("min_now"&DateTime.GetMinute(DateTime.Now))
Log("sec_now"&DateTime.GetSecond(DateTime.Now))

' now brings last time to present minus hours diference
Dim lasttime_present As Long
lasttime_present= lasttimex+(tfy-tfx) ' lasttime ticks + date diference
Log("lasttime_present:" &lasttime_present)
Log(DateTime.Time(lasttime_present))
Log(DateTime.Time(DateTime.Now))

'checks the normal expire time routine as lastime is happens now but at diferent hour clock
If DateTime.Now < lasttime_present + span_minute*DateTime.TicksPerMinute AND DateTime.Now> lasttime_present - span_minute*DateTime.TicksPerMinute Then
Return True
End If


End Sub
 
Upvote 0

hookshy

Well-Known Member
Licensed User
Longtime User
The purpose of my question !
User set proximity alert city x from 6 to 9 o'clock. year 2012 was the time of first location and time based alarm.
Each time user passed city x and the time is between 6 and 9 o'clock an alarm is triggered.
 
Upvote 0

MaFu

Well-Known Member
Licensed User
Longtime User
This code snippet checks the difference in minutes between two times ignoring days (seconds will be ignored at the moment)
dt1 is first DateTime, dt2 is second DateTime, maxRange ist the max. difference in minutes to check.
B4X:
Sub Time_In_Range(dt1 As Long, dt2 As Long, maxRange As Int) As Boolean
    Dim p As Period = DateUtils.PeriodBetween(dt1, dt2)
    Dim diff As Long = Abs(p.Hours) * 60 + Abs(p.Minutes)
    If Min(diff, 1440 - diff) <= maxRange Then
        Return True
    Else
        Return False
    End If
  
End Sub
 
Last edited:
Upvote 0
Top