-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDurationMapper.java
More file actions
28 lines (23 loc) · 887 Bytes
/
DurationMapper.java
File metadata and controls
28 lines (23 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package dev.robothanzo.werewolf.commands;
import dev.robothanzo.jda.interactions.annotations.slash.options.IMapper;
import dev.robothanzo.jda.interactions.annotations.slash.options.Mapper;
import java.time.Duration;
import java.util.Locale;
@Mapper
public class DurationMapper implements IMapper<String, Duration> {
@Override
public Class<String> getSourceType() {
return String.class;
}
@Override
public Class<Duration> getTargetType() {
return Duration.class;
}
@Override
public Duration map(Object source) {
String strDuration = source.toString().replaceAll("\\s+", "").replaceFirst("(\\d+d)", "P$1T");
strDuration = strDuration.charAt(0) != 'P' ? "PT" + strDuration.replace("min", "m")
: strDuration.replace("min", "m");
return Duration.parse(strDuration.toUpperCase(Locale.ROOT));
}
}