dividerToServerTime method

FromToDate dividerToServerTime()

Implementation

FromToDate dividerToServerTime() {
  var divider = this;
  var fromDate = FromToDate(from: '', to: '');
  var currentDate = DateTime.now();
  if (divider == "day") {
    fromDate = fromDate.copyWith(
        from: DateTime.utc(currentDate.year, currentDate.month, currentDate.day, 0)
            .toIso8601String());
  }
  if (divider == "week") {
    fromDate = fromDate.copyWith(
        from: currentDate
            .subtract(Duration(
                days: currentDate.weekday - 1,
                hours: currentDate.hour,
                minutes: currentDate.minute,
                seconds: currentDate.second))
            .toIso8601String());
  }
  if (divider == "month") {
    fromDate = fromDate.copyWith(
        from: DateTime.utc(currentDate.year, currentDate.month, 0).toIso8601String());
  }
  if (divider == "year") {
    fromDate = fromDate.copyWith(from: DateTime.utc(currentDate.year, 0, 0).toIso8601String());
  }
  if (divider == "quarter") {
    fromDate = fromDate.copyWith(
        from: DateTime.utc(currentDate.year, currentDate.month - 2, 0).toIso8601String());
  }
  fromDate = fromDate.copyWith(to: currentDate.toIso8601String());

  return fromDate;
}