startOf method

DateTime startOf(
  1. DurationUnit unit
)

Returned object will have same timezone as this

Notes:

  • instance.startOf(DurationUnit.week) will throw MomentException

  • instance.startOf(DurationUnit.microsecond) will return clone of that instance

Implementation

DateTime startOf(DurationUnit unit) {
  switch (unit) {
    case DurationUnit.microsecond:
      return clone();
    case DurationUnit.week:
      throw MomentException(
          "endOf(DurationUnit.week) is not supported on DateTime. You can use Moment(...).startOf(DurationUnit.week)");
    case DurationUnit.millisecond:
      return DateTimeConstructors.withTimezone(
        isUtc,
        year,
        month,
        day,
        hour,
        minute,
        second,
        millisecond,
      );
    case DurationUnit.second:
      return DateTimeConstructors.withTimezone(
        isUtc,
        year,
        month,
        day,
        hour,
        minute,
        second,
      );
    case DurationUnit.minute:
      return DateTimeConstructors.withTimezone(
        isUtc,
        year,
        month,
        day,
        hour,
        minute,
      );
    case DurationUnit.hour:
      return DateTimeConstructors.withTimezone(
        isUtc,
        year,
        month,
        day,
        hour,
      );
    case DurationUnit.day:
      return DateTimeConstructors.withTimezone(
        isUtc,
        year,
        month,
        day,
      );
    case DurationUnit.month:
      return DateTimeConstructors.withTimezone(
        isUtc,
        year,
        month,
      );
    case DurationUnit.year:
      return DateTimeConstructors.withTimezone(
        isUtc,
        year,
      );
  }
}