/src/libreoffice/vcl/source/pdf/PDFiumTools.cxx
Line | Count | Source |
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 | | |
11 | | #include <vcl/filter/PDFiumLibrary.hxx> |
12 | | |
13 | | namespace vcl::pdf |
14 | | { |
15 | | OUString convertPdfDateToISO8601(std::u16string_view rInput) |
16 | 4 | { |
17 | 4 | if (rInput.size() < 6) |
18 | 1 | return {}; |
19 | | |
20 | 3 | std::u16string_view prefix = rInput.substr(0, 2); |
21 | 3 | if (prefix != u"D:") |
22 | 0 | return {}; |
23 | | |
24 | 3 | std::u16string_view sYear = rInput.substr(2, 4); |
25 | | |
26 | 3 | std::u16string_view sMonth(u"01"); |
27 | 3 | if (rInput.size() >= 8) |
28 | 3 | sMonth = rInput.substr(6, 2); |
29 | | |
30 | 3 | std::u16string_view sDay(u"01"); |
31 | 3 | if (rInput.size() >= 10) |
32 | 3 | sDay = rInput.substr(8, 2); |
33 | | |
34 | 3 | std::u16string_view sHours(u"00"); |
35 | 3 | if (rInput.size() >= 12) |
36 | 3 | sHours = rInput.substr(10, 2); |
37 | | |
38 | 3 | std::u16string_view sMinutes(u"00"); |
39 | 3 | if (rInput.size() >= 14) |
40 | 3 | sMinutes = rInput.substr(12, 2); |
41 | | |
42 | 3 | std::u16string_view sSeconds(u"00"); |
43 | 3 | if (rInput.size() >= 16) |
44 | 3 | sSeconds = rInput.substr(14, 2); |
45 | | |
46 | 3 | OUString sTimeZoneMark(u"Z"_ustr); |
47 | 3 | if (rInput.size() >= 17) |
48 | 3 | sTimeZoneMark = rInput.substr(16, 1); |
49 | | |
50 | 3 | std::u16string_view sTimeZoneHours(u"00"); |
51 | 3 | std::u16string_view sTimeZoneMinutes(u"00"); |
52 | 3 | if ((sTimeZoneMark == "+" || sTimeZoneMark == "-") && rInput.size() >= 22) |
53 | 3 | { |
54 | 3 | std::u16string_view sTimeZoneSeparator = rInput.substr(19, 1); |
55 | 3 | if (sTimeZoneSeparator == u"'") |
56 | 3 | { |
57 | 3 | sTimeZoneHours = rInput.substr(17, 2); |
58 | 3 | sTimeZoneMinutes = rInput.substr(20, 2); |
59 | 3 | } |
60 | 3 | } |
61 | | |
62 | 3 | OUString sTimeZoneString; |
63 | 3 | if (sTimeZoneMark == "+" || sTimeZoneString == "-") |
64 | 2 | sTimeZoneString = sTimeZoneMark + sTimeZoneHours + ":" + sTimeZoneMinutes; |
65 | 1 | else if (sTimeZoneMark == "Z") |
66 | 0 | sTimeZoneString = sTimeZoneMark; |
67 | | |
68 | 3 | return OUString::Concat(sYear) + "-" + sMonth + "-" + sDay + "T" + sHours + ":" + sMinutes + ":" |
69 | 3 | + sSeconds + sTimeZoneString; |
70 | 3 | } |
71 | | } // end vcl::pdf |
72 | | |
73 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |