Skip to content

Commit

Permalink
docs(booking_collection): document tested methods
Browse files Browse the repository at this point in the history
  • Loading branch information
albertms10 committed Feb 26, 2023
1 parent 691bfba commit 7997561
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions lib/src/model/booking_collection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,30 @@ class BookingCollection with ChangeNotifier implements Serializable {
null;
}

/// Returns the occupied [Duration] in a [dateRanger].
///
/// Example:
/// ```dart
/// final bookingCollection = BookingCollection(
/// bookings: {
/// SingleBooking(
/// startDate: DateTime.utc(2022, 12, 4, 9),
/// endDate: DateTime.utc(2022, 12, 4, 9, 30),
/// ),
/// },
/// recurringBookings: {
/// RecurringBooking(
/// startDate: DateTime.utc(2022, 12, 4, 9, 30),
/// endDate: DateTime.utc(2022, 12, 4, 10, 30),
/// recurringEndDate: DateTime.utc(2023, 2, 4),
/// ),
/// },
/// );
/// final occupiedDuration = bookingCollection.occupiedDuration(
/// DateRange.fromDate(DateTime.utc(2022, 12, 4)),
/// );
/// assert(occupiedDuration == const Duration(hours: 1, minutes: 30));
/// ```
Duration occupiedDuration([DateRanger dateRanger = DateRange.infinite]) {
var runDuration = Duration.zero;
for (final booking in allBookings) {
Expand All @@ -123,6 +147,30 @@ class BookingCollection with ChangeNotifier implements Serializable {
return runDuration;
}

/// Returns the occupancy percent in a [dateRanger].
///
/// Example:
/// ```dart
/// final bookingCollection = BookingCollection(
/// bookings: {
/// SingleBooking(
/// startDate: DateTime.utc(2022, 12, 4, 9),
/// endDate: DateTime.utc(2022, 12, 4, 9, 30),
/// ),
/// },
/// recurringBookings: {
/// RecurringBooking(
/// startDate: DateTime.utc(2022, 12, 4, 9, 30),
/// endDate: DateTime.utc(2022, 12, 4, 10),
/// recurringEndDate: DateTime.utc(2023, 2, 4),
/// ),
/// },
/// );
/// final occupancyPercent = bookingCollection.occupancyPercentOn(
/// DateRange.fromDate(DateTime.utc(2022, 12, 4)),
/// );
/// assert(occupancyPercent == 0.0625); // 6.25%
/// ```
double occupancyPercentOn([DateRanger? dateRanger]) {
dateRanger ??= DateRange.today();

Expand Down

0 comments on commit 7997561

Please sign in to comment.