0 purchases
time overlapping
time_overlapping #
TimeOverlapping package is a lightweight and blazing fast for checking the time overlapping in the given DateTime ranges.
Getting Started #
This package accepts only List<OverlapParams>
OverlapParams
This requires an uniqueId, DateTimeRange & dynamic data*.
dynamic data is type dynamic which accepts any sort of data.
It will throw AssertionError if it founds any duplicate Ids.
OverlapParams('uniqueId', DateTimeRange(start, end), {}),
copied to clipboard
There are 3 type of functions to find overlapping.
findOverlap - returns the List<String> ie.., list of overlapping Ids.
findOverlapWithData - returns the List<OverlapParams> which has DateTimeRange overlap.
hasOverlap - to find timeOverlap for only 2 dateTimeRange. - returns bool.
Usage #
findOverlap #
void main() {
final range1 = DateTimeRange(
start: DateTime.now(),
end: DateTime.now().add(const Duration(hours: 2)),
);
final range2 = DateTimeRange(
start: DateTime.now(),
end: DateTime.now().add(const Duration(hours: 1)),
);
final range3 = DateTimeRange(
start: DateTime.now().add(const Duration(hours: 2)),
end: DateTime.now().add(const Duration(hours: 3)),
);
final range4 = DateTimeRange(
start: DateTime.now().add(const Duration(hours: 3)),
end: DateTime.now().add(const Duration(hours: 4)),
);
final overlapParams = [
OverlapParams('001', range1, {}),
OverlapParams('002', range2, {}),
OverlapParams('003', range3, {}),
OverlapParams('004', range4, {}),
];
print(TimeOverlapFinder.findOverlap(overlapParams));
}
copied to clipboard
Output
['001', '002']
copied to clipboard
findOverlapWithData #
void main() {
final range1 = DateTimeRange(
start: DateTime.now(),
end: DateTime.now().add(const Duration(hours: 2)),
);
final range2 = DateTimeRange(
start: DateTime.now(),
end: DateTime.now().add(const Duration(hours: 1)),
);
final range3 = DateTimeRange(
start: DateTime.now().add(const Duration(hours: 2)),
end: DateTime.now().add(const Duration(hours: 3)),
);
final range4 = DateTimeRange(
start: DateTime.now().add(const Duration(hours: 3)),
end: DateTime.now().add(const Duration(hours: 4)),
);
final overlapParams = [
OverlapParams('001', range1, {}),
OverlapParams('002', range2, {}),
OverlapParams('003', range3, {}),
OverlapParams('004', range4, {}),
];
print(TimeOverlapFinder.findOverlapWithData(overlapParams));
}
copied to clipboard
Output
[
OverlapParams(001, 2021-08-12 07:36:07.095 - 2021-08-12 09:36:07.095, {}),
OverlapParams(002, 2021-08-12 07:36:07.095 - 2021-08-12 08:36:07.095, {})
]
copied to clipboard
hasOverlap #
void main() {
final range1 = DateTimeRange(
start: DateTime.now(),
end: DateTime.now().add(const Duration(hours: 2)),
);
final range2 = DateTimeRange(
start: DateTime.now(),
end: DateTime.now().add(const Duration(hours: 1)),
);
final overlapParams = [
OverlapParams('001', range1, {}),
OverlapParams('002', range2, {}),
];
print(TimeOverlapFinder.hasOverlap(range1, range2));
}
copied to clipboard
Output
true
copied to clipboard
Some useful extensions
1. range1.isBefore(range2),
2. range1.isAfter(range2),
copied to clipboard
1. range1.isCrossing(range2),
2. range1.isCrossingStart(range2),
3. range1.isCrossingEnd(range2),
copied to clipboard
Thanks for using my package 🙏 #
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.