From cda9e5dfa097790f04050aa909784af51d4e0675 Mon Sep 17 00:00:00 2001 From: wenshao Date: Sun, 17 Nov 2024 20:24:13 +0800 Subject: [PATCH] fix Math.floorDiv compatible --- .../com/alibaba/fastjson2/benchmark/DateWrite.java | 6 +++--- .../com/alibaba/fastjson2/support/csv/CSVWriter.java | 2 +- .../java/com/alibaba/fastjson2/util/DateUtils.java | 12 ++++++------ .../com/alibaba/fastjson2/writer/FieldWriter.java | 2 +- .../alibaba/fastjson2/writer/FieldWriterDate.java | 2 +- .../fastjson2/writer/ObjectWriterImplDate.java | 2 +- .../fastjson2/writer/ObjectWriterImplInstant.java | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/DateWrite.java b/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/DateWrite.java index 93361b331..ceb3870ed 100644 --- a/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/DateWrite.java +++ b/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/DateWrite.java @@ -78,7 +78,7 @@ public void formatYYYYMMDDHHMMSS19(Blackhole bh) throws Throwable { static String formatYYYYMMDDHHMMSS19(ZoneId zoneId, Date date) throws Throwable { long millis = date.getTime(); - final int SECONDS_PER_DAY = 60 * 60 * 24; + final long SECONDS_PER_DAY = 60 * 60 * 24; long epochSecond = Math.floorDiv(millis, 1000L); int offsetTotalSeconds; @@ -90,8 +90,8 @@ static String formatYYYYMMDDHHMMSS19(ZoneId zoneId, Date date) throws Throwable } long localSecond = epochSecond + offsetTotalSeconds; - long localEpochDay = Math.floorDiv(localSecond, (long) SECONDS_PER_DAY); - int secsOfDay = (int) Math.floorMod(localSecond, (long) SECONDS_PER_DAY); + long localEpochDay = Math.floorDiv(localSecond, SECONDS_PER_DAY); + int secsOfDay = (int) Math.floorMod(localSecond, SECONDS_PER_DAY); int year, month, dayOfMonth; { final int DAYS_PER_CYCLE = 146097; diff --git a/core/src/main/java/com/alibaba/fastjson2/support/csv/CSVWriter.java b/core/src/main/java/com/alibaba/fastjson2/support/csv/CSVWriter.java index cc2fde841..8b29a2301 100644 --- a/core/src/main/java/com/alibaba/fastjson2/support/csv/CSVWriter.java +++ b/core/src/main/java/com/alibaba/fastjson2/support/csv/CSVWriter.java @@ -226,7 +226,7 @@ public void writeBigInteger(BigInteger value) { public final void writeDate(long millis) { ZoneId zoneId = this.zoneId; - final int SECONDS_PER_DAY = 60 * 60 * 24; + final long SECONDS_PER_DAY = 60 * 60 * 24; long epochSecond = Math.floorDiv(millis, 1000L); int offsetTotalSeconds; if (zoneId == DateUtils.SHANGHAI_ZONE_ID || zoneId.getRules() == DateUtils.SHANGHAI_ZONE_RULES) { diff --git a/core/src/main/java/com/alibaba/fastjson2/util/DateUtils.java b/core/src/main/java/com/alibaba/fastjson2/util/DateUtils.java index 7fa56e0c8..edcdf2139 100644 --- a/core/src/main/java/com/alibaba/fastjson2/util/DateUtils.java +++ b/core/src/main/java/com/alibaba/fastjson2/util/DateUtils.java @@ -41,7 +41,7 @@ public class DateUtils { static { final long timeMillis = System.currentTimeMillis(); ZoneId zoneId = DEFAULT_ZONE_ID; - final int SECONDS_PER_DAY = 60 * 60 * 24; + final long SECONDS_PER_DAY = 60 * 60 * 24; long epochSecond = Math.floorDiv(timeMillis, 1000L); int offsetTotalSeconds; @@ -10924,7 +10924,7 @@ public static String formatYMDHMS19(Date date, ZoneId zoneId) { zoneId = DEFAULT_ZONE_ID; } - final int SECONDS_PER_DAY = 60 * 60 * 24; + final long SECONDS_PER_DAY = 60 * 60 * 24; long epochSecond = Math.floorDiv(timeMillis, 1000L); int offsetTotalSeconds; @@ -11029,7 +11029,7 @@ public static String formatYMD8(Date date) { } public static String formatYMD8(long timeMillis, ZoneId zoneId) { - final int SECONDS_PER_DAY = 60 * 60 * 24; + final long SECONDS_PER_DAY = 60 * 60 * 24; long epochSecond = Math.floorDiv(timeMillis, 1000L); int offsetTotalSeconds; @@ -11199,7 +11199,7 @@ public static String formatYMD10(long timeMillis, ZoneId zoneId) { zoneId = DEFAULT_ZONE_ID; } - final int SECONDS_PER_DAY = 60 * 60 * 24; + final long SECONDS_PER_DAY = 60 * 60 * 24; long epochSecond = Math.floorDiv(timeMillis, 1000L); int offsetTotalSeconds; @@ -11572,7 +11572,7 @@ public static String format(Date date) { public static String format(long timeMillis, DateTimeFormatPattern pattern) { ZoneId zoneId = DEFAULT_ZONE_ID; - final int SECONDS_PER_DAY = 60 * 60 * 24; + final long SECONDS_PER_DAY = 60 * 60 * 24; long epochSecond = Math.floorDiv(timeMillis, 1000L); int offsetTotalSeconds; @@ -11733,7 +11733,7 @@ public static String toString(Date date) { } public static String toString(long timeMillis, boolean timeZone, ZoneId zoneId) { - final int SECONDS_PER_DAY = 60 * 60 * 24; + final long SECONDS_PER_DAY = 60 * 60 * 24; long epochSecond = Math.floorDiv(timeMillis, 1000L); int offsetTotalSeconds; diff --git a/core/src/main/java/com/alibaba/fastjson2/writer/FieldWriter.java b/core/src/main/java/com/alibaba/fastjson2/writer/FieldWriter.java index 137156345..36d48201d 100644 --- a/core/src/main/java/com/alibaba/fastjson2/writer/FieldWriter.java +++ b/core/src/main/java/com/alibaba/fastjson2/writer/FieldWriter.java @@ -707,7 +707,7 @@ public void writeDate(JSONWriter jsonWriter, boolean writeFieldName, long millis return; } - final int SECONDS_PER_DAY = 60 * 60 * 24; + final long SECONDS_PER_DAY = 60 * 60 * 24; JSONWriter.Context ctx = jsonWriter.context; if (isDateFormatMillis() || ctx.isDateFormatMillis()) { diff --git a/core/src/main/java/com/alibaba/fastjson2/writer/FieldWriterDate.java b/core/src/main/java/com/alibaba/fastjson2/writer/FieldWriterDate.java index 821d9be5f..b65027401 100644 --- a/core/src/main/java/com/alibaba/fastjson2/writer/FieldWriterDate.java +++ b/core/src/main/java/com/alibaba/fastjson2/writer/FieldWriterDate.java @@ -121,7 +121,7 @@ public void writeDate(JSONWriter jsonWriter, long timeMillis) { return; } - final int SECONDS_PER_DAY = 60 * 60 * 24; + final long SECONDS_PER_DAY = 60 * 60 * 24; JSONWriter.Context ctx = jsonWriter.context; diff --git a/core/src/main/java/com/alibaba/fastjson2/writer/ObjectWriterImplDate.java b/core/src/main/java/com/alibaba/fastjson2/writer/ObjectWriterImplDate.java index b8092cec1..3c714a6b1 100644 --- a/core/src/main/java/com/alibaba/fastjson2/writer/ObjectWriterImplDate.java +++ b/core/src/main/java/com/alibaba/fastjson2/writer/ObjectWriterImplDate.java @@ -111,7 +111,7 @@ public void write(JSONWriter jsonWriter, Object object, Object fieldName, Type f } if (dateFormat == null) { - final int SECONDS_PER_DAY = 60 * 60 * 24; + final long SECONDS_PER_DAY = 60 * 60 * 24; long epochSecond = Math.floorDiv(millis, 1000L); int offsetTotalSeconds; diff --git a/core/src/main/java/com/alibaba/fastjson2/writer/ObjectWriterImplInstant.java b/core/src/main/java/com/alibaba/fastjson2/writer/ObjectWriterImplInstant.java index b3f00592a..6cb040c03 100644 --- a/core/src/main/java/com/alibaba/fastjson2/writer/ObjectWriterImplInstant.java +++ b/core/src/main/java/com/alibaba/fastjson2/writer/ObjectWriterImplInstant.java @@ -43,7 +43,7 @@ public void write(JSONWriter jsonWriter, Object object, Object fieldName, Type f boolean yyyyMMddhhmmss19 = this.yyyyMMddhhmmss19 || (context.isFormatyyyyMMddhhmmss19() && this.format == null); if (yyyyMMddhhmmss14 || yyyyMMddhhmmss19 || yyyyMMdd8 || yyyyMMdd10) { - final int SECONDS_PER_DAY = 60 * 60 * 24; + final long SECONDS_PER_DAY = 60 * 60 * 24; ZoneId zoneId = context.getZoneId(); long epochSecond = instant.getEpochSecond(); int offsetTotalSeconds;