问题描述
我目前正在尝试在机场项目中进行自检。
我想做的是使用(hour)h(minute)Example(14h40
)格式输入出发时间
我必须通过检查小时值是否小于或等于23以及分钟值是否小于或等于59来验证这一点。
如果这是有效的,那么我想计算登机时间,该时间是出发时间之前的35分钟。
有什么想法吗?
我正在使用的GUI。 https://gyazo.com/62dd8ea5a2ff7cd04aa777447679bcf8
解决方法
最好创建一个with aggs as (
select u.user_id,u.first_name,u.last_name,jsonb_agg(DISTINCT to_jsonb(r)) as roles,jsonb_agg(DISTINCT to_jsonb(t)) as teams,jsonb_agg(DISTINCT to_jsonb(s)) as something_else
from users u
left join user_role ur on ur.user_id = u.user_id
left join roles r on r.role_id = ur.role_id
left join user_team ut on ut.user_id = u.user_id
left join teams t on t.team_id = ut.team_id
left join user_something_else us on us.user_id = u.user_id
left join something_else s on s.something_else_id = us.something_else_id
group by u.user_id,u.last_name
)
select to_jsonb(aggs)
from aggs
where user_id = ?
;
,然后一切对您来说都很容易,您可以使用以下方法来实现:
LocalTime
或者如Ole V.V.所述,您可以使用String time = "14h40";
String[] hm = time.split("h");
LocalTime departureTime = null;
try {
departureTime = LocalTime.of(Integer.valueOf(hm[0]),Integer.valueOf(hm[1]));
} catch (DateTimeException e) {
// time is not correct,throw an exception!
throw new IllegalArgumentException("Time is not correct");
}
// do calculation of the boarding time.
LocalTime boardingTime = departureTime.minusMinutes(35);
:
DateTimeFormatter