summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/util')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/util/DateUtil.java13
-rw-r--r--src/main/java/com/keuin/kbackupfabric/util/FilesystemUtil.java11
2 files changed, 20 insertions, 4 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/util/DateUtil.java b/src/main/java/com/keuin/kbackupfabric/util/DateUtil.java
index b101cfd..7111347 100644
--- a/src/main/java/com/keuin/kbackupfabric/util/DateUtil.java
+++ b/src/main/java/com/keuin/kbackupfabric/util/DateUtil.java
@@ -1,13 +1,18 @@
package com.keuin.kbackupfabric.util;
+import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
+import java.util.Date;
public class DateUtil {
+
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss");
+ private static final SimpleDateFormat outFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ private static final DateTimeFormatter prettyFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
public static String getString(LocalDateTime localDateTime) {
return localDateTime.format(formatter);
@@ -28,4 +33,12 @@ public class DateUtil {
public static LocalDateTime toLocalDateTime(String timeString) {
return LocalDateTime.parse(timeString, formatter);
}
+
+ public static String fromEpochMillis(long epochMillis) {
+ return outFormatter.format(new Date(epochMillis));
+ }
+
+ public static String getPrettyString(LocalDateTime localDateTime) {
+ return prettyFormatter.format(localDateTime);
+ }
}
diff --git a/src/main/java/com/keuin/kbackupfabric/util/FilesystemUtil.java b/src/main/java/com/keuin/kbackupfabric/util/FilesystemUtil.java
index f245cff..bccd403 100644
--- a/src/main/java/com/keuin/kbackupfabric/util/FilesystemUtil.java
+++ b/src/main/java/com/keuin/kbackupfabric/util/FilesystemUtil.java
@@ -15,19 +15,22 @@ public class FilesystemUtil {
*/
public static long getFileSizeBytes(String parentDirectory, String fileName) {
long fileSize = -1;
- try{
+ try {
File backupZipFile = new File(parentDirectory, fileName);
fileSize = backupZipFile.length();
- } catch (SecurityException ignored){
+ } catch (SecurityException ignored) {
}
return fileSize;
}
public static long getFileSizeBytes(String filePath) {
+ return getFileSizeBytes(new File(filePath));
+ }
+
+ public static long getFileSizeBytes(File file) {
long fileSize = -1;
try {
- File backupZipFile = new File(filePath);
- fileSize = backupZipFile.length();
+ fileSize = file.length();
} catch (SecurityException ignored) {
}
return fileSize;