英文:
Setting Boundaries for user cancellation of trip
问题
我正在构建一个预订系统,试图限制用户在实际行程日期前一周内尝试取消行程的操作。
换句话说:用户在7月1日预订了旅行,旅行从8月1日开始。用户尝试在7月23日取消他/她的旅行预订。系统应该阻止他/她取消行程的请求。
我想在用户在开始日期之前尝试取消行程时使此日期验证生效。有谁可以帮助我验证用户请求取消行程的日期。
我尝试了下面的代码,但不确定它是否正常工作。
这是我尝试实现的代码:
// 从 JSP 获取输入值
LocalDate.parse(request.getParameter("startDate"));
LocalDate endDate = (LocalDate) LocalDate.parse(request.getParameter("endDate"));
LocalDate startDate = (LocalDate) LocalDate.of(2020, 05, 01);
LocalDate isexpDate = LocalDate.of(2020, 04, 01);
if (startDate.minusWeeks(1).isBefore(isexpDate))
英文:
I am building a booking system and trying to limit the user's cancellation of the trip if he/she tried to cancel it one week before the actual date of the trip.
In other words: The user booked the trip on July 1 and the trip starts on August 1. The user tried to cancel his/her booking of the trip on July 23rd. The system should block his/her request to cancel the trip.
I wanna make this date validation work when the user try to cancel the trip before the start date. Can anyone help me to validate the date the user request to cancel the trip.
I have tried the code below but not sure if it is working properly
This is the code I tried to implement:
//Getting input values from jsp from
LocalDate.parse(request.getParameter("startDate"));
LocalDate endDate = (LocalDate)
LocalDate.parse(request.getParameter("endDate"));
LocalDate startDate = (LocalDate) LocalDate.of(2020, 05, 01);
LocalDate isexpDate = LocalDate.of(2020, 04, 01);
if (startDate.minusWeeks(1).isBefore(isexpDate))
The start and end date should based on the user input
答案1
得分: 0
以下代码应该可以实现此功能,使用的标识符比问题中提供的更易理解,并且日期与问题中提到的日期相符:
LocalDate tripDate = LocalDate.of(2020, 8, 1);
LocalDate latestCancellationDate = tripDate.minusWeeks(1);
LocalDate currentDate = LocalDate.of(2020, 7, 23);
if (currentDate.isAfter(latestCancellationDate)) {
/* 防止取消 */
}
请注意,我实际上并没有尝试编译上述代码,它可能需要一些细微的修改才能在没有错误的情况下编译通过,但逻辑应该是正确的。
英文:
The following should do it, using identifiers that are a bit more understandable than those provided, and dates that are in accordance with the dates mentioned in the question:
LocalDate tripDate = LocalDate.of(2020, 8, 1 );
LocalDate latestCancellationDate = tripDate.minusWeeks( 1 );
LocalDate currentDate = LocalDate.of( 2020, 7, 23 );
if( currentDate.isAfter( latestCancellationDate ) )
{
/* prevent cancellation */
}
Beware that I have not actually tried to compile the above, it might need some slight modifications before it compiles without errors, but the logic should be correct.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论