From b692a73e039fbdb404ef1219785660dc9eb60e60 Mon Sep 17 00:00:00 2001 From: Keuin Date: Fri, 24 Apr 2020 11:55:18 +0800 Subject: Added /kb delete for deleting an backup (with auto-complete supported). Command /kb confirm now confirms both /kb restore and /kb delete. Added /kb prev for easily check out the latest backup. --- .../util/BackupNameTimeFormatter.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main/java/com/keuin/kbackupfabric/util/BackupNameTimeFormatter.java (limited to 'src/main/java/com/keuin/kbackupfabric/util/BackupNameTimeFormatter.java') diff --git a/src/main/java/com/keuin/kbackupfabric/util/BackupNameTimeFormatter.java b/src/main/java/com/keuin/kbackupfabric/util/BackupNameTimeFormatter.java new file mode 100644 index 0000000..5d00270 --- /dev/null +++ b/src/main/java/com/keuin/kbackupfabric/util/BackupNameTimeFormatter.java @@ -0,0 +1,22 @@ +package com.keuin.kbackupfabric.util; + +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; + +public class BackupNameTimeFormatter { + private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss"); + + public static String getTimeString() { + return LocalDateTime.now().format(formatter); + } + + public static long timeStringToEpochSeconds(String timeString) { + ZoneId systemZone = ZoneId.systemDefault(); // my timezone + LocalDateTime localDateTime = LocalDateTime.parse(timeString, formatter); + ZoneOffset currentOffsetForMyZone = systemZone.getRules().getOffset(localDateTime); + return localDateTime.toEpochSecond(currentOffsetForMyZone); + } + +} -- cgit v1.2.3