Skip to content

Commit

Permalink
Make start and end optional (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
njooma authored Jul 18, 2023
1 parent bc54f58 commit 4d209d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 11 additions & 6 deletions lib/src/app/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,19 @@ class DataClient {
}

extension FilterUtils on Filter {
Filter withDateTimeCaptureInterval(DateTime start, DateTime end) {
setDateTimeCaptureInterval(start, end);
Filter withDateTimeCaptureInterval({DateTime? start, DateTime? end}) {
setDateTimeCaptureInterval(start: start, end: end);
return this;
}

void setDateTimeCaptureInterval(DateTime start, DateTime end) {
interval = CaptureInterval()
..start = (Timestamp()..seconds = Int64((start.millisecondsSinceEpoch / 1000).floor()))
..end = (Timestamp()..seconds = Int64((end.millisecondsSinceEpoch / 1000).floor()));
void setDateTimeCaptureInterval({DateTime? start, DateTime? end}) {
final interval = CaptureInterval();
if (start != null) {
interval.start = Timestamp()..seconds = Int64((start.millisecondsSinceEpoch / 1000).floor());
}
if (end != null) {
interval.end = Timestamp()..seconds = Int64((end.millisecondsSinceEpoch / 1000).floor());
}
this.interval = interval;
}
}
4 changes: 2 additions & 2 deletions test/unit_test/app/data_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void main() {

final start = DateTime(2020, 12, 31);
final end = DateTime(2021, 12, 31);
filter.setDateTimeCaptureInterval(start, end);
filter.setDateTimeCaptureInterval(start: start, end: end);
expect(filter.interval.start.seconds.toInt(), equals(start.millisecondsSinceEpoch / 1000));
expect(filter.interval.end.seconds.toInt(), equals(end.millisecondsSinceEpoch / 1000));
});
Expand All @@ -111,7 +111,7 @@ void main() {

final start = DateTime(2020, 12, 31);
final end = DateTime(2021, 12, 31);
filter = filter.withDateTimeCaptureInterval(start, end);
filter = filter.withDateTimeCaptureInterval(start: start, end: end);
expect(filter.interval.start.seconds.toInt(), equals(start.millisecondsSinceEpoch / 1000));
expect(filter.interval.end.seconds.toInt(), equals(end.millisecondsSinceEpoch / 1000));
});
Expand Down

0 comments on commit 4d209d7

Please sign in to comment.