[CDRIVER-2945] Add public function for converting from BSON dates to ISO8601 strings Created: 06/Feb/19  Updated: 05/Feb/24

Status: Backlog
Project: C Driver
Component/s: libbson
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor - P4
Reporter: Stennie Steneker (Inactive) Assignee: Unassigned
Resolution: Unresolved Votes: 1
Labels: bg-rf, neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Epic Link: Improve Developer Experience
Quarter: FY25Q2
Case:

 Description   

It looks like the C driver currently doesn't provide a public function for converting from BSON dates to ISO8601 strings. It would be helpful to provide a standard public cross-platform function via the driver API, as standard C library functions like gmtime() do not consistently support dates before the Unix epoch.

For example, the Windows implementation of the `gmtime()` function currently does not support dates earlier than 1970:

If sourceTime represents a date before midnight, January 1, 1970, *gmtime* returns *NULL*. There is no error return.

A suggested approach on Windows would be to fallback to SYSTEMTIME using the Windows API instead of C API: https://docs.microsoft.com/en-us/windows/desktop/Intl/retrieving-time-and-date-information (GetTimeFormatEx, GetDateFormatEx).



 Comments   
Comment by Stennie Steneker (Inactive) [ 06/Feb/19 ]

Related discussion while tracking down a problem with displaying ISO dates in mongolite 2.0 (which uses the 1.12.0 mongo-c-driver): Query dates before 1970 returns ".000Z".

Generated at Wed Feb 07 21:16:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.