-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from ice-games/feature/timestamps
Timestamp Util & Fix concurrentmodifiedexception
- Loading branch information
Showing
2 changed files
with
73 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/com/seailz/jdaframework/utils/TimestampUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.seailz.jdaframework.utils; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* A util for creating timestamps, with ease. | ||
* @author Seailz | ||
*/ | ||
public class TimestampUtil { | ||
|
||
/** | ||
* Generates a Discord timestamp | ||
* @param type The type of timestamp you want to create | ||
* @param time The time it will represent | ||
* @return The generated timestamp | ||
*/ | ||
public static String createTimestamp(Type type, Date time) { | ||
if (type == Type.BASE) | ||
return String.valueOf(time.getTime()); | ||
String base = "<t:" + time.getTime() + ":"; | ||
|
||
switch (type) { | ||
case SHORT_DATE: | ||
base += "d"; | ||
case LONG_DATE: | ||
base += "D"; | ||
case SHORT_TIME: | ||
base += "t"; | ||
case LONG_TIME: | ||
base += "T"; | ||
case DATE_AND_TIME: | ||
base += "f"; | ||
case LONG_DATE_AND_TIME: | ||
base += "F"; | ||
case AGO: | ||
base += "R"; | ||
} | ||
|
||
base += ">"; | ||
return base; | ||
} | ||
|
||
/** | ||
* Timestamp types | ||
*/ | ||
public enum Type { | ||
SHORT_DATE, | ||
// For example: 26/07/2022 | ||
LONG_DATE, | ||
// For example: 26 July 2022 | ||
SHORT_TIME, | ||
// For example 19:50 | ||
LONG_TIME, | ||
// For example: 19:50:43 | ||
DATE_AND_TIME, | ||
// For example: 26 July 2022 19:50 | ||
LONG_DATE_AND_TIME, | ||
// For example: Tuesday, 26 July 2022 19:50 | ||
AGO, | ||
// For example: 10 minutes ago | ||
BASE | ||
// For example: 1658861400 | ||
} | ||
|
||
} |