summaryrefslogtreecommitdiff
path: root/sw/source/uibase/docvw/edtwin.cxx
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2020-01-19 11:42:23 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2020-01-20 05:42:01 +0100
commit267d2d721c7e89a7b5f28ce0a4fee87d37ee2c61 (patch)
treebe58afd81afddb147be7b5c46064e251fb46fede /sw/source/uibase/docvw/edtwin.cxx
parentd1730033b4fa1f0cfeedd136dfb23ec01a194ec0 (diff)
Simplify getting ISO 8601 date string
Change-Id: If381276990199e4459787ffea090f342241237f1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87037 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sw/source/uibase/docvw/edtwin.cxx')
-rw-r--r--sw/source/uibase/docvw/edtwin.cxx26
1 files changed, 8 insertions, 18 deletions
diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx
index c802664c8aeb..1a81d0851182 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -58,6 +58,7 @@
#include <editeng/flditem.hxx>
#include <editeng/colritem.hxx>
#include <unotools/charclass.hxx>
+#include <unotools/datetime.hxx>
#include <comphelper/lok.hxx>
#include <sfx2/lokhelper.hxx>
@@ -5986,24 +5987,13 @@ void QuickHelpData::FillStrArr( SwWrtShell const & rSh, const OUString& rWord )
// Add matching current date in ISO 8601 format, for example 2016-01-30
OUString rStrToday;
- if (rWord[0] == '2')
- {
- (*pCalendar)->setGregorianDateTime(Date(Date::SYSTEM)); // tdf#130066: reset today
- OUStringBuffer rStr("");
- rStr.append(sal::static_int_cast< sal_Int32 >((*pCalendar)->getValue(i18n::CalendarFieldIndex::YEAR))).append("-");
- sal_Int32 nMonth = sal::static_int_cast< sal_Int32 >((*pCalendar)->getValue(i18n::CalendarFieldIndex::MONTH)+1);
- sal_Int32 nDay = sal::static_int_cast< sal_Int32 > ((*pCalendar)->getValue(i18n::CalendarFieldIndex::DAY_OF_MONTH));
- if (nMonth < 10)
- rStr.append("0");
- rStr.append(nMonth).append("-");
- if (nDay < 10)
- rStr.append("0");
- rStrToday = rStr.append(nDay).toString();
-
- // do not suggest for single years, for example for "2016",
- // only for "201" or "2016-..." (to avoid unintentional text
- // insertion at line ending, for example typing "30 January 2016")
- if (rWord.getLength() != 4 && rStrToday.startsWith(rWord))
+ // do not suggest for single years, for example for "2016",
+ // only for "201" or "2016-..." (to avoid unintentional text
+ // insertion at line ending, for example typing "30 January 2016")
+ if (!rWord.isEmpty() && rWord.getLength() != 4 && rWord[0] == '2')
+ {
+ rStrToday = utl::toISO8601(DateTime(Date(Date::SYSTEM)).GetUNODateTime());
+ if (rStrToday.startsWith(rWord))
m_aHelpStrings.emplace_back(rStrToday, rWord.getLength());
}