MCPcopy Create free account
hub / github.com/creatale/node-dv / l_getFormattedDate

Function l_getFormattedDate

deps/leptonica/src/utils1.c:1103–1141  ·  view source on GitHub ↗

! * \brief l_getFormattedDate() * * \return formatted date string, or NULL on error * * * Notes: * (1) This is used in pdf, in the form specified in section 3.8.2 of * http://partners.adobe.com/public/developer/en/pdf/PDFReference.pdf * (2) Contributed by Dave Bryan. Works on all platforms. * */

Source from the content-addressed store, hash-verified

1101 * </pre>
1102 */
1103char *
1104l_getFormattedDate()
1105{
1106char buf[sizeof "199812231952SS-08'00'"] = "", sep = 'Z';
1107l_int32 gmt_offset, relh, relm;
1108time_t ut, lt;
1109struct tm *tptr;
1110
1111 ut = time(NULL);
1112
1113 /* This generates a second "time_t" value by calling "gmtime" to
1114 fill in a "tm" structure expressed as UTC and then calling
1115 "mktime", which expects a "tm" structure expressed as the
1116 local time. The result is a value that is offset from the
1117 value returned by the "time" function by the local UTC offset.
1118 "tm_isdst" is set to -1 to tell "mktime" to determine for
1119 itself whether DST is in effect. This is necessary because
1120 "gmtime" always sets "tm_isdst" to 0, which would tell
1121 "mktime" to presume that DST is not in effect. */
1122 tptr = gmtime(&ut);
1123 tptr->tm_isdst = -1;
1124 lt = mktime(tptr);
1125
1126 /* Calls "difftime" to obtain the resulting difference in seconds,
1127 * because "time_t" is an opaque type, per the C standard. */
1128 gmt_offset = (l_int32) difftime(ut, lt);
1129
1130 if (gmt_offset > 0)
1131 sep = '+';
1132 else if (gmt_offset < 0)
1133 sep = '-';
1134
1135 relh = L_ABS(gmt_offset) / 3600;
1136 relm = (L_ABS(gmt_offset) % 3600) / 60;
1137
1138 strftime(buf, sizeof(buf), "%Y%m%d%H%M%S", localtime(&ut));
1139 sprintf(buf + 14, "%c%02d'%02d'", sep, relh, relm);
1140 return stringNew(buf);
1141}

Callers 2

generateFixedStringsPdfFunction · 0.85
EndDocumentHandlerMethod · 0.85

Calls 1

stringNewFunction · 0.85

Tested by

no test coverage detected