BluetoothBytesParser { public boolean setDateTime(Calendar calendar) { if (calendar == null) return false; mValue = new byte[7]; mValue[0] = (byte) calendar.get(Calendar.YEAR); mValue[1] = (byte) (calendar.get(Calendar.YEAR) >> 8); mValue[2] = (byte) (calendar.get(Calendar.MONTH) + 1); mValue[3] = (byte) calendar.get(Calendar.DATE); mValue[4] = (byte) calendar.get(Calendar.HOUR_OF_DAY); mValue[5] = (byte) calendar.get(Calendar.MINUTE); mValue[6] = (byte) calendar.get(Calendar.SECOND); return true; } BluetoothBytesParser();  BluetoothBytesParser(ByteOrder byteOrder);  BluetoothBytesParser(byte[] value);  BluetoothBytesParser(byte[] value, ByteOrder byteOrder);  BluetoothBytesParser(byte[] value, int offset);  BluetoothBytesParser(byte[] value, int offset, ByteOrder byteOrder); Integer getIntValue(int formatType); Integer getIntValue(int formatType, ByteOrder byteOrder); long getLongValue(); long getLongValue(ByteOrder byteOrder); long getLongValue(int offset, ByteOrder byteOrder); Integer getIntValue(int formatType, int offset, ByteOrder byteOrder); Float getFloatValue(int formatType); Float getFloatValue(int formatType, ByteOrder byteOrder); Float getFloatValue(int formatType, int offset, ByteOrder byteOrder); String getStringValue(); String getStringValue(int offset); Date getDateTime(); Date getDateTime(int offset); byte[] getValue(); boolean setIntValue(int value, int formatType, int offset); boolean setIntValue(int value, int formatType); boolean setLong(long value); boolean setLong(long value, int offset); boolean setFloatValue(int mantissa, int exponent, int formatType, int offset); boolean setFloatValue(float value, int precision); boolean setString(String value); boolean setString(String value, int offset); void setValue(byte[] value); boolean setCurrentTime(Calendar calendar); boolean setDateTime(Calendar calendar); static String bytes2String(final byte[] bytes); static byte[] mergeArrays(byte[]... arrays); int getOffset(); void setOffset(int offset); ByteOrder getByteOrder(); @Override String toString(); static final int FORMAT_UINT8; static final int FORMAT_UINT16; static final int FORMAT_UINT32; static final int FORMAT_SINT8; static final int FORMAT_SINT16; static final int FORMAT_SINT32; static final int FORMAT_SFLOAT; static final int FORMAT_FLOAT; }
@Test public void setDateTimeTest() { BluetoothBytesParser parser = new BluetoothBytesParser(); Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Amsterdam")); long timestamp = 1578310812218L; calendar.setTimeInMillis(timestamp); parser.setDateTime(calendar); parser.setOffset(0); Date parsedDateTime = parser.getDateTime(); assertEquals(7, parser.getValue().length); calendar.setTime(parsedDateTime); assertEquals(2020, calendar.get(GregorianCalendar.YEAR)); assertEquals(1, calendar.get(GregorianCalendar.MONTH) + 1); assertEquals(6, calendar.get(GregorianCalendar.DAY_OF_MONTH)); assertEquals(12, calendar.get(GregorianCalendar.HOUR_OF_DAY)); assertEquals(40, calendar.get(GregorianCalendar.MINUTE)); assertEquals(12, calendar.get(GregorianCalendar.SECOND)); }