Fix message banner to not appear immediately after dismissal

The redisplay format "Aug 29, 2023, 12:00:00 AM" is not
supported by the document.cookie expires field [1], where it was
ignoring AM and PM. The expires field expects a GMT format such as
"Wed, 14 Jun 2017 07:00:00 GMT". Even though we fix this issue by
making the REST API send the right format, we have another issue
with timezones.

Let's say client is in IST timezone and current GMT time is
"27 Aug 2023 23:30:00" and equivalent IST is "28 Aug 2023 05:00:00".
So the redisplay from the REST API is "28 Aug 2023 00:00:00", which
translates to "28 Aug 2023 05:30:00" in IST. Which means the user will
see the message banner in next 30mins after its dismissal. Ideally the
banner must be redisplayed next day of the client, i.e.
"29 Aug 2023 00:00:00".

It is not the best approach to determine the redisplay time for banner
on server side, as the API has no clue about the client's next day.
Rather calculate the next day for redisplay on client itself, which
sets the correct time for redisplay.

[1] https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie#write_a_new_cookie

Change-Id: Ic24b758a6f0d807c0fa6a2ed3f9bda125fa31c60
diff --git a/gr-messageoftheday/gr-messageoftheday-banner.js b/gr-messageoftheday/gr-messageoftheday-banner.js
index eb938c5..9d7c839 100644
--- a/gr-messageoftheday/gr-messageoftheday-banner.js
+++ b/gr-messageoftheday/gr-messageoftheday-banner.js
@@ -52,13 +52,23 @@
 
   _handleDismissMessage() {
     document.cookie =
-      `msg-${this._message.id}=1; path=/; expires=${this._message.redisplay}`;
+      `msg-${this._message.id}=1; path=/; expires=${this._getExpires()}`;
     this._hidden = true;
   }
 
   _isHidden() {
     this._hidden = document.cookie.search(`msg-${this._message.id}=`) > -1;
   }
+
+  _getExpires() {
+    var date = new Date();
+    date.setHours(0);
+    date.setMinutes(0);
+    date.setSeconds(0);
+    date.setMilliseconds(0);
+    date.setDate(date.getDate() + 1);
+    return date.toUTCString();
+  }
 }
 
 customElements.define(GrMessageOfTheDayBanner.is, GrMessageOfTheDayBanner);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/GetMessage.java b/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/GetMessage.java
index 95bfe2b..b90d4a7 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/GetMessage.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/GetMessage.java
@@ -30,9 +30,7 @@
 import java.nio.file.Path;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.Calendar;
 import java.util.Date;
-import java.util.TimeZone;
 import org.eclipse.jgit.errors.ConfigInvalidException;
 import org.eclipse.jgit.storage.file.FileBasedConfig;
 import org.eclipse.jgit.util.FS;
@@ -105,18 +103,6 @@
       return Response.none();
     }
 
-    motd.redisplay = getRedisplay();
-
     return Response.ok(motd);
   }
-
-  private Date getRedisplay() {
-    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
-    cal.set(Calendar.HOUR_OF_DAY, 0);
-    cal.set(Calendar.MINUTE, 0);
-    cal.set(Calendar.SECOND, 0);
-    cal.set(Calendar.MILLISECOND, 0);
-    cal.add(Calendar.DAY_OF_MONTH, 1);
-    return cal.getTime();
-  }
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/MessageOfTheDayInfo.java b/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/MessageOfTheDayInfo.java
index eed52ce..e17127c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/MessageOfTheDayInfo.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/MessageOfTheDayInfo.java
@@ -24,8 +24,6 @@
   public Date startsAt;
   /** The time from which on the message will not be displayed anymore. */
   public Date expiresAt;
-  /** The date and time the message will be displayed again after being dismissed by the user. */
-  public Date redisplay;
   /** The message in HTML-format. */
   public String html;
 }
diff --git a/src/main/resources/Documentation/about.md b/src/main/resources/Documentation/about.md
index f27bc86..26cc63d 100644
--- a/src/main/resources/Documentation/about.md
+++ b/src/main/resources/Documentation/about.md
@@ -1,3 +1,8 @@
 This plugin provides message of the day to be displayed in Gerrit UI.
 
 The plugin makes use of Gerrit's MessageOfTheDay extension point.
+
+The plugin will display the configured message at the top of the screen.
+The user can dismiss the message banner. Upon dismissal, the banner will be
+redisplayed on the web UI the next day at 00:00. (The next day is calculated
+with respect to the client)
diff --git a/src/main/resources/Documentation/rest-api-config.md b/src/main/resources/Documentation/rest-api-config.md
index 86d923c..84ed041 100644
--- a/src/main/resources/Documentation/rest-api-config.md
+++ b/src/main/resources/Documentation/rest-api-config.md
@@ -36,7 +36,6 @@
     "id": "hello",
     "starts_at": "Feb 4, 2020 5:53:00 PM",
     "expires_at": "Dec 30, 2020 6:00:00 PM",
-    "redisplay": "Feb 5, 2020 1:00:00 AM",
     "html": "hello you!"
   }
 ```
@@ -48,7 +47,6 @@
 * `id`: ID of the message.
 * `starts_at`: Date, when the message will be first displayed
 * `expires_at`: Date, after which the message will not be displayed anymore
-* `redisplay`: Date, after which will the message be displayed again after dismissal
 * `html`: String, containing the HTML-formatted message