You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by ka...@apache.org on 2022/05/25 08:37:03 UTC

[james-project] 03/04: JAMES-3758 MessageSearches should respect zone offset on date-time values

This is an automated email from the ASF dual-hosted git repository.

kao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 31216153846b588954883037a64416be9f164f72
Author: Karsten Otto <ka...@akquinet.de>
AuthorDate: Tue May 17 15:34:18 2022 +0200

    JAMES-3758 MessageSearches should respect zone offset on date-time values
---
 .../org/apache/james/mailbox/store/search/MessageSearches.java     | 7 ++++++-
 .../org/apache/james/mailbox/store/search/SearchUtilsTest.java     | 6 +++---
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
index 879f992516..23026dad31 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
@@ -533,9 +533,10 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
     private Date toISODate(String value) throws ParseException {
         StringReader reader = new StringReader(value);
         DateTime dateTime = new DateTimeParser(reader).parseAll();
-        Calendar cal = getGMT();
+        Calendar cal = getGMT(dateTime.getTimeZone());
         cal.set(dateTime.getYear(), dateTime.getMonth() - 1, dateTime.getDay(), dateTime.getHour(),
                 dateTime.getMinute(), dateTime.getSecond());
+        cal.set(Calendar.MILLISECOND, 0);
         return cal.getTime();
     }
 
@@ -655,4 +656,8 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
         return Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.ENGLISH);
     }
 
+    private Calendar getGMT(int timeZone) {
+        return Calendar.getInstance(TimeZone.getTimeZone(String.format("GMT%+04d", timeZone)), Locale.ENGLISH);
+    }
+
 }
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/SearchUtilsTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/SearchUtilsTest.java
index 5d1bb0f446..ace890bcc5 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/SearchUtilsTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/SearchUtilsTest.java
@@ -761,7 +761,7 @@ class SearchUtilsTest {
     
     @Test
     void testMatchHeaderDateOnWithOffset() throws Exception {
-        builder.header(DATE_FIELD, "Mon, 26 Mar 2007 00:00:00 +0300");
+        builder.header(DATE_FIELD, "Mon, 26 Mar 2007 03:00:00 +0300");
         MailboxMessage row = builder.build();
         assertThat(messageSearches.isMatch(SearchQuery.headerDateOn(DATE_FIELD, getDate(26, 3,
                 2007), DateResolution.Day),row, recent)).isTrue();
@@ -775,7 +775,7 @@ class SearchUtilsTest {
 
     @Test
     void testShouldMatchHeaderDateBeforeWithOffset() throws Exception {
-        builder.header(DATE_FIELD, "Mon, 26 Mar 2007 00:00:00 +0300");
+        builder.header(DATE_FIELD, "Mon, 26 Mar 2007 03:00:00 +0300");
         MailboxMessage row = builder.build();
         assertThat(messageSearches.isMatch(SearchQuery.headerDateBefore(DATE_FIELD, getDate(26, 3,
                 2007), DateResolution.Day),row, recent)).isFalse();
@@ -788,7 +788,7 @@ class SearchUtilsTest {
 
     @Test
     void testShouldMatchHeaderDateAfterWithOffset() throws Exception {
-        builder.header(DATE_FIELD, "Mon, 26 Mar 2007 00:00:00 +0300");
+        builder.header(DATE_FIELD, "Mon, 26 Mar 2007 03:00:00 +0300");
         MailboxMessage row = builder.build();
         assertThat(messageSearches.isMatch(SearchQuery.headerDateAfter(DATE_FIELD, getDate(26, 3,
                 2007), DateResolution.Day),row, recent)).isFalse();


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org