calcValueByDateTime static method

TimeValue calcValueByDateTime({
  1. required String fromDateTime,
  2. required String toDateTime,
  3. String format = Format.fyyyyMMddHHmmss,
})

calculate time value by from date to to date

Implementation

static TimeValue calcValueByDateTime(
    {required String fromDateTime,
    required String toDateTime,
    String format = Format.fyyyyMMddHHmmss}) {
  TimeValue timeValue = TimeValue();
  try {
    if (validDateTimeRange(
        fromDateTime: fromDateTime, toDateTime: toDateTime, format: format)) {
      Duration duration = stringToDateTime(date: toDateTime, format: format)
          .difference(stringToDateTime(date: fromDateTime, format: format));

      timeValue.inSeconds = duration.inSeconds;
      timeValue.inMinutes = duration.inMinutes;
      timeValue.inHours = duration.inHours;
      timeValue.inDays = duration.inDays;

      timeValue.seconds = duration.inSeconds % 60;
      timeValue.minutes = duration.inMinutes % 60;
      timeValue.hours = duration.inHours % 24;
      timeValue.days = duration.inDays;
    }
  } catch (_) {}
  return timeValue;
}