Example usage for org.apache.commons.lang3.time DurationFormatUtils formatDuration

List of usage examples for org.apache.commons.lang3.time DurationFormatUtils formatDuration

Introduction

In this page you can find the example usage for org.apache.commons.lang3.time DurationFormatUtils formatDuration.

Prototype

public static String formatDuration(final long durationMillis, final String format,
        final boolean padWithZeros) 

Source Link

Document

Formats the time gap as a string, using the specified format.

Usage

From source file:de.quadrillenschule.azocamsynca.helpers.Formats.java

public static String toString(long time) {
    return DurationFormatUtils.formatDuration(time, DF, true);

}

From source file:me.bramhaag.discordselfbot.commands.util.CommandTimer.java

@Command(name = "timer", minArgs = 1)
public void execute(@NonNull Message message, @NonNull TextChannel channel, @NonNull String[] args) {
    long delay;//ww  w . java  2  s.c o m

    try {
        delay = Long.valueOf(args[0]);
    } catch (NumberFormatException e) {
        Util.sendError(message, e.toString());
        return;
    }

    message.editMessage(new EmbedBuilder().setTitle("Timer", null)
            .setDescription(
                    "Timer ending in " + DurationFormatUtils.formatDuration(delay * 1000, "H:mm:ss", true))
            .setFooter("Timer | " + Util.generateTimestamp(), null).setColor(Color.GREEN).build()).queue();

    channel.sendMessage(new EmbedBuilder().setTitle("Timer", null).setDescription("Timer expired!")
            .setFooter("Timer | " + Util.generateTimestamp(), null).setColor(Color.GREEN).build())
            .queueAfter(delay, TimeUnit.SECONDS);
}

From source file:ch.jamiete.hilda.music.commands.MusicNowPlayingCommand.java

@Override
public final void execute(final Message message, final String[] args, final String label) {
    final MusicServer server = this.manager.getServer(message.getGuild());

    if ((server == null) || (server.getPlaying() == null)) {
        this.reply(message, "There isn't anything playing.");
        return;//from  www.j a va2  s.  c  o m
    }

    final MessageBuilder mb = new MessageBuilder();
    final QueueItem playing = server.getPlaying();

    mb.append("Now playing ").append(Util.sanitise(MusicManager.getFriendly(playing.getTrack()))).append("\n");

    if (playing.getTrack().getInfo().length != 0L) {
        mb.append("\n").append("Time: ", Formatting.BOLD);
        mb.append(DurationFormatUtils.formatDuration(playing.getTrack().getPosition(), "HH:mm:ss", true));
        mb.append("/");
        mb.append(DurationFormatUtils.formatDuration(playing.getTrack().getDuration(), "HH:mm:ss", true));
    }

    mb.append("\n");
    mb.append("Requestor: ", Formatting.BOLD)
            .append(message.getGuild().getMemberById(playing.getUserId()).getEffectiveName());

    mb.append("\n");
    mb.append("Skip votes: ", Formatting.BOLD);
    final int needed = (int) Math.ceil((double) server.getUsers() / 2);
    mb.append(server.getSkips()).append("/").append(needed);

    this.reply(message, mb.build());
}

From source file:com.spleefleague.superspleef.game.NormalSpleefBattle.java

private void reInitScoreboard() {
    getScoreboard().getObjective("rounds").unregister();
    Objective objective = getScoreboard().registerNewObjective("rounds", "dummy");
    String s = DurationFormatUtils.formatDuration(getTicksPassed() * 50, "HH:mm:ss", true);
    objective.setDisplayName(ChatColor.GRAY.toString() + s + " | " + ChatColor.RED + "Score:");
    objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    objective.getScore(getPlayToString()).setScore(getPlayTo());
    Set<String> requestingReset = new HashSet();
    Set<String> requestingEnd = new HashSet();
    for (SpleefPlayer sp : this.getPlayers()) {
        if (sp.isRequestingReset()) {
            requestingReset.add(sp.getName());
        }//from w ww  .  j  a v  a  2 s  .co m
        if (sp.isRequestingEndgame()) {
            requestingEnd.add(sp.getName());
        }
        objective.getScore(sp.getName()).setScore(getData(sp).getPoints());
    }
    if (!requestingEnd.isEmpty() || !requestingReset.isEmpty()) {
        objective.getScore(ChatColor.BLACK + "-----------").setScore(-1);
    }
    if (!requestingReset.isEmpty()) {
        objective.getScore(ChatColor.GOLD + "Reset requested").setScore(-2);
        for (String name : requestingReset) {
            objective.getScore(ChatColor.LIGHT_PURPLE + "> " + name).setScore(-3);
        }
    }
    if (!requestingEnd.isEmpty()) {
        objective.getScore(ChatColor.RED + "End requested").setScore(-4);
        for (String name : requestingEnd) {
            objective.getScore(ChatColor.AQUA + "> " + name).setScore(-5);
        }
    }
}

From source file:de.tor.tribes.ui.models.FarmTableModel.java

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
    FarmInformation elem = (FarmInformation) FarmManager.getSingleton().getAllElements().get(rowIndex);
    switch (columnIndex) {
    case 0:/*from w  w w. ja  va 2s .c om*/
        return elem.getStatus();
    case 1:
        return elem.isResourcesFoundInLastReport();
    case 2:
        return new Date(elem.getLastReport());
    case 3:
        return elem.getVillage().getShortName();
    case 4:
        return elem.getSiegeStatus();
    case 5:
        return elem.getWallLevel();
    case 6:
        return elem.getStorageStatus();
    case 7:
        long t = elem.getRuntimeInformation();
        t = (t <= 0) ? 0 : t;
        if (t == 0) {
            return "Keine Truppen unterwegs";
        }
        return DurationFormatUtils.formatDuration(t, "HH:mm:ss", true);
    case 8:
        return elem.getLastResult();
    default:
        return elem.getCorrectionFactor();
    }
}

From source file:de.tor.tribes.ui.models.SupportsModel.java

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
    Defense elem = entries.get(rowIndex);
    switch (columnIndex) {
    case 0://from   www.j  a v a 2  s  . c  om
        return elem.getSupporter();
    case 1:
        return elem.getTarget();
    case 2:
        return new Date(elem.getBestSendTime());
    case 3:
        return new Date(elem.getWorstSendTime());
    case 4:

        long sendTime = elem.getBestSendTime();
        if (sendTime < System.currentTimeMillis()) {//if best in past, take worst
            sendTime = elem.getWorstSendTime();
        }
        long t = sendTime - System.currentTimeMillis();
        t = (t <= 0) ? 0 : t;
        return DurationFormatUtils.formatDuration(t, "HHH:mm:ss.SSS", true);
    default:
        return elem.isTransferredToBrowser();
    }
}

From source file:de.tor.tribes.ui.renderer.ColoredCoutdownCellRenderer.java

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    try {//from w  w  w . j  a  v  a 2 s .  c  o  m
        JLabel renderComponent = ((JLabel) c);
        Long d = (Long) value;

        // renderComponent.setText(DurationFormatUtils.formatDuration(d, "HHH:mm:ss.SSS", true));

        long diff = d;
        long five_minutes = 5 * MINUTE;
        long ten_minutes = 10 * MINUTE;
        Color color = null;
        if (row % 2 == 0) {
            color = Constants.DS_ROW_A;
        } else {
            color = Constants.DS_ROW_B;
        }

        if (diff <= 0) {
            //value is expired, stroke result
            //renderComponent.setText(specialFormat.format(d));
            //renderComponent.setForeground(Color.RED);
        } else if (diff <= ten_minutes && diff > five_minutes) {
            float ratio = (float) (diff - five_minutes) / (float) five_minutes;
            Color c1 = Color.YELLOW;
            Color c2 = Color.GREEN;
            int red = (int) (c2.getRed() * ratio + c1.getRed() * (1 - ratio));
            int green = (int) (c2.getGreen() * ratio + c1.getGreen() * (1 - ratio));
            int blue = (int) (c2.getBlue() * ratio + c1.getBlue() * (1 - ratio));
            color = new Color(red, green, blue);
        } else if (diff <= five_minutes) {
            float ratio = (float) diff / (float) five_minutes;
            Color c1 = Color.RED;
            Color c2 = Color.YELLOW;
            int red = (int) (c2.getRed() * ratio + c1.getRed() * (1 - ratio));
            int green = (int) (c2.getGreen() * ratio + c1.getGreen() * (1 - ratio));
            int blue = (int) (c2.getBlue() * ratio + c1.getBlue() * (1 - ratio));
            color = new Color(red, green, blue);
        }
        renderComponent.setText(DurationFormatUtils.formatDuration(d, "HHH:mm:ss.SSS", true));
        if (isSelected) {
            color = c.getBackground();
        }
        renderComponent.setOpaque(true);
        renderComponent.setBackground(color);
        return renderComponent;
    } catch (Exception e) {
        return c;
    }
}

From source file:de.weltraumschaf.minesweeper.model.Game.java

/**
 * Get the elapsed time if game was stopped.
 *
 * Throws exception if invoked before {@link #stop()} called.
 *
 * @return never {@code null}/*from w ww.j a v a  2s.c o m*/
 */
public String getTime() {
    return DurationFormatUtils.formatDuration(watch.getTime(), TIME_FORMAT, true);
}

From source file:de.tor.tribes.ui.components.TimerPanel.java

public void update() {
    long remaining = expires - System.currentTimeMillis();
    remaining = Math.max(remaining, 0);
    jLabel5.setText(DurationFormatUtils.formatDuration(remaining, "dd't' MM'm' yy'y' HH:mm:ss.SSS", true));
}

From source file:com.spleefleague.superspleef.game.TeamSpleefBattle.java

private void reInitScoreboard() {
    getScoreboard().getObjective("rounds").unregister();
    Objective objective = getScoreboard().registerNewObjective("rounds", "dummy");
    String s = DurationFormatUtils.formatDuration(getTicksPassed() * 50, "HH:mm:ss", true);
    objective.setDisplayName(ChatColor.GRAY.toString() + s + " | " + ChatColor.RED + "Score:");
    objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    objective.getScore(getPlayToString()).setScore(getPlayTo());
    Set<String> requestingReset = new HashSet();
    Set<String> requestingEnd = new HashSet();
    for (SpleefPlayer sp : this.getPlayers()) {
        Team t = this.playerTeams.get(sp);
        if (sp.isRequestingReset()) {
            requestingReset.add(t.getChatColor() + sp.getName());
        }/*ww  w .  j  a  v  a2  s.  c o m*/
        if (sp.isRequestingEndgame()) {
            requestingEnd.add(t.getChatColor() + sp.getName());
        }
        getScoreboard().getObjective("rounds").getScore(t.getName()).setScore(t.getPoints());
    }
    if (!requestingEnd.isEmpty() || !requestingReset.isEmpty()) {
        objective.getScore(ChatColor.BLACK + "-----------").setScore(-1);
    }
    if (!requestingReset.isEmpty()) {
        objective.getScore(ChatColor.GOLD + "Reset requested").setScore(-2);
        for (String name : requestingReset) {
            objective.getScore("> " + name).setScore(-3);
        }
    }
    if (!requestingEnd.isEmpty()) {
        objective.getScore(ChatColor.RED + "End requested").setScore(-4);
        for (String name : requestingEnd) {
            objective.getScore("* " + name).setScore(-5);
        }
    }
}