开发者

What does strptime do with the information it reads/converts?

开发者 https://www.devze.com 2023-03-29 02:33 出处:网络
The specification for strptime: http://pubs.opengroup.org/onlinepubs/9699919799/functions/strptime.html

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 dat开发者_如何转开发a. 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号