@Test public void setCurrentTimeTest() { BluetoothBytesParser parser = new BluetoothBytesParser(); Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Amsterdam")); long timestamp = 1578310812218L; calendar.setTimeInMillis(timestamp); parser.setCurrentTime(calendar); parser.setOffset(0); Date parsedDateTime = parser.getDateTime(); assertEquals(10, 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)); assertEquals(1, (int) parser.getIntValue(FORMAT_UINT8)); assertEquals(55, (int) parser.getIntValue(FORMAT_UINT8)); assertEquals(1, (int) parser.getIntValue(FORMAT_UINT8)); }
public boolean setCurrentTime(Calendar calendar) { if (calendar == null) return false; mValue = new byte[10]; 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); mValue[7] = (byte) ((calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7 + 1); mValue[8] = (byte) (calendar.get(Calendar.MILLISECOND) * 256 / 1000); mValue[9] = 1; return true; }
BluetoothBytesParser { public boolean setCurrentTime(Calendar calendar) { if (calendar == null) return false; mValue = new byte[10]; 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); mValue[7] = (byte) ((calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7 + 1); mValue[8] = (byte) (calendar.get(Calendar.MILLISECOND) * 256 / 1000); mValue[9] = 1; return true; } }
BluetoothBytesParser { public boolean setCurrentTime(Calendar calendar) { if (calendar == null) return false; mValue = new byte[10]; 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); mValue[7] = (byte) ((calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7 + 1); mValue[8] = (byte) (calendar.get(Calendar.MILLISECOND) * 256 / 1000); mValue[9] = 1; 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); }
BluetoothBytesParser { public boolean setCurrentTime(Calendar calendar) { if (calendar == null) return false; mValue = new byte[10]; 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); mValue[7] = (byte) ((calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7 + 1); mValue[8] = (byte) (calendar.get(Calendar.MILLISECOND) * 256 / 1000); mValue[9] = 1; 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(); }
BluetoothBytesParser { public boolean setCurrentTime(Calendar calendar) { if (calendar == null) return false; mValue = new byte[10]; 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); mValue[7] = (byte) ((calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7 + 1); mValue[8] = (byte) (calendar.get(Calendar.MILLISECOND) * 256 / 1000); mValue[9] = 1; 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; }