time.h declares struct tm that has (amongst other members) the following:
int tm_mon; /* Month [0, 11] (January = 0) */
int tm_mday; /* Day of the month [1, 31] */
int tm_wday; /* Day of the week [0, 6] (Sunday = 0) */
int tm_yday; /* Day of the year [0, 365] (Jan/01 = 0) */
A structure like this allows you to get into impossible situations… for example:
tm_mon=0 ; tm_mday=1 ; tm_yday=360
or
tm_year=0 ; tm_yday=1 ; tm_wday=5 ; // January 1, 1900 is on a Monday
I’ve had good luck memsetting the structure to 0s and then only setting the fields I want to set.
My question is: Is there a deterministic way that struct tm should be interpreted?
I’ve been experimenting with this for awhile, so this isn’t a "how can I get my code to work" question. Mostly, I’m asking about other experienced programmers’ experience with struct tm and fish for any gotchas.
>Solution :
as per man page for mktime (the only thing that reads a tm)
The values of the members tm_wday and tm_yday of timeptr are ignored,
when reading a tm – from localtime, say, all fields are set. Its up to you to choose which ones are interesting