gdelataillade / alarm

A Flutter plugin to easily manage alarms on iOS and Android
https://pub.dev/packages/alarm
MIT License
132 stars 86 forks source link

If alarm is set to ring after 1 month it rings right after Alarm.set - Android #136

Closed yaro-melnychuk closed 9 months ago

yaro-melnychuk commented 10 months ago

Alarm plugin version 3.0.5

Describe the bug On Android devices, when setting the alarm dateTime for more than 1 month after the current date, the alarm starts immediately. (Should start in 1 month)

To Reproduce to reproduce on the example app replace this line with something like this dateTime: selectedDateTime.add(const Duration(days: 40)),

Expected behavior The alarm should ring after 40 days but rings immediately.

Device info Android only

gdelataillade commented 10 months ago

Hi @yaro-melnychuk

Thank you for sharing this issue.

I was able to reproduce your issue. It was caused by an integer overflow of the variable that stored the alarm delay in milliseconds. I just released a fix in version 3.0.6.

Please let me know if it fixes your issue.

melnychuk-yaro commented 10 months ago

worked, thank you so much

gdelataillade commented 10 months ago

Awesome. I'm closing the issue then.

kydoaod commented 9 months ago

Awesome. I'm closing the issue then.

I want to reopen this as I encounter this in version 3.0.8

gdelataillade commented 9 months ago

@kydoaod

Sure, it's reopened. What is the duration you gave ?

kydoaod commented 9 months ago

@kydoaod

Sure, it's reopened. What is the duration you gave ?

@gdelataillade I did try 1min from now, 7hours from now and 1hour from now but regardless, the outcome is the same. Bug is still there

gdelataillade commented 9 months ago

@kydoaod

Your alarm rings immediately regardless of the date time too ?

Do you have error logs ?

kydoaod commented 9 months ago

@kydoaod

Your alarm rings immediately regardless of the date time too ?

Do you have error logs ?

@gdelataillade

Yes but it does not have any error logs. Its just that the alarm trigger was wrong. By the way, I am using this package as well https://pub.dev/packages/flutter_background_service to overcome the issue about when the app was killed, it wont trigger alarm anymore. And also this package https://pub.dev/packages/awesome_notifications for other matters. Will that be helpful?

gdelataillade commented 9 months ago

@kydoaod

Is your device date time settings are correct ? I wonder if the error could happen if you changed it manually.

Alarm are supposed to ring even when app was killed (Android only).

kydoaod commented 9 months ago

@kydoaod

Is your device date time settings are correct ? I wonder if the error could happen if you changed it manually.

Alarm are supposed to ring even when app was killed (Android only).

@gdelataillade I think I found out what happened. So as I am trying to scheduled something periodically in our own code, there was a part there that stores the the alarm schedule in our code and it accidentally placing previous dates which probably resulted into this. It was quite confusing because even if thats the case, it should have never trigger the alarm at all right? But with some fixes, I think should be good on happy path

gdelataillade commented 9 months ago

Hi @kydoaod

I make alarms with date times in the past ring, to handle the case where an alarm did not trigger for some reason so it can still ring later, when it gets possible.

OK, so I'll let you fix your code. I'm closing this issue again. Send a message here for any other question, I'll see it.