Bump version to 24.04.3.4
[LibreOffice.git] / oox / source / ppt / comments.cxx
blobc38397fcad69603dc58729e0d0ba37d51736cfd0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <oox/ppt/comments.hxx>
11 #include <com/sun/star/lang/IllegalArgumentException.hpp>
12 #include <rtl/math.h>
13 #include <rtl/math.hxx>
14 #include <o3tl/safeint.hxx>
15 #include <o3tl/string_view.hxx>
17 namespace oox::ppt
19 void CommentAuthorList::setValues(const CommentAuthorList& list)
21 for (auto const& author : list.cmAuthorLst)
23 CommentAuthor temp;
24 // TODO JNA : why not doing push_back at the end instead of using back()?
25 cmAuthorLst.push_back(temp);
26 cmAuthorLst.back().clrIdx = author.clrIdx;
27 cmAuthorLst.back().id = author.id;
28 cmAuthorLst.back().initials = author.initials;
29 cmAuthorLst.back().lastIdx = author.lastIdx;
30 cmAuthorLst.back().name = author.name;
34 //DateTime is saved as : 2013-01-10T15:53:26.000
35 void Comment::setDateTime(const OUString& sDateTime)
37 sal_Int32 nIdx{ 0 };
38 aDateTime.Year = o3tl::toInt32(o3tl::getToken(sDateTime, 0, '-', nIdx));
39 aDateTime.Month = o3tl::toUInt32(o3tl::getToken(sDateTime, 0, '-', nIdx));
40 aDateTime.Day = o3tl::toUInt32(o3tl::getToken(sDateTime, 0, 'T', nIdx));
41 aDateTime.Hours = o3tl::toUInt32(o3tl::getToken(sDateTime, 0, ':', nIdx));
42 aDateTime.Minutes = o3tl::toUInt32(o3tl::getToken(sDateTime, 0, ':', nIdx));
43 double seconds = rtl_math_uStringToDouble(sDateTime.getStr() + nIdx,
44 sDateTime.getStr() + sDateTime.getLength(), '.', 0,
45 nullptr, nullptr);
46 aDateTime.Seconds = floor(seconds);
47 seconds -= aDateTime.Seconds;
48 aDateTime.NanoSeconds = ::rtl::math::round(seconds * 1000000000);
49 const int secondsOverflow = (aDateTime.Seconds == 60) ? 61 : 60;
50 // normalise time part of aDateTime
51 if (aDateTime.NanoSeconds == 1000000000)
53 aDateTime.NanoSeconds = 0;
54 ++aDateTime.Seconds;
56 if (aDateTime.Seconds == secondsOverflow)
58 aDateTime.Seconds = 0;
59 ++aDateTime.Minutes;
61 if (aDateTime.Minutes == 60)
63 aDateTime.Minutes = 0;
64 ++aDateTime.Hours;
66 // if overflow goes into date, I give up
69 OUString Comment::getAuthor(const CommentAuthorList& list)
71 const sal_Int32 nId = authorId.toInt32();
72 for (auto const& author : list.cmAuthorLst)
74 if (author.id.toInt32() == nId)
75 return author.name;
77 return "Anonymous";
80 const Comment& CommentList::getCommentAtIndex(int index)
82 if (index < 0 || o3tl::make_unsigned(index) >= cmLst.size())
83 throw css::lang::IllegalArgumentException();
85 return cmLst.at(index);
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */