@Test public void emitDate() throws Exception { DateOption value = new DateOption(); value.modify(date(2000, 2, 9)); emitter.emit(value); value.modify(date(2000, 3, 1)); emitter.emit(value); value.modify(date(100, 3, 30)); emitter.emit(value); emitter.endRecord(); value.setNull(); emitter.emit(value); value.modify(date(1, 1, 1)); emitter.emit(value); value.modify(date(9999, 12, 31)); emitter.emit(value); emitter.endRecord(); emitter.close(); RecordParser parser = parser(); assertThat(parser.next(), is(true)); parser.fill(value); assertThat(value.get(), is(date(2000, 2, 9))); parser.fill(value); assertThat(value.get(), is(date(2000, 3, 1))); parser.fill(value); assertThat(value.get(), is(date(100, 3, 30))); assertThat(parser.next(), is(true)); parser.fill(value); assertThat(value.isNull(), is(true)); parser.fill(value); assertThat(value.get(), is(date(1, 1, 1))); parser.fill(value); assertThat(value.get(), is(date(9999, 12, 31))); assertThat(parser.next(), is(false)); }
private void emitDate(int days) { int year = DateUtil.getYearFromDay(days); int daysInYear = days - DateUtil.getDayFromYear(year); boolean leap = DateUtil.isLeap(year); int month = DateUtil.getMonthOfYear(daysInYear, leap); int day = DateUtil.getDayOfMonth(daysInYear, leap); fill('0', YEAR_FIELD_LENGTH, year); lineBuffer.append(DATE_FIELD_SEPARATOR); fill('0', MONTH_FIELD_LENGTH, month); lineBuffer.append(DATE_FIELD_SEPARATOR); fill('0', DATE_FIELD_LENGTH, day); }
TsvEmitter implements RecordEmitter { private void emitDate(int days) { int year = DateUtil.getYearFromDay(days); int daysInYear = days - DateUtil.getDayFromYear(year); boolean leap = DateUtil.isLeap(year); int month = DateUtil.getMonthOfYear(daysInYear, leap); int day = DateUtil.getDayOfMonth(daysInYear, leap); fill('0', YEAR_FIELD_LENGTH, year); lineBuffer.append(DATE_FIELD_SEPARATOR); fill('0', MONTH_FIELD_LENGTH, month); lineBuffer.append(DATE_FIELD_SEPARATOR); fill('0', DATE_FIELD_LENGTH, day); } }
TsvEmitter implements RecordEmitter { private void emitDate(int days) { int year = DateUtil.getYearFromDay(days); int daysInYear = days - DateUtil.getDayFromYear(year); boolean leap = DateUtil.isLeap(year); int month = DateUtil.getMonthOfYear(daysInYear, leap); int day = DateUtil.getDayOfMonth(daysInYear, leap); fill('0', YEAR_FIELD_LENGTH, year); lineBuffer.append(DATE_FIELD_SEPARATOR); fill('0', MONTH_FIELD_LENGTH, month); lineBuffer.append(DATE_FIELD_SEPARATOR); fill('0', DATE_FIELD_LENGTH, day); } TsvEmitter(Writer writer); }
TsvEmitter implements RecordEmitter { private void emitDate(int days) { int year = DateUtil.getYearFromDay(days); int daysInYear = days - DateUtil.getDayFromYear(year); boolean leap = DateUtil.isLeap(year); int month = DateUtil.getMonthOfYear(daysInYear, leap); int day = DateUtil.getDayOfMonth(daysInYear, leap); fill('0', YEAR_FIELD_LENGTH, year); lineBuffer.append(DATE_FIELD_SEPARATOR); fill('0', MONTH_FIELD_LENGTH, month); lineBuffer.append(DATE_FIELD_SEPARATOR); fill('0', DATE_FIELD_LENGTH, day); } TsvEmitter(Writer writer); @Override void endRecord(); @Override void emit(BooleanOption option); @Override void emit(ByteOption option); @Override void emit(ShortOption option); @Override void emit(IntOption option); @Override void emit(LongOption option); @Override void emit(FloatOption option); @Override void emit(DoubleOption option); @Override void emit(DecimalOption option); @Override void emit(StringOption option); @Override void emit(DateOption option); @Override void emit(DateTimeOption option); @Override void flush(); @Override void close(); }
TsvEmitter implements RecordEmitter { private void emitDate(int days) { int year = DateUtil.getYearFromDay(days); int daysInYear = days - DateUtil.getDayFromYear(year); boolean leap = DateUtil.isLeap(year); int month = DateUtil.getMonthOfYear(daysInYear, leap); int day = DateUtil.getDayOfMonth(daysInYear, leap); fill('0', YEAR_FIELD_LENGTH, year); lineBuffer.append(DATE_FIELD_SEPARATOR); fill('0', MONTH_FIELD_LENGTH, month); lineBuffer.append(DATE_FIELD_SEPARATOR); fill('0', DATE_FIELD_LENGTH, day); } TsvEmitter(Writer writer); @Override void endRecord(); @Override void emit(BooleanOption option); @Override void emit(ByteOption option); @Override void emit(ShortOption option); @Override void emit(IntOption option); @Override void emit(LongOption option); @Override void emit(FloatOption option); @Override void emit(DoubleOption option); @Override void emit(DecimalOption option); @Override void emit(StringOption option); @Override void emit(DateOption option); @Override void emit(DateTimeOption option); @Override void flush(); @Override void close();  }