diff options
author | Jay Berkenbilt <ejb@ql.org> | 2022-05-30 15:00:36 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2022-05-31 02:03:08 +0200 |
commit | 04fc7c4bea9b4efa38a7398b6db56a8fe5273bfb (patch) | |
tree | 4148a27d5f8f2d01681d1c6c41b9fceabe2a1042 /libqpdf/QUtil.cc | |
parent | 6a7c45838171fd8cc4508d09626e27d9066bb39d (diff) | |
download | qpdf-04fc7c4bea9b4efa38a7398b6db56a8fe5273bfb.tar.zst |
Add conversions to ISO-8601 date format
Diffstat (limited to 'libqpdf/QUtil.cc')
-rw-r--r-- | libqpdf/QUtil.cc | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc index 3e68d95e..7a5d3caf 100644 --- a/libqpdf/QUtil.cc +++ b/libqpdf/QUtil.cc @@ -984,6 +984,32 @@ QUtil::qpdf_time_to_pdf_time(QPDFTime const& qtm) QUtil::int_to_string(qtm.second, 2) + tz_offset); } +std::string +QUtil::qpdf_time_to_iso8601(QPDFTime const& qtm) +{ + std::string tz_offset; + int t = qtm.tz_delta; + if (t == 0) { + tz_offset = "Z"; + } else { + if (t < 0) { + t = -t; + tz_offset += "+"; + } else { + tz_offset += "-"; + } + tz_offset += QUtil::int_to_string(t / 60, 2) + ":" + + QUtil::int_to_string(t % 60, 2); + } + return ( + QUtil::int_to_string(qtm.year, 4) + "-" + + QUtil::int_to_string(qtm.month, 2) + "-" + + QUtil::int_to_string(qtm.day, 2) + "T" + + QUtil::int_to_string(qtm.hour, 2) + ":" + + QUtil::int_to_string(qtm.minute, 2) + ":" + + QUtil::int_to_string(qtm.second, 2) + tz_offset); +} + bool QUtil::pdf_time_to_qpdf_time(std::string const& str, QPDFTime* qtm) { @@ -1018,6 +1044,17 @@ QUtil::pdf_time_to_qpdf_time(std::string const& str, QPDFTime* qtm) return true; } +bool +QUtil::pdf_time_to_iso8601(std::string const& pdf_time, std::string& iso8601) +{ + QPDFTime qtm; + if (pdf_time_to_qpdf_time(pdf_time, &qtm)) { + iso8601 = qpdf_time_to_iso8601(qtm); + return true; + } + return false; +} + std::string QUtil::toUTF8(unsigned long uval) { |