Skip to content

Commit

Permalink
Handle CFDate
Browse files Browse the repository at this point in the history
  • Loading branch information
Siguza committed Sep 16, 2024
1 parent ccd6e33 commit bf0e550
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/cfj.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
* defined by the Mozilla Public License, v. 2.0.
**/

#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <CoreFoundation/CoreFoundation.h>

#include "common.h"
Expand Down Expand Up @@ -197,6 +199,14 @@ static void cfj_print_internal(common_ctx_t *ctx, CFTypeRef obj)
fprintf(ctx->stream, "]");
return;
}
else if(type == CFDateGetTypeID())
{
time_t time = floor(CFDateGetAbsoluteTime(obj) + kCFAbsoluteTimeIntervalSince1970);
struct tm date = {};
gmtime_r(&time, &date);
fprintf(ctx->stream, "\"%04d-%02d-%02dT%02d:%02d:%02dZ\"", date.tm_year + 1900, date.tm_mon + 1, date.tm_mday, date.tm_hour, date.tm_min, date.tm_sec);
return;
}
else
{
fprintf(ctx->stream, "<!-- ??? -->");
Expand Down

0 comments on commit bf0e550

Please sign in to comment.