mirror of
https://github.com/Iconica-Development/flutter_availability.git
synced 2025-05-19 05:03:44 +02:00
feat: add validation check for break outside availability
This commit is contained in:
parent
c004417b36
commit
c7ce06624b
4 changed files with 20 additions and 1 deletions
|
@ -13,6 +13,11 @@ enum AvailabilityError {
|
||||||
"and end time",
|
"and end time",
|
||||||
),
|
),
|
||||||
|
|
||||||
|
/// Error identifier for when a break is outside the availability time
|
||||||
|
breakOutsideAvailabilityTime(
|
||||||
|
"The break is outside the availability time",
|
||||||
|
),
|
||||||
|
|
||||||
/// Error identifier for when the end of the day is before the start
|
/// Error identifier for when the end of the day is before the start
|
||||||
endBeforeStart("The end of the day is before the start"),
|
endBeforeStart("The end of the day is before the start"),
|
||||||
|
|
||||||
|
|
|
@ -99,6 +99,8 @@ class _AvailabilitiesModificationScreenState
|
||||||
error = AvailabilityError.breakEndBeforeStart;
|
error = AvailabilityError.breakEndBeforeStart;
|
||||||
} on BreakSubmittedDurationTooLongException {
|
} on BreakSubmittedDurationTooLongException {
|
||||||
error = AvailabilityError.breakSubmittedDurationTooLong;
|
error = AvailabilityError.breakSubmittedDurationTooLong;
|
||||||
|
} on BreakOutsideAvailabilityTimeException {
|
||||||
|
error = AvailabilityError.breakOutsideAvailabilityTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error != null && context.mounted) {
|
if (error != null && context.mounted) {
|
||||||
|
|
|
@ -8,6 +8,9 @@ class BreakEndBeforeStartException implements Exception {}
|
||||||
/// between the start and end time
|
/// between the start and end time
|
||||||
class BreakSubmittedDurationTooLongException implements Exception {}
|
class BreakSubmittedDurationTooLongException implements Exception {}
|
||||||
|
|
||||||
|
/// Exception thrown when a break is outside the availability time
|
||||||
|
class BreakOutsideAvailabilityTimeException implements Exception {}
|
||||||
|
|
||||||
/// Exception thrown when the end is before the start
|
/// Exception thrown when the end is before the start
|
||||||
class AvailabilityEndBeforeStartException implements Exception {}
|
class AvailabilityEndBeforeStartException implements Exception {}
|
||||||
|
|
||||||
|
@ -100,6 +103,12 @@ class AvailabilityModel {
|
||||||
|
|
||||||
for (var breakData in breaks) {
|
for (var breakData in breaks) {
|
||||||
breakData.validate();
|
breakData.validate();
|
||||||
|
var breakStart = breakData.startTime.time;
|
||||||
|
var breakEnd = breakData.endTime.time;
|
||||||
|
if (breakStart.isBefore(startDate.time) ||
|
||||||
|
breakEnd.isAfter(endDate.time)) {
|
||||||
|
throw BreakOutsideAvailabilityTimeException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,7 +210,7 @@ class AvailabilityBreakModel {
|
||||||
|
|
||||||
/// Verify the validity of this break
|
/// Verify the validity of this break
|
||||||
void validate() {
|
void validate() {
|
||||||
if (endTime.compareTo(startTime) < 0) {
|
if (!startTime.isBefore(endTime)) {
|
||||||
throw BreakEndBeforeStartException();
|
throw BreakEndBeforeStartException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,9 @@ extension DateUtils on DateTime {
|
||||||
/// Gets the date without the time
|
/// Gets the date without the time
|
||||||
DateTime get date => DateTime(year, month, day);
|
DateTime get date => DateTime(year, month, day);
|
||||||
|
|
||||||
|
/// Gets the time without the date
|
||||||
|
DateTime get time => DateTime(0, 0, 0, hour, minute);
|
||||||
|
|
||||||
/// Returns true if the time of the date matches the time of the other date
|
/// Returns true if the time of the date matches the time of the other date
|
||||||
bool timeMatches(DateTime other) =>
|
bool timeMatches(DateTime other) =>
|
||||||
other.hour == hour && other.minute == minute;
|
other.hour == hour && other.minute == minute;
|
||||||
|
|
Loading…
Reference in a new issue