Skip to content

Commit

Permalink
optimize:optimize the magic num of date at UUIDGenerator (apache#2400)
Browse files Browse the repository at this point in the history
  • Loading branch information
lightClouds917 committed Mar 15, 2020
1 parent e007cd4 commit c35082c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion server/src/main/java/io/seata/server/UUIDGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.atomic.AtomicLong;
Expand Down Expand Up @@ -103,7 +105,9 @@ public static void init(int serverNodeId) {
UUID.set(UUID_INTERNAL * serverNodeId);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
Date date = format.parse("2019-01-01");
String firstDayOfYear = LocalDate.now()
.with(TemporalAdjusters.firstDayOfYear()).toString();
Date date = format.parse(firstDayOfYear);
cal.setTime(date);
long base = cal.getTimeInMillis();
long current = System.currentTimeMillis();
Expand Down

0 comments on commit c35082c

Please sign in to comment.