You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2016/04/06 11:21:52 UTC
[08/18] james-project git commit: MAILBOX-266 ZonedDateTime does not
support truncate using Month and Year units
MAILBOX-266 ZonedDateTime does not support truncate using Month and Year units
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/b446bffd
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/b446bffd
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/b446bffd
Branch: refs/heads/master
Commit: b446bffdc630da8eedc75fc010c0891758c4f94c
Parents: 0ea8bc6
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Mar 28 14:07:55 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Apr 6 16:18:45 2016 +0700
----------------------------------------------------------------------
.../query/DateResolutionFormater.java | 11 +++++++++--
.../query/DateResolutionFormaterTest.java | 18 ++++++++++++++++++
2 files changed, 27 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/b446bffd/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormater.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormater.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormater.java
index 30574f3..70746b5 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormater.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormater.java
@@ -34,11 +34,18 @@ public class DateResolutionFormater {
public static DateTimeFormatter DATE_TIME_FOMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
public static ZonedDateTime computeUpperDate(ZonedDateTime date, SearchQuery.DateResolution resolution) {
- return date.truncatedTo(convertDateResolutionField(resolution)).plus(1,convertDateResolutionField(resolution));
+ return computeLowerDate(date, resolution).plus(1, convertDateResolutionField(resolution));
}
public static ZonedDateTime computeLowerDate(ZonedDateTime date, SearchQuery.DateResolution resolution) {
- return date.truncatedTo(convertDateResolutionField(resolution));
+ switch (resolution) {
+ case Year:
+ return date.truncatedTo(ChronoUnit.DAYS).withDayOfYear(1);
+ case Month:
+ return date.truncatedTo(ChronoUnit.DAYS).withDayOfMonth(1);
+ default:
+ return date.truncatedTo(convertDateResolutionField(resolution));
+ }
}
private static TemporalUnit convertDateResolutionField(SearchQuery.DateResolution resolution) {
http://git-wip-us.apache.org/repos/asf/james-project/blob/b446bffd/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormaterTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormaterTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormaterTest.java
index fed35c1..07cbe4f 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormaterTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormaterTest.java
@@ -52,6 +52,24 @@ public class DateResolutionFormaterTest {
}
@Test
+ public void calculateUpperDateShouldReturnDateUpToTheNextMonthUsingMonthUnit() throws ParseException {
+ assertThat(
+ ISO_OFFSET_DATE_TIME.format(
+ DateResolutionFormater.computeUpperDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME), SearchQuery.DateResolution.Month)
+ )
+ ).isEqualTo("2014-02-01T00:00:00Z");
+ }
+
+ @Test
+ public void calculateUpperDateShouldReturnDateUpToTheNextYearUsingYearUnit() throws ParseException {
+ assertThat(
+ ISO_OFFSET_DATE_TIME.format(
+ DateResolutionFormater.computeUpperDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME), SearchQuery.DateResolution.Year)
+ )
+ ).isEqualTo("2015-01-01T00:00:00Z");
+ }
+
+ @Test
public void calculateUpperDateShouldReturnDateUpToTheNextDayUsingDayUnit() throws ParseException {
assertThat(
ISO_OFFSET_DATE_TIME.format(
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org