提交 468f649d authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Rename setCalendarFields() to convertToMillis() and return time in millis

上级 84877c3d
...@@ -168,10 +168,9 @@ public class DateTimeUtils { ...@@ -168,10 +168,9 @@ public class DateTimeUtils {
cal.clear(); cal.clear();
cal.setLenient(true); cal.setLenient(true);
long dateValue = d.getDateValue(); long dateValue = d.getDateValue();
setCalendarFields(cal, yearFromDateValue(dateValue), long ms = convertToMillis(cal, yearFromDateValue(dateValue),
monthFromDateValue(dateValue), dayFromDateValue(dateValue), 0, monthFromDateValue(dateValue), dayFromDateValue(dateValue), 0,
0, 0, 0); 0, 0, 0);
long ms = cal.getTimeInMillis();
return new Date(ms); return new Date(ms);
} }
...@@ -199,10 +198,7 @@ public class DateTimeUtils { ...@@ -199,10 +198,7 @@ public class DateTimeUtils {
s -= m * 60; s -= m * 60;
long h = m / 60; long h = m / 60;
m -= h * 60; m -= h * 60;
setCalendarFields(cal, 1970, 1, 1, (int) h, (int) m, (int) s, return new Time(convertToMillis(cal, 1970, 1, 1, (int) h, (int) m, (int) s, (int) millis));
(int) millis);
long ms = cal.getTimeInMillis();
return new Time(ms);
} }
/** /**
...@@ -230,10 +226,9 @@ public class DateTimeUtils { ...@@ -230,10 +226,9 @@ public class DateTimeUtils {
s -= m * 60; s -= m * 60;
long h = m / 60; long h = m / 60;
m -= h * 60; m -= h * 60;
setCalendarFields(cal, yearFromDateValue(dateValue), long ms = convertToMillis(cal, yearFromDateValue(dateValue),
monthFromDateValue(dateValue), dayFromDateValue(dateValue), monthFromDateValue(dateValue), dayFromDateValue(dateValue),
(int) h, (int) m, (int) s, (int) millis); (int) h, (int) m, (int) s, (int) millis);
long ms = cal.getTimeInMillis();
Timestamp x = new Timestamp(ms); Timestamp x = new Timestamp(ms);
x.setNanos((int) (nanos + millis * 1000000)); x.setNanos((int) (nanos + millis * 1000000));
return x; return x;
...@@ -473,12 +468,11 @@ public class DateTimeUtils { ...@@ -473,12 +468,11 @@ public class DateTimeUtils {
c = getCalendar(tz); c = getCalendar(tz);
} }
c.setLenient(lenient); c.setLenient(lenient);
setCalendarFields(c, year, month, day, hour, minute, second, millis); return convertToMillis(c, year, month, day, hour, minute, second, millis);
return c.getTimeInMillis();
} }
private static void setCalendarFields(Calendar cal, int year, int month, static long convertToMillis(Calendar cal, int year, int month, int day,
int day, int hour, int minute, int second, int millis) { int hour, int minute, int second, int millis) {
if (year <= 0) { if (year <= 0) {
cal.set(Calendar.ERA, GregorianCalendar.BC); cal.set(Calendar.ERA, GregorianCalendar.BC);
cal.set(Calendar.YEAR, 1 - year); cal.set(Calendar.YEAR, 1 - year);
...@@ -493,6 +487,7 @@ public class DateTimeUtils { ...@@ -493,6 +487,7 @@ public class DateTimeUtils {
cal.set(Calendar.MINUTE, minute); cal.set(Calendar.MINUTE, minute);
cal.set(Calendar.SECOND, second); cal.set(Calendar.SECOND, second);
cal.set(Calendar.MILLISECOND, millis); cal.set(Calendar.MILLISECOND, millis);
return cal.getTimeInMillis();
} }
/** /**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论