fitnesse.wikitext.parser.LastModified Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fitnesse Show documentation
Show all versions of fitnesse Show documentation
The fully integrated standalone wiki, and acceptance testing framework.
The newest version!
package fitnesse.wikitext.parser;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import fitnesse.util.Clock;
import fitnesse.wiki.WikiPageProperty;
public class LastModified extends SymbolType implements Translation {
public LastModified() {
super("LastModified");
wikiMatcher(new Matcher().string("!lastmodified"));
htmlTranslation(this);
}
@Override
public String toTarget(Translator translator, Symbol symbol) {
String user = translator.getPage().getProperty(WikiPageProperty.LAST_MODIFYING_USER);
String date = translator.getPage().getProperty(WikiPageProperty.LAST_MODIFIED);
return translator.formatMessage(
"Last modified " +
(!user.isEmpty() ? "by " + user : "anonymously") +
" on " + formatDate(date));
}
private String formatDate(String dateString) {
Date date;
if (dateString.isEmpty()) date = Clock.currentDate();
else {
try {
date = WikiPageProperty.getTimeFormat().parse(dateString);
}
catch (ParseException e) {
return dateString;
}
}
return new SimpleDateFormat("MMM dd, yyyy").format(date) + " at " + new SimpleDateFormat("hh:mm:ss a").format(date);
}
}