[Libreoffice-commits] core.git: 2 commits - svtools/source sw/qa
Jan Holesovsky
kendy at collabora.com
Wed May 10 15:47:40 UTC 2017
svtools/source/svhtml/parhtml.cxx | 34 ++++++++++++-------
sw/qa/extras/htmlimport/data/meta-ISO8601-dates.html | 20 +++++++++++
sw/qa/extras/htmlimport/htmlimport.cxx | 22 ++++++++++++
3 files changed, 65 insertions(+), 11 deletions(-)
New commits:
commit c43ee7161ab57a22b53655b7b8d6e20ce1a70daa
Author: Jan Holesovsky <kendy at collabora.com>
Date: Wed May 10 16:42:01 2017 +0200
related tdf#107677 html import: Fix the legacy datetime format reading.
Also includes unit test for both the legacy and new format.
Change-Id: I254c40af45a4700319577f11e6cb8ff5f0ff6128
diff --git a/svtools/source/svhtml/parhtml.cxx b/svtools/source/svhtml/parhtml.cxx
index 0906aab472fa..5ad3a2d3b836 100644
--- a/svtools/source/svhtml/parhtml.cxx
+++ b/svtools/source/svhtml/parhtml.cxx
@@ -1970,7 +1970,7 @@ bool HTMLParser::ParseMetaOptionsImpl(
if (comphelper::string::getTokenCount(aContent, ';') == 2)
{
Date aDate((sal_uLong)aContent.getToken(0, ';').toInt32());
- tools::Time aTime((sal_uLong)aContent.getToken(1, ';').toInt32());
+ tools::Time aTime((sal_uLong)aContent.getToken(1, ';').toInt64());
DateTime aDateTime(aDate, aTime);
uDT = aDateTime.GetUNODateTime();
valid = true;
diff --git a/sw/qa/extras/htmlimport/data/meta-ISO8601-dates.html b/sw/qa/extras/htmlimport/data/meta-ISO8601-dates.html
new file mode 100644
index 000000000000..86390d77eade
--- /dev/null
+++ b/sw/qa/extras/htmlimport/data/meta-ISO8601-dates.html
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
+ <title></title>
+ <meta name="generator" content="LibreOfficeDev 5.4.0.0.alpha1 (Linux)"/>
+ <meta name="created" content="2017-05-07T12:34:03.921000000"/>
+ <meta name="changed" content="20170508;124700386000000"/>
+ <style type="text/css">
+ @page { size: 21cm 29.7cm; margin: 2cm }
+ p { margin-bottom: 0.25cm; line-height: 120% }
+ td p { margin-bottom: 0cm }
+ </style>
+</head>
+<body>
+<p>
+Test
+</p>
+</body>
+</html>
diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx
index 216b7f42f12c..1e73ac89fc2b 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -13,6 +13,8 @@
#include <com/sun/star/graphic/GraphicType.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
#include <com/sun/star/drawing/BitmapMode.hpp>
+#include <tools/datetime.hxx>
+#include <unotools/datetime.hxx>
#include <vcl/GraphicNativeTransform.hxx>
#include <sfx2/linkmgr.hxx>
@@ -174,6 +176,26 @@ DECLARE_HTMLIMPORT_TEST(testListStyleType, "list-style.html")
CPPUNIT_FAIL("no NumberingType property found for para 14");
}
+DECLARE_HTMLIMPORT_TEST(testMetaIsoDates, "meta-ISO8601-dates.html")
+{
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
+ CPPUNIT_ASSERT(pTextDoc);
+ SwDocShell* pDocShell(pTextDoc->GetDocShell());
+ uno::Reference<document::XDocumentProperties> xDocProps;
+
+ CPPUNIT_ASSERT(pDocShell);
+ uno::Reference<document::XDocumentPropertiesSupplier> xDPS(pDocShell->GetModel(), uno::UNO_QUERY);
+ xDocProps.set(xDPS->getDocumentProperties());
+
+ // get the document properties
+ CPPUNIT_ASSERT(xDocProps.is());
+ DateTime aCreated(xDocProps->getCreationDate()); // in the new format
+ DateTime aModified(xDocProps->getModificationDate()); // in the legacy format (what LibreOffice used to write)
+
+ CPPUNIT_ASSERT_EQUAL(DateTime(Date(7, 5, 2017), tools::Time(12, 34, 3, 921000000)), aCreated);
+ CPPUNIT_ASSERT_EQUAL(DateTime(Date(8, 5, 2017), tools::Time(12, 47, 0, 386000000)), aModified);
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit bb0543f6de926a2d89797162a974bb01772d890d
Author: Jan Holesovsky <kendy at collabora.com>
Date: Wed May 10 15:58:45 2017 +0200
tdf#107677 html import: Import ISO8601 datetime in html meta tags too.
Change-Id: I51073f5c9e433fb1d9dd2c62bcfea38b299aa010
diff --git a/svtools/source/svhtml/parhtml.cxx b/svtools/source/svhtml/parhtml.cxx
index c35856b9ba88..0906aab472fa 100644
--- a/svtools/source/svhtml/parhtml.cxx
+++ b/svtools/source/svhtml/parhtml.cxx
@@ -27,6 +27,7 @@
#include <tools/tenccvt.hxx>
#include <tools/datetime.hxx>
+#include <unotools/datetime.hxx>
#include <svl/inettype.hxx>
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/document/XDocumentProperties.hpp>
@@ -1962,18 +1963,29 @@ bool HTMLParser::ParseMetaOptionsImpl(
case HtmlMeta::Created:
case HtmlMeta::Changed:
- if ( i_xDocProps.is() && !aContent.isEmpty() &&
- comphelper::string::getTokenCount(aContent, ';') == 2 )
+ if (i_xDocProps.is() && !aContent.isEmpty())
{
- Date aDate( (sal_uLong)aContent.getToken(0, ';').toInt32() );
- tools::Time aTime( (sal_uLong)aContent.getToken(1, ';').toInt32() );
- DateTime aDateTime( aDate, aTime );
- ::util::DateTime uDT = aDateTime.GetUNODateTime();
- if ( HtmlMeta::Created==nAction )
- i_xDocProps->setCreationDate( uDT );
- else
- i_xDocProps->setModificationDate( uDT );
- bChanged = true;
+ ::util::DateTime uDT;
+ bool valid = false;
+ if (comphelper::string::getTokenCount(aContent, ';') == 2)
+ {
+ Date aDate((sal_uLong)aContent.getToken(0, ';').toInt32());
+ tools::Time aTime((sal_uLong)aContent.getToken(1, ';').toInt32());
+ DateTime aDateTime(aDate, aTime);
+ uDT = aDateTime.GetUNODateTime();
+ valid = true;
+ }
+ else if (utl::ISO8601parseDateTime(aContent, uDT))
+ valid = true;
+
+ if (valid)
+ {
+ bChanged = true;
+ if (HtmlMeta::Created == nAction)
+ i_xDocProps->setCreationDate(uDT);
+ else
+ i_xDocProps->setModificationDate(uDT);
+ }
}
break;
More information about the Libreoffice-commits
mailing list