Skip to content

Commit

Permalink
Even easier subclass, if only the unit is different
Browse files Browse the repository at this point in the history
  • Loading branch information
fhoeben committed Sep 18, 2013
1 parent 72f80d8 commit adb061c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/fitnesse/wikitext/parser/Today.java
Expand Up @@ -11,13 +11,15 @@
public class Today extends SymbolType implements Rule, Translation {
private static final String Format = "Format";
private static final String Increment = "Increment";
private final int incrementUnit;

public Today() {
this("Today", "!today");
this("Today", "!today", Calendar.DAY_OF_MONTH);
}

protected Today(String symbolName, String symbolText) {
protected Today(String symbolName, String symbolText, int unitForIncrement) {
super(symbolName);
incrementUnit = unitForIncrement;
wikiMatcher(new Matcher().string(symbolText));
wikiRule(this);
htmlTranslation(this);
Expand Down Expand Up @@ -69,7 +71,7 @@ public String toTarget(Translator translator, Symbol symbol) {
}

protected void addIncrement(GregorianCalendar calendar, int increment) {
calendar.add(Calendar.DAY_OF_MONTH, increment);
calendar.add(incrementUnit, increment);
}

private String makeFormat(String format) {
Expand Down
7 changes: 1 addition & 6 deletions src/fitnesse/wikitext/test/TodayExtensionTest.java
Expand Up @@ -56,12 +56,7 @@ public void translatesInTable() {

private static class MonthsFromToday extends Today {
public MonthsFromToday() {
super("MonthsFromToday", "!monthsFromToday");
}

@Override
protected void addIncrement(GregorianCalendar calendar, int increment) {
calendar.add(Calendar.MONTH, increment);
super("MonthsFromToday", "!monthsFromToday", Calendar.MONTH);
}
}
}

0 comments on commit adb061c

Please sign in to comment.