forked from j62/ctbrec
1
0
Fork 0

Fix: date placeholders with patterns with more than one ocurrence are

This commit is contained in:
0xb00bface 2020-11-21 16:06:45 +01:00
parent dc8d288b05
commit 0e7b5b5452
3 changed files with 24 additions and 6 deletions

View File

@ -1,8 +1,13 @@
3.10.5
========================
* You can now click on the recording / pause indicator to pause or resume
recording in the thubmnail overview tabs
* MFC websocket now uses the TLS URL
* Fix: date placeholders with patterns with more than one ocurrence are
replaced with the value of the first one
* Some smaller UI tweaks
- adjusted component sizes for small resolutions
- recording indicator can now be used to pause / resume the recording
- adjusted scroll speed in the thumbnail overviews
- added shortcuts for the thumbnail overviews (keys 1-9 and arrow keys)
3.10.4
========================

View File

@ -67,15 +67,18 @@ public abstract class AbstractPlaceholderAwarePostProcessor extends AbstractPost
private String replaceDateTime(Recording rec, String filename, String placeHolder, ZoneId zone) {
String pattern = "yyyy-MM-dd_HH-mm-ss";
Matcher m = Pattern.compile("\\$\\{" + placeHolder + "(?:\\((.*?)\\))?\\}").matcher(filename);
if (m.find()) {
Pattern regex = Pattern.compile("\\$\\{" + placeHolder + "(?:\\((.*?)\\))?\\}");
Matcher m = regex.matcher(filename);
while (m.find()) {
String p = m.group(1);
if (p != null) {
pattern = p;
}
String formattedDate = getDateTime(rec, pattern, zone);
filename = m.replaceFirst(formattedDate);
m = regex.matcher(filename);
}
String formattedDate = getDateTime(rec, pattern, zone);
return m.replaceAll(formattedDate);
return filename;
}
private String getDateTime(Recording rec, String pattern, ZoneId zone) {

View File

@ -54,6 +54,7 @@ public class AbstractPlaceholderAwarePostProcessorTest extends AbstractPpTest {
@Test
public void testUtcTimeReplacement() {
// without user defined pattern
String date = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss")
.withLocale(Locale.US)
.withZone(ZoneOffset.UTC)
@ -61,12 +62,21 @@ public class AbstractPlaceholderAwarePostProcessorTest extends AbstractPpTest {
String input = "asdf_${utcDateTime}_asdf";
assertEquals("asdf_" + date + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, rec, config));
// with user defined pattern
date = DateTimeFormatter.ofPattern("yyyyMMdd-HHmmss")
.withLocale(Locale.US)
.withZone(ZoneOffset.UTC)
.format(rec.getStartDate());
input = "asdf_${utcDateTime(yyyyMMdd-HHmmss)}_asdf";
assertEquals("asdf_" + date + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, rec, config));
// multiple occurences with user defined patterns
date = DateTimeFormatter.ofPattern("yyyy-MM-dd/yyyy")
.withLocale(Locale.US)
.withZone(ZoneOffset.UTC)
.format(rec.getStartDate());
input = "asdf_${utcDateTime(yyyy)}-${utcDateTime(MM)}-${utcDateTime(dd)}/${utcDateTime(yyyy)}_asdf";
assertEquals("asdf_" + date + "_asdf", placeHolderAwarePp.fillInPlaceHolders(input, rec, config));
}
@Test