无论如何,是否有要求属性是JSON模式的ISO时间间隔?

发布于 2025-02-03 06:27:46 字数 511 浏览 0 评论 0原文

JSON模式似乎支持ISO时代,日期,日期时间甚至持续时间(请参阅文档),但我还是找不到支持ISO 时间范围

我可以使用REGEX(JSON模式确实支持),但是我将无法检查间隔的起点和终点是否实际上是有效的日期/时间(例如2022-13-04没有第13个月)。我应该如何继续?我是否只需要接受任何字符串并在JSON消费应用程序中进行验证?

JSON Schema seems to support ISO times, dates, date-times, and even durations (see documentation), but I can't find anyway to support ISO time ranges.

I could use regex (which JSON Schema does support) but then I wouldn't be able to check if the start and end points of the interval were actually valid dates/times (e.g. 2022-13-04 there is no 13th month). How should I proceed? Do I just have to accept any string and do the validation in the JSON consuming application?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尹雨沫 2025-02-10 06:27:46

默认情况下未验证字符串格式;相反,它们仅仅是注释 - 供申请采取行动的信息。

但是,许多实现确实具有可以启用的验证。许多人还支持自定义格式,尽管您可能需要自己提供逻辑。

另一种方法是将时间范围分为起点和结束组件并独立验证这些方法。然后,您的应用要做的就是验证start<结束

String formats aren't validated by default; instead they're merely annotations - information for the application to act upon.

However, many implementations do have validation that can be enabled. Many also support custom formats, though you'd likely need to provide the logic yourself.

An alternative approach is to split the time range into its start and end components and validate those independently. Then all your app has to do is verify that start < end.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文