|
@@ -15,11 +15,7 @@ import java.util.regex.Pattern;
|
|
|
* Utility class built on top of {@link SimpleDateFormat}.
|
|
* Utility class built on top of {@link SimpleDateFormat}.
|
|
|
*/
|
|
*/
|
|
|
@UtilityClass
|
|
@UtilityClass
|
|
|
-public class FormatTime {
|
|
|
|
|
-
|
|
|
|
|
- private static final String DATE = "yyyy-MM-dd";
|
|
|
|
|
-
|
|
|
|
|
- private static final String TIME = "HH:mm:ss";
|
|
|
|
|
|
|
+public class DateTimeFormatUtils {
|
|
|
|
|
|
|
|
private static final String DATE_TIME = "yyyy-MM-dd HH:mm:ss";
|
|
private static final String DATE_TIME = "yyyy-MM-dd HH:mm:ss";
|
|
|
|
|
|
|
@@ -32,8 +28,9 @@ public class FormatTime {
|
|
|
* @param time time
|
|
* @param time time
|
|
|
* @return String
|
|
* @return String
|
|
|
*/
|
|
*/
|
|
|
- public static String asDate(Date time) {
|
|
|
|
|
- return asText(DATE, time);
|
|
|
|
|
|
|
+ public static String formatDate(Date time) {
|
|
|
|
|
+ // @todo test
|
|
|
|
|
+ return DateTimeFormat.DATE.formatDate(time.toInstant());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -42,8 +39,8 @@ public class FormatTime {
|
|
|
* @param time time
|
|
* @param time time
|
|
|
* @return String
|
|
* @return String
|
|
|
*/
|
|
*/
|
|
|
- public static String asTime(Date time) {
|
|
|
|
|
- return asText(TIME, time);
|
|
|
|
|
|
|
+ public static String formatTime(Date time) {
|
|
|
|
|
+ return DateTimeFormat.TIME.formatTime(time.toInstant());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -52,8 +49,8 @@ public class FormatTime {
|
|
|
* @param time time
|
|
* @param time time
|
|
|
* @return String
|
|
* @return String
|
|
|
*/
|
|
*/
|
|
|
- public static String asDateTime(Date time) {
|
|
|
|
|
- return asText(DATE_TIME, time);
|
|
|
|
|
|
|
+ public static String formatDateTime(Date time) {
|
|
|
|
|
+ return DateTimeFormat.DATETIME.format(time.toInstant());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -63,7 +60,7 @@ public class FormatTime {
|
|
|
* @param time time
|
|
* @param time time
|
|
|
* @return String
|
|
* @return String
|
|
|
*/
|
|
*/
|
|
|
- private static String asText(String pattern, Date time) {
|
|
|
|
|
|
|
+ private static String format(String pattern, Date time) {
|
|
|
return new SimpleDateFormat(pattern).format(time);
|
|
return new SimpleDateFormat(pattern).format(time);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -75,7 +72,7 @@ public class FormatTime {
|
|
|
* @param text text
|
|
* @param text text
|
|
|
* @return Duration
|
|
* @return Duration
|
|
|
*/
|
|
*/
|
|
|
- public static Duration asDuration(String text) {
|
|
|
|
|
|
|
+ public static Duration parseDuration(String text) {
|
|
|
Matcher hit = TIME_TO_MS.matcher(text.replace(',', '.'));
|
|
Matcher hit = TIME_TO_MS.matcher(text.replace(',', '.'));
|
|
|
if (hit.matches()) {
|
|
if (hit.matches()) {
|
|
|
double h = asNumber(hit.group(1));
|
|
double h = asNumber(hit.group(1));
|
|
@@ -100,8 +97,8 @@ public class FormatTime {
|
|
|
* @param duration duration
|
|
* @param duration duration
|
|
|
* @return String
|
|
* @return String
|
|
|
*/
|
|
*/
|
|
|
- public static String asText(Duration duration) {
|
|
|
|
|
- return asText(duration, ChronoUnit.MILLIS);
|
|
|
|
|
|
|
+ public static String formatDuration(Duration duration) {
|
|
|
|
|
+ return formatDuration(duration, ChronoUnit.MILLIS);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -118,7 +115,7 @@ public class FormatTime {
|
|
|
*
|
|
*
|
|
|
* @return String
|
|
* @return String
|
|
|
*/
|
|
*/
|
|
|
- public static String asText(Duration duration, TemporalUnit precision) {
|
|
|
|
|
|
|
+ public static String formatDuration(Duration duration, TemporalUnit precision) {
|
|
|
long ts = duration.getSeconds();
|
|
long ts = duration.getSeconds();
|
|
|
long tn = duration.getNano();
|
|
long tn = duration.getNano();
|
|
|
|
|
|