Thats why the day doesn't end at the instant of 23:59:59, nor does it end at 23:59:60 (if there is a leap second). It actually ends at 24:00:00. Which is the same instant in time as 00:00:00 of the following day. Every conforming implementation of ISO 8601 should know about that. And all software should conform to ISO 8601.
23:59:59.500 is after 23:59:59 when interpreted as an instant, but it is part of 23:59:59 as a duration.