convertSecondsMinutesToHours static method

String convertSecondsMinutesToHours(
  1. String value,
  2. double dNumber
)

Convert seconds into minute and minutes into hour.

Implementation

static String convertSecondsMinutesToHours(String value, double dNumber) {
  bool isDateValue = false;
  if ((dNumber % 1) == 0) {
    isDateValue = true;
  }
  final CultureInfo currentCulture = CultureInfo.currentCulture;
  if (!isDateValue &&
      (dNumber > -657435.0) &&
      (dNumber < 2958465.99999999) &&
      Range.fromOADate(dNumber).millisecond >
          SecondToken.defaultMilliSecondHalf) {
    final String decimalSeparator =
        currentCulture.numberFormat.numberDecimalSeparator;
    final RegExp regex = RegExp(
        '([0-9]*:[0-9]*:[0-9]*"$decimalSeparator[0-9]*|[0-9]*:[0-9]*:[0-9]*|[0-9]*:[0-9]*"$decimalSeparator[0-9]*|[0-9]*:[0-9]*)');
    final List<RegExpMatch> matches = regex.allMatches(value).toList();
    for (final Match match in matches) {
      final String semiColon = currentCulture.dateTimeFormat.timeSeparator;
      const String valueFormat = SecondToken.defaultFormatLong;
      final List<String> timeValues =
          match.pattern.toString().split(semiColon);
      final int minutesValue = Range.fromOADate(dNumber).minute;
      String updatedValue = timeValues[0];
      int updateMinutesValue = 0;
      switch (timeValues.length) {
        case 2:
          updateMinutesValue = minutesValue + 1;
          if (updateMinutesValue == 60) {
            updatedValue = (int.parse(timeValues[0]) + 1).toString();
            // .toString(valueFormat);
            updatedValue = updatedValue +
                semiColon +
                timeValues[timeValues.length - 1].replaceAll(
                    timeValues[timeValues.length - 1], valueFormat);
            value = value.replaceAll(match.pattern.toString(), updatedValue);
          }
          break;
        case 3:
          final int secondsValue = Range.fromOADate(dNumber).second;
          final int updatedSecondsValue = secondsValue +
              (timeValues[timeValues.length - 1].contains(decimalSeparator)
                  ? 0
                  : 1);
          if (updatedSecondsValue == 60) {
            updateMinutesValue = minutesValue + 1;
            if (updateMinutesValue == 60) {
              updatedValue = (int.parse(timeValues[0]) + 1).toString();
              // .toString(valueFormat);
              updatedValue = updatedValue +
                  semiColon +
                  valueFormat +
                  semiColon +
                  timeValues[timeValues.length - 1]
                      .replaceAll(secondsValue.toString(), valueFormat);
            } else {
              updatedValue = timeValues[0] +
                  semiColon +
                  updateMinutesValue.toString() +
                  // .toString(valueFormat)
                  semiColon +
                  timeValues[timeValues.length - 1]
                      .replaceAll(secondsValue.toString(), valueFormat);
            }
          } else {
            updatedValue = timeValues[0] +
                semiColon +
                timeValues[1] +
                semiColon +
                timeValues[timeValues.length - 1].replaceAll(
                    secondsValue.toString(), updatedSecondsValue.toString());
          }
          value = value.replaceAll(match.pattern.toString(), updatedValue);
          break;
      }
    }
  }
  return value;
}