DST-switch-aware getter for UNIX timestamp of current day's local time midnight
*(Language/API: Standard C 89 library and / or POSIX)*

Probably a trivial question, but I've got a feeling that I'm missing something.

I need to implement this function:

    time_t get_local_midnight_timestamp(time_t ts);

That is, we get arbitrary timestamp (from the last year, for example), and return it rounded up to the midnight of the same day.

The problem is that the function must be aware of DST switches and DST rules changes (like DST cancellation and/or extension).

(The reason I need this that I need to implement look up into some older statistics data.)

As far as I understand, naïve approach with zeroing out `struct tm` time fields would not work — precisely because of DST stuff (looks like in DST-change day there are two local midnight time_t timestamps).

Please point me in the right direction...

I doubt that it can be done with standard C 89, so POSIX-specific solutions are acceptable. If not POSIX, then something Debian-specific would do...
DST-switch-aware getter for UNIX timestamp of current day's local time midnight
===

*(Language/API: Standard C 89 library and / or POSIX)*

Probably a trivial question, but I've got a feeling that I'm missing something.

I need to implement this function:

    time_t get_local_midnight_timestamp(time_t ts);

That is, we get arbitrary timestamp (from the last year, for example), and return it rounded up to the midnight of the same day.

The problem is that the function must be aware of DST switches and DST rules changes (like DST cancellation and/or extension).

(The reason I need this that I need to implement look up into some older statistics data.)

As far as I understand, naïve approach with zeroing out `struct tm` time fields would not work — precisely because of DST stuff (looks like in DST-change day there are two local midnight time_t timestamps).

Please point me in the right direction...

I doubt that it can be done with standard C 89, so POSIX-specific solutions are acceptable. If not POSIX, then something Debian-specific would do...