MCPcopy Create free account
hub / github.com/amazon-ion/ion-java / valueOf

Method valueOf

src/main/java/com/amazon/ion/Timestamp.java:962–1140  ·  view source on GitHub ↗

Returns a new Timestamp that represents the point in time, precision and local offset defined in Ion format by the CharSequence. @param ionFormattedTimestamp a sequence of characters that is the Ion representation of a Timestamp @throws IllegalArgumentException i

(CharSequence ionFormattedTimestamp)

Source from the content-addressed store, hash-verified

960 * @see <a href="http://www.w3.org/TR/NOTE-datetime">W3C Note on Date and Time Formats</a>
961 */
962 public static Timestamp valueOf(CharSequence ionFormattedTimestamp)
963 {
964 final CharSequence in = ionFormattedTimestamp;
965 int pos;
966
967 final int length = in.length();
968 if (length == 0)
969 {
970 throw fail(in);
971 }
972
973 // check for 'null.timestamp'
974 if (in.charAt(0) == 'n') {
975 if (length >= LEN_OF_NULL_IMAGE
976 && NULL_TIMESTAMP_IMAGE.contentEquals(in.subSequence(0, LEN_OF_NULL_IMAGE)))
977 {
978 if (length > LEN_OF_NULL_IMAGE) {
979 if (!isValidFollowChar(in.charAt(LEN_OF_NULL_IMAGE))) {
980 throw fail(in);
981 }
982 }
983 return null;
984 }
985 throw fail(in);
986 }
987
988 int year = 1;
989 int month = 1;
990 int day = 1;
991 int hour = 0;
992 int minute = 0;
993 int seconds = 0;
994 BigDecimal fraction = null;
995 Precision precision;
996
997 // fake label to turn goto's into a break so Java is happy :) enjoy
998 do {
999 // otherwise we expect yyyy-mm-ddThh:mm:ss.ssss+hh:mm
1000 if (length < END_OF_YEAR + 1) { // +1 for the "T"
1001 throw fail(in, "year is too short (must be at least yyyyT)");
1002 }
1003 pos = END_OF_YEAR;
1004 precision = Precision.YEAR;
1005 year = read_digits(in, 0, 4, -1, "year");
1006
1007 char c = in.charAt(END_OF_YEAR);
1008 if (c == 'T') break;
1009 if (c != '-') {
1010 throw fail(in,
1011 "expected \"-\" between year and month, found "
1012 + printCodePointAsString(c));
1013 }
1014 if (length < END_OF_MONTH + 1) { // +1 for the "T"
1015 throw fail(in, "month is too short (must be yyyy-mmT)");
1016 }
1017 pos = END_OF_MONTH;
1018 precision = Precision.MONTH;
1019 month = read_digits(in, END_OF_YEAR + 1, 2, -1, "month");

Calls 7

failMethod · 0.95
isValidFollowCharMethod · 0.95
read_digitsMethod · 0.95
lengthMethod · 0.80
toStringMethod · 0.65
isDigitMethod · 0.45