Skip to content

Commit

Permalink
Added outputting the time as HH:mm:ss
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsbasjes committed Nov 5, 2016
1 parent 5d91592 commit a9df147
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public List<String> getPossibleOutput() {
result.add("TIME.SECOND:second");
result.add("TIME.MILLISECOND:millisecond");

result.add("TIME.DATE:date"); // yyyy-mm-dd
result.add("TIME.DATE:date"); // yyyy-MM-dd
result.add("TIME.TIME:time"); // HH:mm:ss

// Timezone independent
result.add("TIME.ZONE:timezone");
Expand All @@ -123,7 +124,8 @@ public List<String> getPossibleOutput() {
result.add("TIME.SECOND:second_utc");
result.add("TIME.MILLISECOND:millisecond_utc");

result.add("TIME.DATE:date_utc"); // yyyy-mm-dd
result.add("TIME.DATE:date_utc"); // yyyy-MM-dd
result.add("TIME.TIME:time_utc"); // HH:mm:ss

return result;
}
Expand All @@ -146,6 +148,8 @@ public List<String> getPossibleOutput() {
private boolean wantSecond = false;
private boolean wantMillisecond = false;
private boolean wantDate = false;
private boolean wantTime = false;


// Timezone independent
private boolean wantTimezone = false;
Expand All @@ -163,6 +167,7 @@ public List<String> getPossibleOutput() {
private boolean wantSecondUTC = false;
private boolean wantMillisecondUTC = false;
private boolean wantDateUTC = false;
private boolean wantTimeUTC = false;

@Override
public EnumSet<Casts> prepareForDissect(final String inputname, final String outputname) {
Expand Down Expand Up @@ -213,6 +218,10 @@ public EnumSet<Casts> prepareForDissect(final String inputname, final String out
wantDate = true;
return Casts.STRING_ONLY;

case "time":
wantTime = true;
return Casts.STRING_ONLY;

// Timezone independent
case "timezone":
wantTimezone = true;
Expand Down Expand Up @@ -267,6 +276,10 @@ public EnumSet<Casts> prepareForDissect(final String inputname, final String out
wantDateUTC = true;
return Casts.STRING_ONLY;

case "time_utc":
wantTimeUTC = true;
return Casts.STRING_ONLY;

default:
return null;
}
Expand All @@ -289,7 +302,8 @@ public void prepareForRun() {
|| wantMinute
|| wantSecond
|| wantMillisecond
|| wantDate;
|| wantDate
|| wantTime;

// Timezone independent
wantAnyTZIndependent =
Expand All @@ -308,12 +322,14 @@ public void prepareForRun() {
|| wantMinuteUTC
|| wantSecondUTC
|| wantMillisecondUTC
|| wantDateUTC;
|| wantDateUTC
|| wantTimeUTC;
}

// --------------------------------------------

private static final DateTimeFormatter ISO_DATE_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd");
private static final DateTimeFormatter ISO_TIME_FORMATTER = DateTimeFormat.forPattern("HH:mm:ss");

@Override
public void dissect(final Parsable<?> parsable, final String inputname) throws DissectionFailure {
Expand Down Expand Up @@ -378,6 +394,11 @@ public void dissect(final Parsable<?> parsable, final String inputname) throws D
ISO_DATE_FORMATTER.print(dateTime));
}

if (wantTime) {
parsable.addDissection(inputname, "TIME.TIME", "time",
ISO_TIME_FORMATTER.print(dateTime));
}

// Timezone independent
if (wantTimezone) {
parsable.addDissection(inputname, "TIME.TIMEZONE", "timezone",
Expand Down Expand Up @@ -437,6 +458,12 @@ public void dissect(final Parsable<?> parsable, final String inputname) throws D
parsable.addDissection(inputname, "TIME.DATE", "date_utc",
ISO_DATE_FORMATTER.print(dateTime));
}

if (wantTimeUTC) {
parsable.addDissection(inputname, "TIME.TIME", "time_utc",
ISO_TIME_FORMATTER.print(dateTime));
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class TestRecord {
"TIME.YEAR:request.receive.time.year",
"TIME.MONTHNAME:request.receive.time.monthname",
"TIME.DATE:request.receive.time.date",
"TIME.TIME:request.receive.time.time",

"TIME.SECOND:request.receive.time.second_utc",
"TIME.MINUTE:request.receive.time.minute_utc",
"TIME.HOUR:request.receive.time.hour_utc",
Expand All @@ -57,6 +59,7 @@ public class TestRecord {
"TIME.YEAR:request.receive.time.year_utc",
"TIME.MONTHNAME:request.receive.time.monthname_utc",
"TIME.DATE:request.receive.time.date_utc",
"TIME.TIME:request.receive.time.time_utc",
})
public void setValue(final String name, final String value) {
results.put(name, value);
Expand Down Expand Up @@ -115,6 +118,7 @@ public void testTimeStampDissector() throws Exception {
assertEquals("44", results.get("TIME.SECOND:request.receive.time.second"));
assertEquals(Long.valueOf(44), longResults.get("TIME.SECOND:request.receive.time.second"));
assertEquals("2012-12-31", results.get("TIME.DATE:request.receive.time.date"));
assertEquals("23:00:44", results.get("TIME.TIME:request.receive.time.time"));

assertEquals("2013", results.get("TIME.YEAR:request.receive.time.year_utc"));
assertEquals("1", results.get("TIME.MONTH:request.receive.time.month_utc"));
Expand All @@ -128,6 +132,7 @@ public void testTimeStampDissector() throws Exception {
assertEquals("44", results.get("TIME.SECOND:request.receive.time.second_utc"));
assertEquals(Long.valueOf(44), longResults.get("TIME.SECOND:request.receive.time.second_utc"));
assertEquals("2013-01-01", results.get("TIME.DATE:request.receive.time.date_utc"));
assertEquals("06:00:44", results.get("TIME.TIME:request.receive.time.time_utc"));
}

@Test
Expand Down

0 comments on commit a9df147

Please sign in to comment.