Skip to content

Commit

Permalink
truncate to responseDate to seconds; fixes #20685
Browse files Browse the repository at this point in the history
  • Loading branch information
Keelhaul committed May 11, 2021
1 parent f0d7ac3 commit dd3bbef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Expand Up @@ -72,7 +72,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse res) throws Se

Element responseDate = new Element("responseDate", xmlns);

responseDate.setText(Utils.getCurrentUTCTime(LocalDateTime.now(), 0));
responseDate.setText(Utils.getCurrentUTCTime(LocalDateTime.now()));
root.addContent(responseDate);

RequestHandler handler = new RequestHandler(request);
Expand Down
Expand Up @@ -84,16 +84,16 @@ public class Utils {
* insert some chars in the time string
*
* @param ldt LocalDateTime to use
* @param milliSecondsAdd milliseconds to add to the current utc time if milliSecondsAdd = 0, no milli are added
* @should format time correctly
* @return the time in the format YYYY-MM-DDThh:mm:ssZ
* @should format time correctly
* @should truncate to seconds
*/
public static String getCurrentUTCTime(LocalDateTime ldt, long milliSecondsAdd) {
public static String getCurrentUTCTime(LocalDateTime ldt) {
if (ldt == null) {
throw new IllegalArgumentException("ldt may not be null");
}
return ldt.atOffset(ZoneOffset.UTC)
.plus(milliSecondsAdd, ChronoUnit.MILLIS)
.truncatedTo(ChronoUnit.SECONDS)
.format(formatterISO8601DateTimeWithOffset);
}

Expand Down
Expand Up @@ -60,7 +60,17 @@ public void convertDate_shouldConvertTimeCorrectly() throws Exception {
*/
@Test
public void getCurrentUTCTime_shouldFormatTimeCorrectly() throws Exception {
Assert.assertEquals("2020-09-07T14:30:01Z", Utils.getCurrentUTCTime(LocalDateTime.of(2020, 9, 7, 14, 30, 00), 1000));
Assert.assertEquals("2020-09-07T14:30:00Z", Utils.getCurrentUTCTime(LocalDateTime.of(2020, 9, 7, 14, 30, 00)));
}


/**
* @see Utils#getCurrentUTCTime(LocalDateTime)
* @verifies truncate to seconds
*/
@Test
public void getCurrentUTCTime_shouldTruncateToSeconds() throws Exception {
Assert.assertEquals("2020-09-07T14:30:00Z", Utils.getCurrentUTCTime(LocalDateTime.of(2020, 9, 7, 14, 30, 00, 1000000)));
}

/**
Expand Down

0 comments on commit dd3bbef

Please sign in to comment.