timeSpanToTimeSince function

DateTime? timeSpanToTimeSince(
  1. TrendTimeArg timeSpan,
  2. DateTime currentTime
)

Converts a time span argument and current time into a time since argument into an Energy management API time since parameter.

Implementation

DateTime? timeSpanToTimeSince(TrendTimeArg timeSpan, DateTime currentTime) {
  switch (timeSpan) {
    case TrendTimeArg.last14Days:
      return currentTime.subtract(const Duration(days: 14)).toUtc();
    case TrendTimeArg.last30days:
      return currentTime.subtract(const Duration(days: 30)).toUtc();
    case TrendTimeArg.last2months:
      return currentTime.subtract(const Duration(days: 30 * 2)).toUtc();
    case TrendTimeArg.last3months:
      return currentTime.subtract(const Duration(days: 30 * 3)).toUtc();
    case TrendTimeArg.last4months:
      return currentTime.subtract(const Duration(days: 30 * 4)).toUtc();
    case TrendTimeArg.last6months:
      return currentTime.subtract(const Duration(days: 30 * 6)).toUtc();
    case TrendTimeArg.lastYear:
      return currentTime.subtract(const Duration(days: 30 * 12)).toUtc();
    case TrendTimeArg.all:
      return null;
  }
}