TradeSystem icon indicating copy to clipboard operation
TradeSystem copied to clipboard

Cleanup System for trade logs

Open erikzimmermann opened this issue 4 years ago • 0 comments

Config option for cleanup cycle. Please use this time format: "0d, 0h, 0m, 0s" - Unnecessary values can be removed (examples: "1d, 5m", "10s", "5h")!

public static long convertFromTimeFormat(String text) throws NumberFormatException {
    long d = 0, h = 0, m = 0, s = 0;

    text = text.trim().toLowerCase();

    if(text.contains("d")) {
        String[] a = text.split("d")[0].split(" ");
        d = Long.parseLong(a[a.length - 1]);
    }

    if(text.contains("h")) {
        String[] a = text.split("h")[0].split(" ");
        h = Long.parseLong(a[a.length - 1]);
    }

    if(text.contains("m")) {
        String[] a = text.split("m")[0].split(" ");
        m = Long.parseLong(a[a.length - 1]);
    }

    if(text.contains("s")) {
        String[] a = text.split("s")[0].split(" ");
        s = Long.parseLong(a[a.length - 1]);
    }

    return TimeUnit.MILLISECONDS.convert(d, TimeUnit.DAYS) + TimeUnit.MILLISECONDS.convert(h, TimeUnit.HOURS) + TimeUnit.MILLISECONDS.convert(m, TimeUnit.MINUTES) + TimeUnit.MILLISECONDS.convert(s, TimeUnit.SECONDS);
}

erikzimmermann avatar Sep 21 '20 09:09 erikzimmermann