theshoeshiner commented on code in PR #1062:
URL: https://github.com/apache/commons-lang/pull/1062#discussion_r1223208339


##########
src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java:
##########
@@ -632,4 +632,31 @@ public void testLowDurations() {
         }
     }
 
+    @Test
+    public void testUnmatchedOptionalToken() {
+        assertThrows(IllegalArgumentException.class, () -> 
DurationFormatUtils.formatDuration(1, "[s"));

Review Comment:
   Nesting has little value that I can see, so simplest solution will be to 
catch any nesting and throw an IllegalArgumentException. That will prevent 
unbalancing issues since the current optional state is tracked with a boolean, 
similar to literals, and we can easily detect attempts to nest.
   
   Multiple optional blocks are supported by default (though realistic use 
cases may be few). If you wanted to always show minutes, but omit zero-value 
hours and seconds, then the format `[H'h']m'm'[s's']` will produce values like:
   ```
   254h16m
   15m15s 
   0m9s
   ```
   Added 
https://github.com/apache/commons-lang/pull/1062/commits/12bf4b67ef7545789b97f0785231c64d5aad5a24
 to address the nesting issue.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to