aboutsummaryrefslogtreecommitdiffstats
path: root/include/qpdf/QUtil.hh
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2021-02-09 20:56:35 +0100
committerJay Berkenbilt <ejb@ql.org>2021-02-09 23:50:24 +0100
commitbf0e6eb3022bf2fde5623a0a3d151c07f5e82945 (patch)
tree72a4c73a318fd7020ad1a01ffb2469b0f2b7d62e /include/qpdf/QUtil.hh
parentbfbeec5497c04e58e25fa207773ece1d29b67000 (diff)
downloadqpdf-bf0e6eb3022bf2fde5623a0a3d151c07f5e82945.tar.zst
Add QUtil methods for dealing with PDF timestamp strings
Diffstat (limited to 'include/qpdf/QUtil.hh')
-rw-r--r--include/qpdf/QUtil.hh46
1 files changed, 45 insertions, 1 deletions
diff --git a/include/qpdf/QUtil.hh b/include/qpdf/QUtil.hh
index fe18c9b7..09a6c181 100644
--- a/include/qpdf/QUtil.hh
+++ b/include/qpdf/QUtil.hh
@@ -158,7 +158,6 @@ namespace QUtil
QPDF_DLL
void setLineBuf(FILE*);
-
// May modify argv0
QPDF_DLL
char* getWhoami(char* argv0);
@@ -172,6 +171,51 @@ namespace QUtil
QPDF_DLL
time_t get_current_time();
+ // Portable structure representing a point in time with second
+ // granularity and time zone offset
+ struct QPDFTime
+ {
+ QPDFTime() = default;
+ QPDFTime(QPDFTime const&) = default;
+ QPDFTime& operator=(QPDFTime const&) = default;
+ QPDFTime(int year, int month, int day, int hour,
+ int minute, int second, int tz_delta) :
+ year(year),
+ month(month),
+ day(day),
+ hour(hour),
+ minute(minute),
+ second(second),
+ tz_delta(tz_delta)
+ {
+ }
+ int year; // actual year, no 1900 stuff
+ int month; // 1--12
+ int day; // 1--31
+ int hour;
+ int minute;
+ int second;
+ int tz_delta; // minutes before UTC
+ };
+
+ QPDF_DLL
+ QPDFTime get_current_qpdf_time();
+
+ // Convert a QPDFTime structure to a PDF timestamp string, which
+ // is "D:yyyymmddhhmmss<z>" where <z> is either "Z" for UTC or
+ // "-hh'mm'" or "+hh'mm'" for timezone offset. Examples:
+ // "D:20210207161528-05'00'", "D:20210207211528Z". See
+ // get_current_qpdf_time and the QPDFTime structure above.
+ QPDF_DLL
+ std::string qpdf_time_to_pdf_time(QPDFTime const&);
+
+ // Convert a PDF timestamp string to a QPDFTime. If syntactically
+ // valid, return true and fill in qtm. If not valid, return false,
+ // and do not modify qtm. If qtm is null, just check the validity
+ // of the string.
+ QPDF_DLL
+ bool pdf_time_to_qpdf_time(std::string const&, QPDFTime* qtm = nullptr);
+
// Return a string containing the byte representation of the UTF-8
// encoding for the unicode value passed in.
QPDF_DLL