LibreOffice Module vcl (master) 1
PDFiumTools.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 */
10
12
13namespace vcl::pdf
14{
15OUString convertPdfDateToISO8601(OUString const& rInput)
16{
17 if (rInput.getLength() < 6)
18 return {};
19
20 std::u16string_view prefix = rInput.subView(0, 2);
21 if (prefix != u"D:")
22 return {};
23
24 std::u16string_view sYear = rInput.subView(2, 4);
25
26 std::u16string_view sMonth(u"01");
27 if (rInput.getLength() >= 8)
28 sMonth = rInput.subView(6, 2);
29
30 std::u16string_view sDay(u"01");
31 if (rInput.getLength() >= 10)
32 sDay = rInput.subView(8, 2);
33
34 std::u16string_view sHours(u"00");
35 if (rInput.getLength() >= 12)
36 sHours = rInput.subView(10, 2);
37
38 std::u16string_view sMinutes(u"00");
39 if (rInput.getLength() >= 14)
40 sMinutes = rInput.subView(12, 2);
41
42 std::u16string_view sSeconds(u"00");
43 if (rInput.getLength() >= 16)
44 sSeconds = rInput.subView(14, 2);
45
46 OUString sTimeZoneMark("Z");
47 if (rInput.getLength() >= 17)
48 sTimeZoneMark = rInput.subView(16, 1);
49
50 std::u16string_view sTimeZoneHours(u"00");
51 std::u16string_view sTimeZoneMinutes(u"00");
52 if ((sTimeZoneMark == "+" || sTimeZoneMark == "-") && rInput.getLength() >= 22)
53 {
54 std::u16string_view sTimeZoneSeparator = rInput.subView(19, 1);
55 if (sTimeZoneSeparator == u"'")
56 {
57 sTimeZoneHours = rInput.subView(17, 2);
58 sTimeZoneMinutes = rInput.subView(20, 2);
59 }
60 }
61
62 OUString sTimeZoneString;
63 if (sTimeZoneMark == "+" || sTimeZoneString == "-")
64 sTimeZoneString = sTimeZoneMark + sTimeZoneHours + ":" + sTimeZoneMinutes;
65 else if (sTimeZoneMark == "Z")
66 sTimeZoneString = sTimeZoneMark;
67
68 return OUString::Concat(sYear) + "-" + sMonth + "-" + sDay + "T" + sHours + ":" + sMinutes + ":"
69 + sSeconds + sTimeZoneString;
70}
71} // end vcl::pdf
72
73/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
float u
OUString convertPdfDateToISO8601(OUString const &rInput)
Definition: PDFiumTools.cxx:15