Be more strict about dates we generate
authorMike Rylander <mrylander@gmail.com>
Mon, 8 Oct 2012 18:12:49 +0000 (14:12 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Tue, 9 Oct 2012 18:01:20 +0000 (14:01 -0400)
ISO-8601 dates must have a 4-character year component, however strftime does
not left-pad years to 4 characters when the century is one character long even
though the man page for strftime(3) suggests otherwise:

       %F     Equivalent to %Y-%m-%d (the ISO 8601 date format). (C99)

This makes stricter ISO-8601 parsers, such as Perl's DateTime module, unhappy.
So, we'll do it ourselves using the glibc extensions available to strftime for
specifying a padding character and desired length.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/c-apps/oils_sql.c

index c9c1618..5c93b29 100644 (file)
@@ -6436,10 +6436,10 @@ static jsonObject* oilsMakeFieldmapperFromResult( dbi_result result, osrfHash* m
                                                strftime( dt_string, sizeof( dt_string ), "%T", &gmdt );
                                        } else if( !( attr & DBI_DATETIME_TIME )) {
                                                localtime_r( &_tmp_dt, &gmdt );
-                                               strftime( dt_string, sizeof( dt_string ), "%F", &gmdt );
+                                               strftime( dt_string, sizeof( dt_string ), "%04Y-%m-%d", &gmdt );
                                        } else {
                                                localtime_r( &_tmp_dt, &gmdt );
-                                               strftime( dt_string, sizeof( dt_string ), "%FT%T%z", &gmdt );
+                                               strftime( dt_string, sizeof( dt_string ), "%04Y-%m-%dT%T%z", &gmdt );
                                        }
 
                                        jsonObjectSetIndex( object, fmIndex, jsonNewObject( dt_string ));
@@ -6522,10 +6522,10 @@ static jsonObject* oilsMakeJSONFromResult( dbi_result result ) {
                                                strftime( dt_string, sizeof( dt_string ), "%T", &gmdt );
                                        } else if( !( attr & DBI_DATETIME_TIME )) {
                                                localtime_r( &_tmp_dt, &gmdt );
-                                               strftime( dt_string, sizeof( dt_string ), "%F", &gmdt );
+                                               strftime( dt_string, sizeof( dt_string ), "%04Y-%m-%d", &gmdt );
                                        } else {
                                                localtime_r( &_tmp_dt, &gmdt );
-                                               strftime( dt_string, sizeof( dt_string ), "%FT%T%z", &gmdt );
+                                               strftime( dt_string, sizeof( dt_string ), "%04Y-%m-%dT%T%z", &gmdt );
                                        }
 
                                        jsonObjectSetKey( object, columnName, jsonNewObject( dt_string ));