package net.northking.cctp.device.util.prometheus;


import java.util.Date;

public class MonitorTools {

    public static String getInstance(Date startTime, Date endTime) {
        long between = endTime.getTime() / 1000 - startTime.getTime() / 1000;
        String instance = "";
        if (between <= 30) {
            return "30s";
        }
        if (between >= 365 * 24 * 60 * 60) {
            instance = instance + between / (365 * 24 * 60 * 60) + "y";
            between = between % (365 * 24 * 60 * 60);
        }
        if (between >= 24 * 60 * 60) {
            instance = instance + between / (24 * 60 * 60) + "d";
            between = between % (24 * 60 * 60);
        }
        if (between >= 60 * 60) {
            instance = instance + between / (60 * 60) + "h";
            between = between % (60 * 60);
        }
        if (between >= 60) {
            instance = instance + between / 60 + "m";
            between = between % 60;
        }
        if (between > 0) {
            instance = instance + between + "s";
        }
        return instance;
    }
}
