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 _old = DateTime.fromMillisecondsSinceEpoch(ms, isUtc: isUtc);
  DateTime _now;
  if (locMs != null) {
    _now = DateUtil.getDateTimeByMs(locMs, isUtc: isUtc);
  } else {
    _now = isUtc ? DateTime.now().toUtc() : DateTime.now().toLocal();
  }

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