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 fa1872e682ad842918ed9d5eeb8462181ab6adc0 Author: Jan Holesovsky <[email protected]> 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 3bddc50595de..971821384827 100644 --- a/svtools/source/svhtml/parhtml.cxx +++ b/svtools/source/svhtml/parhtml.cxx @@ -2001,7 +2001,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 66d070db4752..f32bdb4b2a4b 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> @@ -126,6 +128,26 @@ DECLARE_HTMLIMPORT_TEST(testInlinedImagesPageAndParagraph, "PageAndParagraphFill } } +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 f8dcc41b6d7b0e023096dbb213f9e182046da5cc Author: Jan Holesovsky <[email protected]> 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 c09ecc59c58c..3bddc50595de 100644 --- a/svtools/source/svhtml/parhtml.cxx +++ b/svtools/source/svhtml/parhtml.cxx @@ -29,6 +29,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> @@ -1993,18 +1994,29 @@ bool HTMLParser::ParseMetaOptionsImpl( case HTML_META_CREATED: case HTML_META_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 ( HTML_META_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 (HTML_META_CREATED == nAction) + i_xDocProps->setCreationDate(uDT); + else + i_xDocProps->setModificationDate(uDT); + } } break; _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
