解决服务器时区引起的格式化时间的星期问题

This commit is contained in:
wulin 2023-10-30 15:49:18 +08:00
parent 7d17ebfd98
commit 6cab54d420

View File

@ -12,9 +12,35 @@ import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
@Component
@Slf4j
public class TimeActionCommand extends ActionCommand implements IActionCommand{
Map<String, String> dayOfWeek = new HashMap<String, String>(){{
put("星期0", "星期日");
put("星期1", "星期一");
put("星期2", "星期二");
put("星期3", "星期三");
put("星期4", "星期四");
put("星期5", "星期五");
put("星期6", "星期六");
}
};
private String getDayOfWeek(String v){
int index = v.indexOf("星期");
if(index >= 0){
String ms = v.substring(index, index + 3);
if(dayOfWeek.containsKey(ms)) {
ms = dayOfWeek.get(ms);
}
v = v.substring(0, index) + ms + v.substring(index + 3);
}
return v;
}
public Mono<Boolean> process(Action action, BaseSession baseSession) {
log.info("时间词相关Time Action{}", action.getAsk());
@ -35,7 +61,7 @@ public class TimeActionCommand extends ActionCommand implements IActionCommand{
BoxMessageResp resp = new BoxMessageResp();
resp.setType(action.getSystemTalkAnswerConfigEntity().getAnswerType());
resp.setText(action.getTime().getDetailTime().format(df));
resp.setText(getDayOfWeek(action.getTime().getDetailTime().format(df)));
resp.setTime(dateTimeResp);
return baseWebSocketService.sendMessage(
action,