getCoverValidityPeriod function
getCoverValidityPeriod gets the validity period of a cover
pass in a valid validTo string and it returns a validity period in human readable form
Implementation
String getCoverValidityPeriod(String validTo) {
final Duration validityDuration =
DateTime.parse(validTo).difference(DateTime.now());
final String remainingMonths =
(validityDuration.inDays / 30).floor().toString();
final String remainingDays =
(validityDuration.inDays % 30).floor().toString();
if (validityDuration < const Duration(hours: 1)) {
return 'Your cover has expired. It was valid';
}
return 'Valid for the next $remainingMonths months and $remainingDays days';
}