Skip to content

Commit

Permalink
#7 Trim both spaces and commas from date pattern after "Number of day…
Browse files Browse the repository at this point in the history
…s to event" substitution into the pattern. Now comma disappears with disappearing "Number of days to event" string
  • Loading branch information
yvolk committed Mar 14, 2020
1 parent dbc0d94 commit 0c6f6b3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,19 @@ public void customPatterns() {
assertPattern(now, "BBB " + javaPattern + " b", todayText + " " + javaFormatted);
assertPattern(now.plusDays(1), "BBB " + javaPattern + " b", tomorrowText + " " +
javaFormatted(javaPattern, now.plusDays(1)));
assertPattern(now.plusDays(1), "BBB, " + javaPattern + " b", tomorrowText + ", " +
javaFormatted(javaPattern, now.plusDays(1)));
assertPattern(now.plusDays(2), "BBB " + javaPattern + " b",
javaFormatted(javaPattern, now.plusDays(2)) + " 2");
assertPattern(now.plusDays(2), "BBB, " + javaPattern + " b",
javaFormatted(javaPattern, now.plusDays(2)) + " 2");

assertPattern(now, "BBB " + javaPattern + " BBBB", todayText + " " + javaFormatted);
assertPattern(now, "BBB " + javaPattern + ", BBBB", todayText + " " + javaFormatted);
assertPattern(now.plusDays(1), "BBB " + javaPattern + " BBBB", tomorrowText + " " +
javaFormatted(javaPattern, now.plusDays(1)));
assertPattern(now.plusDays(1), "BBB " + javaPattern + ", BBBB", tomorrowText + " " +
javaFormatted(javaPattern, now.plusDays(1)));
assertPattern(now.plusDays(2), "BBB " + javaPattern + " BBBB",
javaFormatted(javaPattern, now.plusDays(2)) + " " + inTwoDaysText);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public enum DateFormatType {
DAY_IN_MONTH("dayInMonth", R.string.date_format_day_in_month, "dd"),
MONTH_DAY("monthDay", R.string.date_format_month_day, "MM-dd"),
WEEK_IN_YEAR("weekInYear", R.string.date_format_week_in_year, "ww"),
DEFAULT_EXAMPLE("example", R.string.pattern_example, "BBB EEEE d MMM yyyy BBBB"),
DEFAULT_EXAMPLE("example", R.string.pattern_example, "BBB, EEEE d MMM yyyy, BBBB"),
PATTERN_EXAMPLE1("example1", R.string.pattern_example, "b 'days,' EEE, d MMM yyyy, 'week' ww"),
CUSTOM("custom-01", R.string.custom_pattern, ""),
UNKNOWN("unknown", R.string.not_found, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,19 @@ private String preProcessNumberOfDaysToEvent(DateTime date, String pattern, int
replacement +
(ind2 < pattern.length() ? pattern.substring(ind2) : "");

return preProcessNumberOfDaysToEvent(date, pattern2.trim(), startIndex + replacement.length(),
return preProcessNumberOfDaysToEvent(date, trimPattern(pattern2), startIndex + replacement.length(),
alreadyShown || replacement.length() > 0);
}

private String trimPattern(String pattern) {
String pattern2 = pattern.trim();
if (pattern2.endsWith(",")) pattern2 = pattern2.substring(0, pattern2.length()-1);
if (pattern2.startsWith(",")) pattern2 = pattern2.substring(1);
if (pattern2.equals(pattern)) return pattern;

return trimPattern(pattern2);
}

private int getIndexOfNumberOfDaysLetter(String pattern, int startIndex) {
boolean inQuotes = false;
for (int ind = startIndex; ind < pattern.length(); ind++) {
Expand Down

0 comments on commit 0c6f6b3

Please sign in to comment.