EllaTime.fromInterval constructor

EllaTime.fromInterval(
  1. String value
)

Expects input in format of hh:mm. Does not support an offset unit greater than hours.

Implementation

factory EllaTime.fromInterval(String value)
{
  bool isNegative = value.codeUnitAt(0) == _NEGATIVE_INTERVAL_PREFIX_CODE_UNIT;
  List<int> segments = value.split(_INTERVAL_SEGMENT_SEPARATOR).map(int.parse).toList();
  if (segments.length != 3) {
    throw new IllegalArgumentException("Wrong number of SQL interval components.");
  }
  int hoursComponent = segments[0].abs();
  int minutesComponent = segments[1].abs();
  int seconds = EllaTime.componentsToSeconds(hoursComponent, minutesComponent, 0);
  if (isNegative) {
    seconds *= -1;
  }
  return new EllaTime(seconds);
}