Skip to content

Commit

Permalink
Fix override alarm logic & increment to 3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gdelataillade committed Dec 21, 2023
1 parent 2958ed3 commit d701f78
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 3.0.1
* Only override an existing alarm if it's scheduled for the identical second.

## 3.0.0
**💥 Breaking Changes**\
**🔧 Android installation steps were updated [here](https://github.com/gdelataillade/alarm/blob/main/help/INSTALL-ANDROID.md).**
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ This is how to run some code when alarm starts ringing. I implemented it as a st
Alarm.ringStream.stream.listen((_) => yourOnRingCallback());
```

To avoid unexpected behaviors, if you set an alarm for the same time as an existing one, the new alarm will replace the existing one.
To avoid unexpected behaviors, if you set an alarm for the same time, down to the second, as an existing one, the new alarm will replace the existing one.

## 📱 Example app

Expand Down
2 changes: 1 addition & 1 deletion example/lib/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class _ExampleAlarmHomeScreenState extends State<ExampleAlarmHomeScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('alarm 3.0.0')),
appBar: AppBar(title: const Text('alarm 3.0.1')),
body: SafeArea(
child: alarms.isNotEmpty
? ListView.separated(
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
path: ".."
relative: true
source: path
version: "3.0.0"
version: "3.0.1"
async:
dependency: transitive
description:
Expand Down
14 changes: 11 additions & 3 deletions lib/alarm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ class Alarm {

for (final alarm in Alarm.getAlarms()) {
if (alarm.id == alarmSettings.id ||
(alarm.dateTime.day == alarmSettings.dateTime.day &&
alarm.dateTime.hour == alarmSettings.dateTime.hour &&
alarm.dateTime.minute == alarmSettings.dateTime.minute)) {
alarm.dateTime.isSameSecond(alarmSettings.dateTime)) {
await Alarm.stop(alarm.id);
}
}
Expand Down Expand Up @@ -172,3 +170,13 @@ class AlarmException implements Exception {
@override
String toString() => message;
}

extension DateTimeExtension on DateTime {
bool isSameSecond(DateTime other) =>
year == other.year &&
month == other.month &&
day == other.day &&
hour == other.hour &&
minute == other.minute &&
second == other.second;
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: alarm
description: A simple Flutter alarm manager plugin for both iOS and Android.
version: 3.0.0
version: 3.0.1
homepage: https://github.com/gdelataillade/alarm

environment:
Expand Down

0 comments on commit d701f78

Please sign in to comment.