This is an automated email from the ASF dual-hosted git repository.

jimjag pushed a commit to branch odf-devel
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit c9eaa240f95f6c0d808f68cbe8ab0335a61000e8
Author: Jim Jagielski <[email protected]>
AuthorDate: Thu Oct 29 07:06:23 2026 -0400

    xmloff: write form time controls as xsd:time in ODF 1.2 strict mode, read 
both
---
 main/xmloff/source/forms/elementexport.cxx         | 31 +++++++++++++
 .../source/forms/handler/vcl_time_handler.cxx      | 53 +++++++++++++++++++++-
 2 files changed, 83 insertions(+), 1 deletion(-)

diff --git a/main/xmloff/source/forms/elementexport.cxx 
b/main/xmloff/source/forms/elementexport.cxx
index eb51401a01..1ef68ba4bb 100644
--- a/main/xmloff/source/forms/elementexport.cxx
+++ b/main/xmloff/source/forms/elementexport.cxx
@@ -96,6 +96,27 @@ namespace xmloff
        using namespace ::com::sun::star::text;
     using namespace ::com::sun::star::form::binding;
 
+    namespace
+    {
+        // PTnnHnnMnn[.f]S -> nn:nn:nn[.f], keeping the digits of the 
duration; anything else is left alone
+        ::rtl::OUString lcl_durationToXsdTime( const ::rtl::OUString& 
_rDuration )
+        {
+            const sal_Int32 nLen = _rDuration.getLength();
+            const sal_Int32 nH = _rDuration.indexOf( sal_Unicode( 'H' ) );
+            const sal_Int32 nM = _rDuration.indexOf( sal_Unicode( 'M' ) );
+            if ( !_rDuration.matchAsciiL( "PT", 2 ) || nH < 3 || nM < nH + 2 
|| nLen < nM + 3
+                || _rDuration.getStr()[ nLen - 1 ] != sal_Unicode( 'S' ) )
+                return _rDuration;
+
+            ::rtl::OUStringBuffer aBuffer( _rDuration.copy( 2, nH - 2 ) );
+            aBuffer.append( sal_Unicode( ':' ) );
+            aBuffer.append( _rDuration.copy( nH + 1, nM - nH - 1 ) );
+            aBuffer.append( sal_Unicode( ':' ) );
+            aBuffer.append( _rDuration.copy( nM + 1, nLen - nM - 2 ) );
+            return aBuffer.makeStringAndClear();
+        }
+    }
+
        //=====================================================================
        //= OElementExport
        //=====================================================================
@@ -510,6 +531,16 @@ namespace xmloff
 
                     const Any propValue = m_xProps->getPropertyValue( 
prop->Name );
                     attributeValue = handler->getAttributeValue( propValue );
+
+                    // ODF 1.2 wants xsd:time for the time controls
+                    if  (   m_rContext.getGlobalContext().getDefaultVersion() 
== SvtSaveOptions::ODFVER_012
+                        &&  (   propDescription->propertyId == PID_TIME_MIN
+                            ||  propDescription->propertyId == PID_TIME_MAX
+                            ||  propDescription->propertyId == PID_DEFAULT_TIME
+                            ||  propDescription->propertyId == PID_TIME
+                            )
+                        )
+                        attributeValue = lcl_durationToXsdTime( attributeValue 
);
                 }
                 else
                 {
diff --git a/main/xmloff/source/forms/handler/vcl_time_handler.cxx 
b/main/xmloff/source/forms/handler/vcl_time_handler.cxx
index f10ebe44b0..6356391d35 100644
--- a/main/xmloff/source/forms/handler/vcl_time_handler.cxx
+++ b/main/xmloff/source/forms/handler/vcl_time_handler.cxx
@@ -40,6 +40,57 @@ namespace xmloff
     using ::com::sun::star::uno::makeAny;
     using ::com::sun::star::util::DateTime;
 
+    namespace
+    {
+        // xsd:time, hh:mm:ss[.s+][Z|(+|-)hh:mm]; a time zone is accepted and 
ignored
+        bool lcl_convertXsdTime( const ::rtl::OUString& i_value, DateTime& 
o_time )
+        {
+            const ::rtl::OUString sValue( i_value.trim() );
+            const sal_Unicode* pStr = sValue.getStr();
+            const sal_Int32 nLen = sValue.getLength();
+            if ( nLen < 8 || pStr[2] != sal_Unicode(':') || pStr[5] != 
sal_Unicode(':') )
+                return false;
+            for ( sal_Int32 i = 0; i < 8; ++i )
+                if ( i != 2 && i != 5 && ( pStr[i] < sal_Unicode('0') || 
pStr[i] > sal_Unicode('9') ) )
+                    return false;
+            const sal_Int32 nHours = sValue.copy( 0, 2 ).toInt32();
+            const sal_Int32 nMins = sValue.copy( 3, 2 ).toInt32();
+            const sal_Int32 nSecs = sValue.copy( 6, 2 ).toInt32();
+            if ( nHours > 24 || nMins > 59 || nSecs > 59 )
+                return false;
+
+            sal_Int32 nPos = 8;
+            sal_Int32 nHundredths = 0;
+            if ( nPos < nLen && pStr[nPos] == sal_Unicode('.') )
+            {
+                const sal_Int32 nStart = ++nPos;
+                while ( nPos < nLen && pStr[nPos] >= sal_Unicode('0') && 
pStr[nPos] <= sal_Unicode('9') )
+                {
+                    if ( nPos - nStart < 2 )
+                        nHundredths = nHundredths * 10 + ( pStr[nPos] - 
sal_Unicode('0') );
+                    ++nPos;
+                }
+                if ( nPos == nStart )
+                    return false;
+                if ( nPos - nStart == 1 )
+                    nHundredths *= 10;
+            }
+            if ( nPos < nLen && pStr[nPos] == sal_Unicode('Z') )
+                ++nPos;
+            else if ( nLen - nPos == 6 && ( pStr[nPos] == sal_Unicode('+') || 
pStr[nPos] == sal_Unicode('-') )
+                && pStr[nPos + 3] == sal_Unicode(':') )
+                nPos += 6;
+            if ( nPos != nLen )
+                return false;
+
+            o_time.Hours = static_cast< sal_uInt16 >( nHours );
+            o_time.Minutes = static_cast< sal_uInt16 >( nMins );
+            o_time.Seconds = static_cast< sal_uInt16 >( nSecs );
+            o_time.HundredthSeconds = static_cast< sal_uInt16 >( nHundredths );
+            return true;
+        }
+    }
+
        
//==================================================================================================================
        //= VCLTimeHandler
        
//==================================================================================================================
@@ -79,7 +130,7 @@ namespace xmloff
         sal_Int32 nVCLTime(0);
 
         DateTime aDateTime;
-        if ( SvXMLUnitConverter::convertTime( aDateTime, i_attributeValue ) )
+        if ( SvXMLUnitConverter::convertTime( aDateTime, i_attributeValue ) || 
lcl_convertXsdTime( i_attributeValue, aDateTime ) )
         {
             ::Time aVCLTime( aDateTime.Hours, aDateTime.Minutes, 
aDateTime.Seconds, aDateTime.HundredthSeconds );
             nVCLTime = aVCLTime.GetTime();

Reply via email to