Skip to content

Commit

Permalink
fix Math.floorDiv compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Nov 17, 2024
1 parent 6c68b0e commit cda9e5d
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions core/src/main/java/com/alibaba/fastjson2/util/DateUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cda9e5d

Please sign in to comment.