Przeglądaj źródła

新增判断指定日期是否在当前时间周期内方法

woody 2 lat temu
rodzic
commit
7d354c38d6

+ 11 - 0
framework-base/src/main/java/com/chelvc/framework/base/model/Period.java

@@ -458,6 +458,17 @@ public final class Period implements Serializable {
         return Duration.ofMillis((begin + offset * 1000) - System.currentTimeMillis());
     }
 
+    /**
+     * 判断指定日期是否包含在当前时间周期内
+     *
+     * @param date 日期对象
+     * @return true/false
+     */
+    public boolean contains(Date date) {
+        return date != null && this.begin != null && this.end != null
+                && !this.begin.after(date) && !this.end.before(date);
+    }
+
     /**
      * 时间周期偏移
      *