如何在YUP验证中最多一天的一天结束日期?
目前,我有一个 yup 模式来确保 end_time 至少在 start_time 之后,
start_time: yup
.date()
.min(new Date(), 'Start datetime cannot be in the past')
.required('Start datetime is required'),
end_time: yup
.date()
.min(yup.ref('start_time'), 'End datetime must be after start datetime')
.required('End datetime is required'),
我想让 end_time 最多在 start_time 之后 1 天/24 小时。 例如,如果 start_time 为 "Mon Apr 11 2022 18:30:00"
,我希望 end_time 最多为 "Tue Apr 12 2022 18:30:00"
代码>. 我会考虑使用 .when()
或 .max()
,但我不确定如何开始的格式。
Currently, I have a yup schema to ensure that the end_time is at least after the start_time
start_time: yup
.date()
.min(new Date(), 'Start datetime cannot be in the past')
.required('Start datetime is required'),
end_time: yup
.date()
.min(yup.ref('start_time'), 'End datetime must be after start datetime')
.required('End datetime is required'),
I want to make it so that the end_time is at most 1day/24hrs after the start_time.
For example, if the start_time is "Mon Apr 11 2022 18:30:00"
, I want the end_time to be at most "Tue Apr 12 2022 18:30:00"
.
I would think of using .when()
or .max()
, but I am not sure of the format of how to begin.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于遇到类似问题的任何人,我已经设法使用
Schema
对象上的.when()
方法解决了该问题For anyone that runs into a similar issue, I have managed to solve the issue using the
.when()
method on theSchema
object