LocalTime.sinceMidnight constructor

LocalTime.sinceMidnight(
  1. Time time
)

Factory method for creating a local time from the number of ticks which have elapsed since midnight.

Returns: The resulting LocalTime.

Implementation

factory LocalTime.sinceMidnight(Time time) {
  var nanoseconds = time.inNanoseconds;
  // Avoid the method calls which give a decent exception unless we're actually going to fail.
  if (nanoseconds < 0 || nanoseconds >= TimeConstants.nanosecondsPerDay) {
    // Range error requires 'num' to be the range bounds, which isn't conceptually true here.
    // todo: is there a way to make this a Range error?
    throw ArgumentError.value('Invalid value: $time was out of range of [${Time.zero}, ${Time.oneDay}).');
  }
  return LocalTime._(nanoseconds);
}