From e2731bbe2cda1cdaadf43f8ca7657731e2153bd0 Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 10 Jun 2021 15:37:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=A4=E6=96=AD=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=90=8C=E4=B8=80=E5=A4=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/synebula/gaea/data/date/DateTime.kt | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/data/date/DateTime.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/data/date/DateTime.kt index 03a0eab..9b8916f 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/data/date/DateTime.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/data/date/DateTime.kt @@ -272,9 +272,9 @@ class DateTime() : Comparable { * 比较当前时间是否在目标时间范围内。 * @param start 目标开始时间。 * @param end 目标结束时间。 - * @return 是否。 + * @return true or false */ - fun between(start: DateTime, end: DateTime): Boolean { + fun isBetween(start: DateTime, end: DateTime): Boolean { //return this in start..end return start.dateNoTime.compareTo(this.dateNoTime) * this.dateNoTime.compareTo(end.dateNoTime) >= 0 } @@ -284,9 +284,9 @@ class DateTime() : Comparable { * @param start 目标开始时间。 * @param end 目标结束时间。 * @param level 比较时间的最小级别。 - * @return 是否。 + * @return true or false */ - fun between(start: DateTime, end: DateTime, level: TimeUnit): Boolean { + fun isBetween(start: DateTime, end: DateTime, level: TimeUnit): Boolean { return this.compareTo(start, level) >= 0 && this.compareTo(end, level) <= 0 } @@ -295,9 +295,9 @@ class DateTime() : Comparable { * 判断当前时间是否在某时间后 * * @param other 另一时间 - * @return new DateTime object + * @return true or false */ - fun after(other: DateTime): Boolean { + fun isAfter(other: DateTime): Boolean { return this.date.after(other.date) } @@ -305,12 +305,24 @@ class DateTime() : Comparable { * 判断当前时间是否在某时间前 * * @param other 另一时间 - * @return new DateTime object + * @return true or false */ - fun before(other: DateTime): Boolean { + fun isBefore(other: DateTime): Boolean { return this.date.before(other.date) } + /** + * 判断当前时间是否同一天 + * + * @param other 另一时间 + * @return true or false + */ + fun isSameDay(other: DateTime): Boolean { + return this.calendar.get(Calendar.ERA) == other.calendar.get(Calendar.ERA) + && this.calendar.get(Calendar.YEAR) == other.calendar.get(Calendar.YEAR) + && this.calendar.get(Calendar.DAY_OF_YEAR) == other.calendar.get(Calendar.DAY_OF_YEAR) + } + /** * 加减年。