Skip to content

Commit dffcb52

Browse files
committed
custom time format
1 parent dc73b9b commit dffcb52

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.github.axolotlclient.modules.hud.gui.hud;
22

3-
import io.github.axolotlclient.config.options.BooleanOption;
43
import io.github.axolotlclient.config.options.OptionBase;
4+
import io.github.axolotlclient.config.options.StringOption;
55
import net.minecraft.util.Identifier;
66

77
import java.text.SimpleDateFormat;
@@ -10,14 +10,12 @@
1010

1111
public class RealTimeHud extends CleanHudEntry{
1212

13-
private Date date = new Date();
14-
private final SimpleDateFormat dateFormatSeconds = new SimpleDateFormat("kk:mm:ss");
15-
private final SimpleDateFormat dateFormat = new SimpleDateFormat("kk:mm");
13+
private final Date date = new Date();
14+
private final StringOption dateFormat = new StringOption("format", "HH:mm");
15+
private SimpleDateFormat format = new SimpleDateFormat("HH:mm");
1616

1717
private int second = 0;
1818

19-
protected BooleanOption showSeconds = new BooleanOption("showSeconds", false);
20-
2119
public static Identifier ID = new Identifier("realtimehud");
2220

2321
@Override
@@ -27,7 +25,7 @@ public Identifier getId() {
2725

2826
@Override
2927
public String getValue() {
30-
return showSeconds.get()?dateFormatSeconds.format(date):dateFormat.format(date);
28+
return format.format(date);
3129
}
3230

3331
@Override
@@ -38,7 +36,7 @@ public String getPlaceholder() {
3836
@Override
3937
public void addConfigOptions(List<OptionBase<?>> options) {
4038
super.addConfigOptions(options);
41-
options.add(showSeconds);
39+
options.add(dateFormat);
4240
}
4341

4442
@Override
@@ -49,8 +47,16 @@ public boolean tickable() {
4947
@Override
5048
public void tick() {
5149
if(second>=20){
52-
date = new Date();
50+
date.setTime(System.currentTimeMillis());
5351
second=0;
5452
} else second++;
53+
54+
if(!format.toPattern().equals(dateFormat.get()) && dateFormat.get() != null){
55+
try {
56+
format = new SimpleDateFormat(dateFormat.get());
57+
} catch (IllegalArgumentException e){
58+
dateFormat.set(dateFormat.get().substring(0, dateFormat.get().length()-1));
59+
}
60+
}
5561
}
5662
}

0 commit comments

Comments
 (0)