use of java.text.DateFormat in project OpenGrok by OpenGrok.
the class RazorHistoryParser method parseContents.
protected History parseContents(BufferedReader contents) throws IOException {
DateFormat df = repository.getDateFormat();
String line;
ArrayList<HistoryEntry> entries = new ArrayList<HistoryEntry>();
HistoryEntry entry = null;
boolean ignoreEntry = false;
boolean seenActionType = false;
boolean lastWasTitle = true;
Matcher actionMatcher = ACTION_TYPE_PATTERN.matcher("");
Matcher infoMatcher = ADDITIONAL_INFO_PATTERN.matcher("");
while ((line = contents.readLine()) != null) {
parseDebug("Processing '" + line + "'");
if (StringUtils.isOnlyWhitespace(line)) {
if (entry != null && entry.getDate() != null) {
entries.add(entry);
dumpEntry(entry);
}
entry = new HistoryEntry();
ignoreEntry = false;
seenActionType = false;
} else if (!ignoreEntry) {
if (seenActionType) {
infoMatcher.reset(line);
if (infoMatcher.find()) {
String infoType = infoMatcher.group(1);
String details = infoMatcher.group(2);
if ("TITLE".equals(infoType)) {
parseDebug("Setting Message : '" + details + "'");
entry.setMessage(details);
lastWasTitle = true;
} else if ("ISSUE".equals(infoType)) {
parseDebug("Adding CR : '" + details + "'");
entry.addChangeRequest(details);
} else {
parseDebug("Ignoring Info Type Line '" + line + "'");
}
} else {
if (!line.startsWith("##") && line.charAt(0) == '#') {
parseDebug("Seen Comment : '" + line + "'");
if (lastWasTitle) {
entry.appendMessage("");
lastWasTitle = false;
}
entry.appendMessage(line.substring(1));
} else {
parseProblem("Expecting addlInfo and got '" + line + "'");
}
}
} else {
actionMatcher.reset(line);
if (actionMatcher.find()) {
seenActionType = true;
if (entry != null && entry.getDate() != null) {
entries.add(entry);
dumpEntry(entry);
}
entry = new HistoryEntry();
String actionType = actionMatcher.group(1);
String userName = actionMatcher.group(2);
String revision = actionMatcher.group(3);
String state = actionMatcher.group(4);
String dateTime = actionMatcher.group(5);
parseDebug("New History Event Seen : actionType = " + actionType + ", userName = " + userName + ", revision = " + revision + ", state = " + state + ", dateTime = " + dateTime);
if (actionType.startsWith("INTRODUCE") || actionType.contains("CHECK-IN") || "CHECK-POINT".equals(actionType) || "REVERT".equals(actionType)) {
entry.setAuthor(userName);
entry.setRevision(revision);
entry.setActive("Active".equals(state));
Date date = null;
try {
date = df.parse(dateTime);
} catch (ParseException pe) {
//
throw new IOException("Could not parse date: " + dateTime, pe);
}
entry.setDate(date);
ignoreEntry = false;
} else {
ignoreEntry = true;
}
} else {
parseProblem("Expecting actionType and got '" + line + "'");
}
}
}
}
if (entry != null && entry.getDate() != null) {
entries.add(entry);
dumpEntry(entry);
}
History history = new History();
history.setHistoryEntries(entries);
return history;
}
use of java.text.DateFormat in project OpenGrok by OpenGrok.
the class SubversionRepositoryTest method testDateFormats.
@Test
public void testDateFormats() {
String[][] tests = new String[][] { { "abcd", "expected exception" }, { "2016-01-01 10:00:00", "expected exception" }, { "2016 Sat, 1 Apr 2008 15:12:51 +0000", "expected exception" }, { "Sat, 1 Dub 2008 15:12:51 +0000", "expected exception" }, { "2016_01_01T10:00:00Z", "expected exception" }, { "2016-01-01T10:00:00T", "expected exception" }, { "2016-01-01T10:00:00.200", "expected exception" }, { "2016-01-01 10:00:00Z", "expected exception" }, // lenient - wrong hour
{ "2016-01-01T40:00:00Z", null }, // lenient - wrong minute
{ "2016-01-01T00:70:00Z", null }, // lenient - wrong second
{ "2016-01-01T00:00:99Z", null }, // lenient - wrong day
{ "2016-03-40T00:00:00Z", null }, { "2016-01-01T10:00:00.200Z", null }, { "2016-01-01T11:00:00.200Z", null }, { "2016-01-01T10:00:00.Z", null }, { "2017-01-01T10:00:00.Z", null }, { "2016-01-01T10:00:00Z", null } };
DateFormat format = new SubversionRepository().getDateFormat();
for (String[] test : tests) {
try {
format.parse(test[0]);
if (test[1] != null) {
Assert.fail("Shouldn't be able to parse the date: " + test[0]);
}
} catch (ParseException ex) {
if (test[1] == null) {
// no exception
Assert.fail("Shouldn't throw a parsing exception for date: " + test[0]);
}
}
}
}
use of java.text.DateFormat in project OpenGrok by OpenGrok.
the class RepositoryTest method testDateFormats.
@Test
public void testDateFormats() throws ParseException {
String[][] tests = new String[][] { { "2016-01-01 10:00:00", "yyyy-MM-dd HH:mm:ss" }, { "2016 Sat, 5 Apr 2008 15:12:51 +0000", "yyyy EE, d MMM yyyy HH:mm:ss Z" }, { "Sat, 5 Apr 2008 15:12:51 +0000", "EE, d MMM yyyy HH:mm:ss Z" }, { "2016_01_01T10:00:00Z", "yyyy_MM_dd'T'HH:mm:ss'Z'" }, { "2016-01-01 10:00", "yyyy-MM-dd HH:mm" }, { "2016_01_01 10:00 +0000", "yyyy_MM_dd HH:mm Z" }, { "2016-01-01 10:00:00 +0000", "yyyy-MM-dd HH:mm:ss Z" }, { "2016-01-01 10:00 +0000", "yyyy-MM-dd HH:mm Z" }, { "2016-01-02 10:00 +0000", "yyyy-MM-dd HH:mm Z" }, { "2017-01-01 10:00 +0700", "yyyy-MM-dd HH:mm Z" }, { "2016-12-31 10:00 +0000", "yyyy-MM-dd HH:mm Z" } };
for (String[] test : tests) {
RepositoryImplementation repository = new RepositoryImplementation();
repository.setDatePatterns(new String[] { test[1] });
DateFormat format = repository.getDateFormat();
format.parse(test[0]);
}
}
use of java.text.DateFormat in project OpenGrok by OpenGrok.
the class RepositoryTest method testMultipleInvalidDateFormats.
@Test
public void testMultipleInvalidDateFormats() {
String[][] tests = new String[][] { { "2016-01-01 10:00:00", "'abcd'", "MMM yy:ss ", "EE, d MMM yyyy Hss Z" }, { "2016 Sat, 5 Apr 2008 15:12:51 +0000", "yyyy d MMM yy:ss Z", "yyyy EE, d MMM ss Z" }, { "Sat, 5 Apr 2008 15:12:51 +0000", "d MMM yyyy Z", "EE, d MMM yyyy Hss Z" }, { "2016_01_01T10:00:00Z", "yyyy_MM_dd'T'ss'Z'" }, { "2016-01-01 10:00", "MM-dd Z", "EE-MM-dd HH", "Z dd-dd HH:mm" }, { "2016_01_01 10:00 +0000", "yyyy-MM_dd HH:mm Z" }, { "2016-01-01 10:00:00 +0000", "yyyy_MM_dd HH:s Z", "'bad format'" }, { "2016-01-01 10:00 +0000", "MM-d HH:mm", "yyyy-MM-dmm Z" }, { "2016-01-02 10:00 +0000", "yyyy-Mmm Z", "yyyy-M HH:mm Z" } };
for (String[] test : tests) {
RepositoryImplementation repository = new RepositoryImplementation();
repository.setDatePatterns(Arrays.copyOfRange(test, 1, test.length));
DateFormat format = repository.getDateFormat();
try {
format.parse(test[0]);
Assert.fail("Shouldn't be able to parse the date: " + test[0]);
} catch (ParseException ex) {
}
}
}
use of java.text.DateFormat in project actor-platform by actorapp.
the class CallFragment method startTimer.
protected void startTimer() {
final DateFormat formatter = new SimpleDateFormat("HH:mm:ss");
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
if (timer == null) {
timer = ActorSystem.system().actorOf(Props.create(() -> new TimerActor(300)), "calls/timer");
timer.send(new TimerActor.Register((currentTime, timeFromRegister) -> {
if (getActivity() != null) {
getActivity().runOnUiThread(() -> {
if (currentState == CallState.IN_PROGRESS) {
statusTV.setText(formatter.format(new Date(timeFromRegister)));
}
});
}
}, TIMER_ID));
}
}
Aggregations