class MySQLTimeBinaryProtocolValue implements MySQLBinaryProtocolValue {

    @Override
    public void write(final MySQLPacketPayload payload, final Object value) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(((Time) value).getTime());
        int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY);
        int minutes = calendar.get(Calendar.MINUTE);
        int seconds = calendar.get(Calendar.SECOND);
        int nanos = new Timestamp(calendar.getTimeInMillis()).getNanos();
        boolean isTimeAbsent = 0 == hourOfDay && 0 == minutes && 0 == seconds;
        boolean isNanosAbsent = 0 == nanos;
        if (isTimeAbsent && isNanosAbsent) {
            payload.writeInt1(0);
            return;
        }
        if (isNanosAbsent) {
            payload.writeInt1(8);
            writeTime(payload, hourOfDay, minutes, seconds);
            return;
        }
        payload.writeInt1(12);
        writeTime(payload, hourOfDay, minutes, seconds);
        writeNanos(payload, nanos);
    }

}