strptime 如何处理它读取/转换的信息?

发布于 2024-11-29 16:48:00 字数 754 浏览 2 评论 0原文

strptime 的规范:

http://pubs.opengroup .org/onlinepubs/9699919799/functions/strptime.html

基本上清楚了可能的转换规范以及它们需要什么输入。但是,似乎没有说明该函数如何将结果存储在 struct tm 中。如果多个说明符读取部分或全部冲突的数据,会发生什么情况。一个简单的例子是同时存在 %m%b (甚至重复的 %m)读取冲突的月份,但也许一个更有趣的例子是 %d (月份中的某一天)和 %a (星期几)发生冲突。哪个优先? strptime 是否应该确保 struct tm 中的输出一致,或者只是将字段存储为读取状态?诸如%W(一年中的一周)之类的某些事物在struct tm中没有直接表示,因此我假设它们必须导致基于其他字段生成派生输出,但尚不清楚何时适用。

我意识到,由于似乎缺乏规范,我可能会要求一个根本不存在的答案,但可以描述有用答案的事情是:

  • 标准化函数所基于的历史实现的行为。
  • 相关缺陷报告的引用
  • 链接到该主题的过去讨论(邮件列表、错误跟踪器、usenet 等)
  • 其他相关的时间解析标准

The specification for strptime:

http://pubs.opengroup.org/onlinepubs/9699919799/functions/strptime.html

is mostly clear on the possible conversion specifications and what input they require. However, there seems to be no specification for how this function stores the results in the struct tm. What is supposed to happen if multiple specifiers read partly or wholly conflicting data. A simple example would be the presence of both %m and %b (or even duplicate %m's) reading conflicting months, but perhaps a more interesting example is when %d (day of month) and %a (day of week) conflict. Which takes precedence? Is strptime even supposed to ensure a consistent output in the struct tm, or simply store the fields as-read? Certain things like %W (week of year) have no direct representation in struct tm, so I would assume they must result in the generation of derived output based on other fields, but it's unclear when this applies.

I realize since the specification seems to be lacking, I may be asking for an answer that simply doesn't exist, but things that could characterize a helpful answer would be:

  • behavior of historical implementations on which the standardized function was based.
  • citations of relevant defect reports
  • links to past discussions of the topic (mailing lists, bug trackers, usenet, etc.)
  • other related standards for time parsing

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

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

发布评论

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

评论(1

病女 2024-12-06 16:48:00

附加字段可用于验证日期。验证和验证,您可以将字符串转换为一系列重新表示日期的数字,然后您必须验证所有这些数字是否引用一个正确的日期,例如星期几是正确的,如果日期无效则<代码>strptime返回NULL

The additional fields can be used for verification of the date. Validation and verification, you can convert the string to a series of numbers that reresent a date, then you must verify that all those numbers refer to one correct date, e.g. day-of-week is correct, if the date is not valid then strptime returns NULL.

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