checkForFileChange method
Check whether to create a new logfile depending on the RotationCycle.
Implementation
Future<void>? checkForFileChange() async {
var now = DateTime.now();
var create = false;
switch (rotationCycle) {
case RotationCycle.NEVER:
return;
case RotationCycle.DAY:
if (now.year > created.year || now.month > created.month) {
create = true;
} else if (now.day > created.day) {
create = true;
}
break;
case RotationCycle.WEEK:
if (now.year > created.year) {
create = true;
} else if (DateUtils.getCalendarWeek(now) >
DateUtils.getCalendarWeek(created)) {
create = true;
}
break;
case RotationCycle.MONTH:
if (now.year > created.year) {
create = true;
} else if (now.month > created.month) {
create = true;
}
break;
case RotationCycle.YEAR:
if (now.year > created.year) {
create = true;
}
break;
}
if (create) {
created = now;
_file = await File(_getFullFilename()).create();
}
return null;
}