in core/src/main/java/com/alibaba/fastjson2/util/DateUtils.java [6230:6624]
public static long parseMillis19(String str, ZoneId zoneId) {
if (str == null) {
throw new NullPointerException();
}
char c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18;
if (JVM_VERSION == 8) {
char[] chars = JDKUtils.getCharArray(str);
if (chars.length != 19) {
throw new DateTimeParseException("illegal input " + str, str, 0);
}
c0 = chars[0];
c1 = chars[1];
c2 = chars[2];
c3 = chars[3];
c4 = chars[4];
c5 = chars[5];
c6 = chars[6];
c7 = chars[7];
c8 = chars[8];
c9 = chars[9];
c10 = chars[10];
c11 = chars[11];
c12 = chars[12];
c13 = chars[13];
c14 = chars[14];
c15 = chars[15];
c16 = chars[16];
c17 = chars[17];
c18 = chars[18];
} else if (STRING_CODER != null && STRING_VALUE != null && STRING_CODER.applyAsInt(str) == 0) {
byte[] chars = JDKUtils.STRING_VALUE.apply(str);
if (chars.length != 19) {
throw new DateTimeParseException("illegal input " + str, str, 0);
}
c0 = (char) chars[0];
c1 = (char) chars[1];
c2 = (char) chars[2];
c3 = (char) chars[3];
c4 = (char) chars[4];
c5 = (char) chars[5];
c6 = (char) chars[6];
c7 = (char) chars[7];
c8 = (char) chars[8];
c9 = (char) chars[9];
c10 = (char) chars[10];
c11 = (char) chars[11];
c12 = (char) chars[12];
c13 = (char) chars[13];
c14 = (char) chars[14];
c15 = (char) chars[15];
c16 = (char) chars[16];
c17 = (char) chars[17];
c18 = (char) chars[18];
} else {
if (str.length() != 19) {
throw new DateTimeParseException("illegal input " + str, str, 0);
}
c0 = str.charAt(0);
c1 = str.charAt(1);
c2 = str.charAt(2);
c3 = str.charAt(3);
c4 = str.charAt(4);
c5 = str.charAt(5);
c6 = str.charAt(6);
c7 = str.charAt(7);
c8 = str.charAt(8);
c9 = str.charAt(9);
c10 = str.charAt(10);
c11 = str.charAt(11);
c12 = str.charAt(12);
c13 = str.charAt(13);
c14 = str.charAt(14);
c15 = str.charAt(15);
c16 = str.charAt(16);
c17 = str.charAt(17);
c18 = str.charAt(18);
}
char y0, y1, y2, y3, m0, m1, d0, d1, h0, h1, i0, i1, s0, s1;
if (c4 == '-' && c7 == '-' && (c10 == ' ' || c10 == 'T') && c13 == ':' && c16 == ':') {
// yyyy-MM-dd HH:mm:ss
// yyyy-MM-dd'T'HH:mm:ss
y0 = c0;
y1 = c1;
y2 = c2;
y3 = c3;
m0 = c5;
m1 = c6;
d0 = c8;
d1 = c9;
h0 = c11;
h1 = c12;
i0 = c14;
i1 = c15;
s0 = c17;
s1 = c18;
} else if (c4 == '/' && c7 == '/' && (c10 == ' ' || c10 == 'T') && c13 == ':' && c16 == ':') {
// yyyy/MM/dd HH:mm:ss
// yyyy/MM/dd'T'HH:mm:ss
y0 = c0;
y1 = c1;
y2 = c2;
y3 = c3;
m0 = c5;
m1 = c6;
d0 = c8;
d1 = c9;
h0 = c11;
h1 = c12;
i0 = c14;
i1 = c15;
s0 = c17;
s1 = c18;
} else if (c2 == '/' && c5 == '/' && c10 == ' ' && c13 == ':' && c16 == ':') {
// dd/MM/yyyy HH:mm:ss
d0 = c0;
d1 = c1;
m0 = c3;
m1 = c4;
y0 = c6;
y1 = c7;
y2 = c8;
y3 = c9;
h0 = c11;
h1 = c12;
i0 = c14;
i1 = c15;
s0 = c17;
s1 = c18;
} else if (c2 == '.' && c5 == '.' && c10 == ' ' && c13 == ':' && c16 == ':') {
// dd.MM.yyyy HH:mm:ss
d0 = c0;
d1 = c1;
m0 = c3;
m1 = c4;
y0 = c6;
y1 = c7;
y2 = c8;
y3 = c9;
h0 = c11;
h1 = c12;
i0 = c14;
i1 = c15;
s0 = c17;
s1 = c18;
} else if (c1 == ' ' && c5 == ' ' && c10 == ' ' && c13 == ':' && c16 == ':') {
// d MMM yyyy HH:mm:ss
// 6 DEC 2020 12:13:14
d0 = '0';
d1 = c0;
int month = DateUtils.month(c2, c3, c4);
if (month > 0) {
m0 = (char) ('0' + month / 10);
m1 = (char) ('0' + (month % 10));
} else {
throw new DateTimeParseException("illegal input " + str, str, 0);
}
y0 = c6;
y1 = c7;
y2 = c8;
y3 = c9;
h0 = c11;
h1 = c12;
i0 = c14;
i1 = c15;
s0 = c17;
s1 = c18;
} else if (c2 == ' ' && c6 == ' ' && c11 == ' ' && c13 == ':' && c16 == ':') {
// dd MMM yyyy H:mm:ss
// 16 DEC 2020 2:13:14
d0 = c0;
d1 = c1;
int month = DateUtils.month(c3, c4, c5);
if (month > 0) {
m0 = (char) ('0' + month / 10);
m1 = (char) ('0' + (month % 10));
} else {
throw new DateTimeParseException("illegal input " + str, str, 0);
}
y0 = c7;
y1 = c8;
y2 = c9;
y3 = c10;
h0 = '0';
h1 = c12;
i0 = c14;
i1 = c15;
s0 = c17;
s1 = c18;
} else if (c2 == ' ' && c6 == ' ' && c11 == ' ' && c14 == ':' && c16 == ':') {
// dd MMM yyyy HH:m:ss
// 16 DEC 2020 12:3:14
d0 = c0;
d1 = c1;
int month = DateUtils.month(c3, c4, c5);
if (month > 0) {
m0 = (char) ('0' + month / 10);
m1 = (char) ('0' + (month % 10));
} else {
throw new DateTimeParseException("illegal input " + str, str, 0);
}
y0 = c7;
y1 = c8;
y2 = c9;
y3 = c10;
h0 = c12;
h1 = c13;
i0 = '0';
i1 = c15;
s0 = c17;
s1 = c18;
} else if (c2 == ' ' && c6 == ' ' && c11 == ' ' && c14 == ':' && c17 == ':') {
// dd MMM yyyy HH:m:ss
// 16 DEC 2020 12:3:14
d0 = c0;
d1 = c1;
int month = DateUtils.month(c3, c4, c5);
if (month > 0) {
m0 = (char) ('0' + month / 10);
m1 = (char) ('0' + (month % 10));
} else {
throw new DateTimeParseException("illegal input " + str, str, 0);
}
y0 = c7;
y1 = c8;
y2 = c9;
y3 = c10;
h0 = c12;
h1 = c13;
i0 = c15;
i1 = c16;
s0 = '0';
s1 = c18;
} else {
throw new DateTimeParseException("illegal input " + str, str, 0);
}
int year;
if (y0 >= '0' && y0 <= '9'
&& y1 >= '0' && y1 <= '9'
&& y2 >= '0' && y2 <= '9'
&& y3 >= '0' && y3 <= '9'
) {
year = (y0 - '0') * 1000 + (y1 - '0') * 100 + (y2 - '0') * 10 + (y3 - '0');
} else {
throw new DateTimeParseException("illegal input " + str, str, 0);
}
int month;
if (m0 >= '0' && m0 <= '9'
&& m1 >= '0' && m1 <= '9'
) {
month = (m0 - '0') * 10 + (m1 - '0');
if ((month == 0 && year != 0) || month > 12) {
throw new DateTimeParseException("illegal input " + str, str, 0);
}
} else {
throw new DateTimeParseException("illegal input " + str, str, 0);
}
int dom;
if (d0 >= '0' && d0 <= '9'
&& d1 >= '0' && d1 <= '9'
) {
dom = (d0 - '0') * 10 + (d1 - '0');
int max = 31;
switch (month) {
case 2:
boolean leapYear = (year & 3) == 0 && ((year % 100) != 0 || (year % 400) == 0);
max = leapYear ? 29 : 28;
break;
case 4:
case 6:
case 9:
case 11:
max = 30;
break;
}
if ((dom == 0 && year != 0) || dom > max) {
throw new DateTimeParseException("illegal input " + str, str, 0);
}
} else {
throw new DateTimeParseException("illegal input " + str, str, 0);
}
int hour;
if (h0 >= '0' && h0 <= '9'
&& h1 >= '0' && h1 <= '9'
) {
hour = (h0 - '0') * 10 + (h1 - '0');
} else {
throw new DateTimeParseException("illegal input " + str, str, 0);
}
int minute;
if (i0 >= '0' && i0 <= '9'
&& i1 >= '0' && i1 <= '9'
) {
minute = (i0 - '0') * 10 + (i1 - '0');
} else {
throw new DateTimeParseException("illegal input " + str, str, 0);
}
int second;
if (s0 >= '0' && s0 <= '9'
&& s1 >= '0' && s1 <= '9'
) {
second = (s0 - '0') * 10 + (s1 - '0');
} else {
throw new DateTimeParseException("illegal input " + str, str, 0);
}
if (year == 0 && month == 0 && dom == 0) {
year = 1970;
month = 1;
dom = 1;
}
long utcSeconds;
{
long epochDay = calcEpochDay(year, month, dom);
utcSeconds = epochDay * 86400
+ hour * 3600
+ minute * 60
+ second;
}
int zoneOffsetTotalSeconds;
if (zoneId == null) {
zoneId = DEFAULT_ZONE_ID;
}
boolean shanghai = zoneId == SHANGHAI_ZONE_ID || zoneId.getRules() == SHANGHAI_ZONE_RULES;
long SECONDS_1991_09_15_02 = 684900000; // utcMillis(1991, 9, 15, 2, 0, 0);
if (shanghai && utcSeconds >= SECONDS_1991_09_15_02) {
zoneOffsetTotalSeconds = 28800; // OFFSET_0800_TOTAL_SECONDS
} else if (zoneId == ZoneOffset.UTC || "UTC".equals(zoneId.getId())) {
zoneOffsetTotalSeconds = 0;
} else {
LocalDate localDate = LocalDate.of(year, month, dom);
LocalTime localTime = LocalTime.of(hour, minute, second, 0);
LocalDateTime ldt = LocalDateTime.of(localDate, localTime);
ZoneOffset offset = zoneId.getRules().getOffset(ldt);
zoneOffsetTotalSeconds = offset.getTotalSeconds();
}
return (utcSeconds - zoneOffsetTotalSeconds) * 1000L;
}