in core/src/main/java/com/alibaba/fastjson2/util/DateUtils.java [6961:7295]
public static long parseMillis19(char[] bytes, int off, ZoneId zoneId) {
if (bytes == null) {
throw new NullPointerException();
}
char c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18;
c0 = bytes[off];
c1 = bytes[off + 1];
c2 = bytes[off + 2];
c3 = bytes[off + 3];
c4 = bytes[off + 4];
c5 = bytes[off + 5];
c6 = bytes[off + 6];
c7 = bytes[off + 7];
c8 = bytes[off + 8];
c9 = bytes[off + 9];
c10 = bytes[off + 10];
c11 = bytes[off + 11];
c12 = bytes[off + 12];
c13 = bytes[off + 13];
c14 = bytes[off + 14];
c15 = bytes[off + 15];
c16 = bytes[off + 16];
c17 = bytes[off + 17];
c18 = bytes[off + 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 == '/') || (c2 == '-' && c5 == '-') || (c2 == '.' && c5 == '.'))
&& c10 == ' '
&& c13 == ':' && c16 == ':') {
// dd/MM/yyyy HH:mm:ss
// dd-MM-yyyy HH:mm:ss
// 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 {
String str = new String(bytes, off, 19);
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 {
String str = new String(bytes, off, 19);
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 {
String str = new String(bytes, off, 19);
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 {
String str = new String(bytes, off, 19);
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 {
String str = new String(bytes, off, 19);
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 {
String str = new String(bytes, off, 19);
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) {
String str = new String(bytes, off, 19);
throw new DateTimeParseException("illegal input " + str, str, 0);
}
} else {
String str = new String(bytes, off, 19);
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) {
String str = new String(bytes, off, 19);
throw new DateTimeParseException("illegal input " + str, str, 0);
}
} else {
String str = new String(bytes, off, 19);
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 {
String str = new String(bytes, off, 19);
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 {
String str = new String(bytes, off, 19);
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 {
String str = new String(bytes, off, 19);
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;
}