Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/manthri-mohan-sai/time_overlapping
TimeOverlapping package is a lightweight and blazing fast for checking the time overlapping in the given DateTime ranges.
https://github.com/manthri-mohan-sai/time_overlapping
Last synced: 4 months ago
JSON representation
TimeOverlapping package is a lightweight and blazing fast for checking the time overlapping in the given DateTime ranges.
- Host: GitHub
- URL: https://github.com/manthri-mohan-sai/time_overlapping
- Owner: manthri-mohan-sai
- License: mit
- Created: 2021-08-12T02:33:49.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-27T11:05:52.000Z (over 1 year ago)
- Last Synced: 2024-05-16T08:12:17.273Z (9 months ago)
- Language: Dart
- Size: 99.6 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-blazingly-fast - time_overlapping - TimeOverlapping package is a lightweight and blazing fast for checking the time overlapping in the given DateTime ranges. (Dart)
README
# time_overlapping
TimeOverlapping package is a lightweight and blazing fast for checking the time overlapping in the given DateTime ranges.
[](https://codecov.io/gh/MohanSaiManthri/time_overlapping)
[](https://github.com/MohanSaiManthri/time_overlapping/actions/workflows/dart.yml)
[](https://pub.dartlang.org/packages/time_overlapping)
[](https://github.com/MohanSaiManthri/time_overlapping/blob/main/LICENSE)## Getting Started
This package accepts only `List`
#### 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.
```dart
OverlapParams('uniqueId', DateTimeRange(start, end), {}),
```There are 3 type of functions to find overlapping.
1. **findOverlap** - returns the `List` ie.., list of overlapping Ids.
2. **findOverlapWithData** - returns the `List` which has DateTimeRange overlap.
3. **hasOverlap** - to find timeOverlap for only 2 dateTimeRange. - returns bool.## Usage
### findOverlap```dart
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));
}
```
##### Output
```dart
['001', '002']
```### findOverlapWithData
```dart
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));
}
```
##### Output
```dart
[
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, {})
]
```### hasOverlap
```dart
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));
}
```##### Output
```dart
true
```#### Some useful extensions
```dart
1. range1.isBefore(range2),
2. range1.isAfter(range2),
``````dart
1. range1.isCrossing(range2),
2. range1.isCrossingStart(range2),
3. range1.isCrossingEnd(range2),
```### Thanks for using my package 🙏