[Libreoffice-commits] core.git: sw/qa sw/source
Mike Kaganski (via logerrit)
logerrit at kemper.freedesktop.org
Sat Jul 3 22:13:11 UTC 2021
sw/qa/extras/ww8export/ww8export3.cxx | 23 ++++++++++++++++++++++
sw/source/filter/ww8/ww8par5.cxx | 35 ++++++++++++----------------------
2 files changed, 36 insertions(+), 22 deletions(-)
New commits:
commit 79d31d08146afa0861ceb1705262411449e71ec7
Author: Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Sat Jul 3 21:52:53 2021 +0300
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sun Jul 4 00:12:37 2021 +0200
tdf100961: import fixed date/time field attribute from DOC
Change-Id: Ic67e1cb2fbdb0e7efdeca67ba5cf72ff30856e80
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118357
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
diff --git a/sw/qa/extras/ww8export/ww8export3.cxx b/sw/qa/extras/ww8export/ww8export3.cxx
index a69ddb7d989d..58e226506ccf 100644
--- a/sw/qa/extras/ww8export/ww8export3.cxx
+++ b/sw/qa/extras/ww8export/ww8export3.cxx
@@ -73,6 +73,29 @@ DECLARE_WW8EXPORT_TEST(testTdf100961_fixedDateTime, "tdf100961_fixedDateTime.doc
{
// This should be a fixed date/time field, not the current time.
getParagraph(1, "05.01.19 04:06:08");
+
+ css::uno::Reference<css::text::XTextFieldsSupplier> xSupplier(mxComponent,
+ css::uno::UNO_QUERY_THROW);
+ auto xFieldsAccess(xSupplier->getTextFields());
+ auto xFields(xFieldsAccess->createEnumeration());
+
+ css::uno::Reference<css::uno::XInterface> xField(xFields->nextElement(), css::uno::UNO_QUERY);
+ // Check fixed property was imported and date value was parsed correctly
+ CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xField, "IsFixed"));
+ CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xField, "IsDate"));
+ auto datetime = getProperty<css::util::DateTime>(xField, "DateTimeValue");
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(5), datetime.Day);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), datetime.Month);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(2019), datetime.Year);
+
+ xField.set(xFields->nextElement(), css::uno::UNO_QUERY);
+ // Check fixed property was imported and time value was parsed correctly
+ CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xField, "IsFixed"));
+ CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(xField, "IsDate"));
+ datetime = getProperty<css::util::DateTime>(xField, "DateTimeValue");
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(4), datetime.Hours);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(6), datetime.Minutes);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(8), datetime.Seconds);
}
DECLARE_WW8EXPORT_TEST(testTdf138345_paraCharHighlight, "tdf138345_paraCharHighlight.doc")
diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx
index 0a583ca80f90..9096889a9c60 100644
--- a/sw/source/filter/ww8/ww8par5.cxx
+++ b/sw/source/filter/ww8/ww8par5.cxx
@@ -1822,31 +1822,22 @@ eF_ResT SwWW8ImplReader::Read_F_DateTime( WW8FieldDesc*pF, OUString& rStr )
}
}
- sal_uInt16 nDoNotRecalculate = (pF->nOpt & 0x10) ? FIXEDFLD : 0;
- if (nDoNotRecalculate)
- {
- // TODO: Doing this properly would require setting the field to the original date/time.
- // Unfortunately, none of the plumbing to do this exists AFAICS
- //SAL_WARN("DEBUG","Need to aField.SetDateTime() to ["<<GetFieldResult(pF)<<"] based on format string["<<aReadParam.GetResult()<<"]");
- // So instead, just drop the field and insert the plain text.
- // That is at least better than having the current date/time.
- return eF_ResT::TEXT;
- }
- if (nDT & SvNumFormatType::DATE)
+ if (nDT & SvNumFormatType::DATE || nDT == SvNumFormatType::TIME)
{
SwDateTimeField aField(static_cast<SwDateTimeFieldType*>(
m_rDoc.getIDocumentFieldsAccess().GetSysFieldType(SwFieldIds::DateTime)),
- (DATEFLD | nDoNotRecalculate),
- nFormat);
- ForceFieldLanguage(aField, nLang);
- m_rDoc.getIDocumentContentOperations().InsertPoolItem( *m_pPaM, SwFormatField( aField ) );
- }
- else if (nDT == SvNumFormatType::TIME)
- {
- SwDateTimeField aField(static_cast<SwDateTimeFieldType*>(
- m_rDoc.getIDocumentFieldsAccess().GetSysFieldType(SwFieldIds::DateTime)),
- (TIMEFLD | nDoNotRecalculate),
- nFormat);
+ nDT & SvNumFormatType::DATE ? DATEFLD : TIMEFLD, nFormat);
+ if (pF->nOpt & 0x10) // Fixed field
+ {
+ double fSerial;
+ if (!m_rDoc.GetNumberFormatter()->IsNumberFormat(GetFieldResult(pF), nFormat, fSerial,
+ SvNumInputOptions::LAX_TIME))
+ return eF_ResT::TEXT; // just drop the field and insert the plain text.
+ aField.SetSubType(aField.GetSubType() | FIXEDFLD);
+ DateTime aSetDateTime(m_rDoc.GetNumberFormatter()->GetNullDate());
+ aSetDateTime.AddTime(fSerial);
+ aField.SetDateTime(aSetDateTime);
+ }
ForceFieldLanguage(aField, nLang);
m_rDoc.getIDocumentContentOperations().InsertPoolItem( *m_pPaM, SwFormatField( aField ) );
}
More information about the Libreoffice-commits
mailing list