File tree Expand file tree Collapse file tree 1 file changed +65
-0
lines changed
src/main/java/com/seailz/jdaframework/utils Expand file tree Collapse file tree 1 file changed +65
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .seailz .jdaframework .utils ;
2+
3+ import java .util .Date ;
4+
5+ /**
6+ * A util for creating timestamps, with ease.
7+ * @author Seailz
8+ */
9+ public class TimestampUtil {
10+
11+ /**
12+ * Generates a Discord timestamp
13+ * @param type The type of timestamp you want to create
14+ * @param time The time it will represent
15+ * @return The generated timestamp
16+ */
17+ public static String createTimestamp (Type type , Date time ) {
18+ if (type == Type .BASE )
19+ return String .valueOf (time .getTime ());
20+ String base = "<t:" + time .getTime () + ":" ;
21+
22+ switch (type ) {
23+ case SHORT_DATE :
24+ base += "d" ;
25+ case LONG_DATE :
26+ base += "D" ;
27+ case SHORT_TIME :
28+ base += "t" ;
29+ case LONG_TIME :
30+ base += "T" ;
31+ case DATE_AND_TIME :
32+ base += "f" ;
33+ case LONG_DATE_AND_TIME :
34+ base += "F" ;
35+ case AGO :
36+ base += "R" ;
37+ }
38+
39+ base += ">" ;
40+ return base ;
41+ }
42+
43+ /**
44+ * Timestamp types
45+ */
46+ public enum Type {
47+ SHORT_DATE ,
48+ // For example: 26/07/2022
49+ LONG_DATE ,
50+ // For example: 26 July 2022
51+ SHORT_TIME ,
52+ // For example 19:50
53+ LONG_TIME ,
54+ // For example: 19:50:43
55+ DATE_AND_TIME ,
56+ // For example: 26 July 2022 19:50
57+ LONG_DATE_AND_TIME ,
58+ // For example: Tuesday, 26 July 2022 19:50
59+ AGO ,
60+ // For example: 10 minutes ago
61+ BASE
62+ // For example: 1658861400
63+ }
64+
65+ }
You can’t perform that action at this time.
0 commit comments