@Test void decodeDateTimeShouldThrowOnNull() { assertThatThrownBy(() -> DecoderUtils.decodeDateTime(null)) .isInstanceOf(DecodingException.class); }
public static LocalDateTime decodeDateTime(CharSequence chars) throws DecodingException { if (isDateTime(chars)) { char dayHigh = chars.charAt(0); char dayLow = chars.charAt(1); int day = decodeFixedDay(dayHigh, dayLow); char monthFirstChar = chars.charAt(3); char monthSecondChar = chars.charAt(4); char monthThirdChar = chars.charAt(5); int month = decodeMonth(monthFirstChar, monthSecondChar, monthThirdChar); char milleniumChar = chars.charAt(7); char centuryChar = chars.charAt(8); char decadeChar = chars.charAt(9); char yearChar = chars.charAt(10); int year = decodeYear(milleniumChar, centuryChar, decadeChar, yearChar); char zoneDeterminent = chars.charAt(21); char zoneDigitOne = chars.charAt(22); char zoneDigitTwo = chars.charAt(23); char zoneDigitThree = chars.charAt(24); char zoneDigitFour = chars.charAt(25); int offset = decodeZone(zoneDeterminent, zoneDigitOne, zoneDigitTwo, zoneDigitThree, zoneDigitFour); char hourHigh = chars.charAt(12); char hourLow = chars.charAt(13); int hour = applyHourOffset(offset, decodeNumber(hourHigh, hourLow)); char minuteHigh = chars.charAt(15); char minuteLow = chars.charAt(16); int minute = applyMinuteOffset(offset, decodeNumber(minuteHigh, minuteLow)); char secondHigh = chars.charAt(18); char secondLow = chars.charAt(19); int second = decodeNumber(secondHigh, secondLow); GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"), Locale.US); calendar.clear(); calendar.set(year, month, day, hour, minute, second); return LocalDateTime.ofInstant(calendar.getTime().toInstant(), ZoneId.systemDefault()); } else { final String message; if (chars == null) { message = "Expected a date-time but was nothing."; } else { message = new StringBuffer("Expected a date-time but was ").append(chars.toString()).toString(); } throw new DecodingException(HumanReadableText.ILLEGAL_ARGUMENTS, message); } }
DecoderUtils { public static LocalDateTime decodeDateTime(CharSequence chars) throws DecodingException { if (isDateTime(chars)) { char dayHigh = chars.charAt(0); char dayLow = chars.charAt(1); int day = decodeFixedDay(dayHigh, dayLow); char monthFirstChar = chars.charAt(3); char monthSecondChar = chars.charAt(4); char monthThirdChar = chars.charAt(5); int month = decodeMonth(monthFirstChar, monthSecondChar, monthThirdChar); char milleniumChar = chars.charAt(7); char centuryChar = chars.charAt(8); char decadeChar = chars.charAt(9); char yearChar = chars.charAt(10); int year = decodeYear(milleniumChar, centuryChar, decadeChar, yearChar); char zoneDeterminent = chars.charAt(21); char zoneDigitOne = chars.charAt(22); char zoneDigitTwo = chars.charAt(23); char zoneDigitThree = chars.charAt(24); char zoneDigitFour = chars.charAt(25); int offset = decodeZone(zoneDeterminent, zoneDigitOne, zoneDigitTwo, zoneDigitThree, zoneDigitFour); char hourHigh = chars.charAt(12); char hourLow = chars.charAt(13); int hour = applyHourOffset(offset, decodeNumber(hourHigh, hourLow)); char minuteHigh = chars.charAt(15); char minuteLow = chars.charAt(16); int minute = applyMinuteOffset(offset, decodeNumber(minuteHigh, minuteLow)); char secondHigh = chars.charAt(18); char secondLow = chars.charAt(19); int second = decodeNumber(secondHigh, secondLow); GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"), Locale.US); calendar.clear(); calendar.set(year, month, day, hour, minute, second); return LocalDateTime.ofInstant(calendar.getTime().toInstant(), ZoneId.systemDefault()); } else { final String message; if (chars == null) { message = "Expected a date-time but was nothing."; } else { message = new StringBuffer("Expected a date-time but was ").append(chars.toString()).toString(); } throw new DecodingException(HumanReadableText.ILLEGAL_ARGUMENTS, message); } } }
DecoderUtils { public static LocalDateTime decodeDateTime(CharSequence chars) throws DecodingException { if (isDateTime(chars)) { char dayHigh = chars.charAt(0); char dayLow = chars.charAt(1); int day = decodeFixedDay(dayHigh, dayLow); char monthFirstChar = chars.charAt(3); char monthSecondChar = chars.charAt(4); char monthThirdChar = chars.charAt(5); int month = decodeMonth(monthFirstChar, monthSecondChar, monthThirdChar); char milleniumChar = chars.charAt(7); char centuryChar = chars.charAt(8); char decadeChar = chars.charAt(9); char yearChar = chars.charAt(10); int year = decodeYear(milleniumChar, centuryChar, decadeChar, yearChar); char zoneDeterminent = chars.charAt(21); char zoneDigitOne = chars.charAt(22); char zoneDigitTwo = chars.charAt(23); char zoneDigitThree = chars.charAt(24); char zoneDigitFour = chars.charAt(25); int offset = decodeZone(zoneDeterminent, zoneDigitOne, zoneDigitTwo, zoneDigitThree, zoneDigitFour); char hourHigh = chars.charAt(12); char hourLow = chars.charAt(13); int hour = applyHourOffset(offset, decodeNumber(hourHigh, hourLow)); char minuteHigh = chars.charAt(15); char minuteLow = chars.charAt(16); int minute = applyMinuteOffset(offset, decodeNumber(minuteHigh, minuteLow)); char secondHigh = chars.charAt(18); char secondLow = chars.charAt(19); int second = decodeNumber(secondHigh, secondLow); GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"), Locale.US); calendar.clear(); calendar.set(year, month, day, hour, minute, second); return LocalDateTime.ofInstant(calendar.getTime().toInstant(), ZoneId.systemDefault()); } else { final String message; if (chars == null) { message = "Expected a date-time but was nothing."; } else { message = new StringBuffer("Expected a date-time but was ").append(chars.toString()).toString(); } throw new DecodingException(HumanReadableText.ILLEGAL_ARGUMENTS, message); } }  }
DecoderUtils { public static LocalDateTime decodeDateTime(CharSequence chars) throws DecodingException { if (isDateTime(chars)) { char dayHigh = chars.charAt(0); char dayLow = chars.charAt(1); int day = decodeFixedDay(dayHigh, dayLow); char monthFirstChar = chars.charAt(3); char monthSecondChar = chars.charAt(4); char monthThirdChar = chars.charAt(5); int month = decodeMonth(monthFirstChar, monthSecondChar, monthThirdChar); char milleniumChar = chars.charAt(7); char centuryChar = chars.charAt(8); char decadeChar = chars.charAt(9); char yearChar = chars.charAt(10); int year = decodeYear(milleniumChar, centuryChar, decadeChar, yearChar); char zoneDeterminent = chars.charAt(21); char zoneDigitOne = chars.charAt(22); char zoneDigitTwo = chars.charAt(23); char zoneDigitThree = chars.charAt(24); char zoneDigitFour = chars.charAt(25); int offset = decodeZone(zoneDeterminent, zoneDigitOne, zoneDigitTwo, zoneDigitThree, zoneDigitFour); char hourHigh = chars.charAt(12); char hourLow = chars.charAt(13); int hour = applyHourOffset(offset, decodeNumber(hourHigh, hourLow)); char minuteHigh = chars.charAt(15); char minuteLow = chars.charAt(16); int minute = applyMinuteOffset(offset, decodeNumber(minuteHigh, minuteLow)); char secondHigh = chars.charAt(18); char secondLow = chars.charAt(19); int second = decodeNumber(secondHigh, secondLow); GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"), Locale.US); calendar.clear(); calendar.set(year, month, day, hour, minute, second); return LocalDateTime.ofInstant(calendar.getTime().toInstant(), ZoneId.systemDefault()); } else { final String message; if (chars == null) { message = "Expected a date-time but was nothing."; } else { message = new StringBuffer("Expected a date-time but was ").append(chars.toString()).toString(); } throw new DecodingException(HumanReadableText.ILLEGAL_ARGUMENTS, message); } }  static void setFlag(String flagString, Flags flags); static LocalDateTime decodeDateTime(CharSequence chars); static int decodeNumber(char high, char low); static int decodeZone(char zoneDeterminent, char zoneDigitOne, char zoneDigitTwo, char zoneDigitThree, char zoneDigitFour); static boolean isSimpleDigit(char character); static int decodeYear(char milleniumChar, char centuryChar, char decadeChar, char yearChar); static int decodeMonth(char monthFirstChar, char monthSecondChar, char monthThirdChar); static int decodeFixedDay(char dayHigh, char dayLow); static int decodeDigit(char character); }
DecoderUtils { public static LocalDateTime decodeDateTime(CharSequence chars) throws DecodingException { if (isDateTime(chars)) { char dayHigh = chars.charAt(0); char dayLow = chars.charAt(1); int day = decodeFixedDay(dayHigh, dayLow); char monthFirstChar = chars.charAt(3); char monthSecondChar = chars.charAt(4); char monthThirdChar = chars.charAt(5); int month = decodeMonth(monthFirstChar, monthSecondChar, monthThirdChar); char milleniumChar = chars.charAt(7); char centuryChar = chars.charAt(8); char decadeChar = chars.charAt(9); char yearChar = chars.charAt(10); int year = decodeYear(milleniumChar, centuryChar, decadeChar, yearChar); char zoneDeterminent = chars.charAt(21); char zoneDigitOne = chars.charAt(22); char zoneDigitTwo = chars.charAt(23); char zoneDigitThree = chars.charAt(24); char zoneDigitFour = chars.charAt(25); int offset = decodeZone(zoneDeterminent, zoneDigitOne, zoneDigitTwo, zoneDigitThree, zoneDigitFour); char hourHigh = chars.charAt(12); char hourLow = chars.charAt(13); int hour = applyHourOffset(offset, decodeNumber(hourHigh, hourLow)); char minuteHigh = chars.charAt(15); char minuteLow = chars.charAt(16); int minute = applyMinuteOffset(offset, decodeNumber(minuteHigh, minuteLow)); char secondHigh = chars.charAt(18); char secondLow = chars.charAt(19); int second = decodeNumber(secondHigh, secondLow); GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"), Locale.US); calendar.clear(); calendar.set(year, month, day, hour, minute, second); return LocalDateTime.ofInstant(calendar.getTime().toInstant(), ZoneId.systemDefault()); } else { final String message; if (chars == null) { message = "Expected a date-time but was nothing."; } else { message = new StringBuffer("Expected a date-time but was ").append(chars.toString()).toString(); } throw new DecodingException(HumanReadableText.ILLEGAL_ARGUMENTS, message); } }  static void setFlag(String flagString, Flags flags); static LocalDateTime decodeDateTime(CharSequence chars); static int decodeNumber(char high, char low); static int decodeZone(char zoneDeterminent, char zoneDigitOne, char zoneDigitTwo, char zoneDigitThree, char zoneDigitFour); static boolean isSimpleDigit(char character); static int decodeYear(char milleniumChar, char centuryChar, char decadeChar, char yearChar); static int decodeMonth(char monthFirstChar, char monthSecondChar, char monthThirdChar); static int decodeFixedDay(char dayHigh, char dayLow); static int decodeDigit(char character);  }