isWeek static method

bool isWeek(
  1. int? ms, {
  2. bool isUtc = false,
  3. int? locMs,
})

is Week. 是否是本周.

Implementation

static bool isWeek(int? ms, {bool isUtc = false, int? locMs}) {
  if (ms == null || ms <= 0) {
    return false;
  }
  DateTime old0 = DateTime.fromMillisecondsSinceEpoch(ms, isUtc: isUtc);
  DateTime now0;
  if (locMs != null) {
    now0 = DateUtil.getDateTimeByMs(locMs, isUtc: isUtc);
  } else {
    now0 = isUtc ? DateTime.now().toUtc() : DateTime.now().toLocal();
  }

  DateTime old =
      now0.millisecondsSinceEpoch > old0.millisecondsSinceEpoch ? old0 : now0;
  DateTime now =
      now0.millisecondsSinceEpoch > old0.millisecondsSinceEpoch ? now0 : old0;
  return (now.weekday >= old.weekday) &&
      (now.millisecondsSinceEpoch - old.millisecondsSinceEpoch <=
          7 * 24 * 60 * 60 * 1000);
}