Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / xmloff / source / forms / handler / vcl_time_handler.cxx
blob2bedb56cc7752f620cb40a82a67c99781dff3953
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "vcl_time_handler.hxx"
22 #include <rtl/ustrbuf.hxx>
24 #include <com/sun/star/util/Duration.hpp>
25 #include <com/sun/star/util/Time.hpp>
27 #include <sax/tools/converter.hxx>
29 #include <tools/diagnose_ex.h>
30 #include <tools/time.hxx>
32 namespace xmloff
35 using ::com::sun::star::uno::Any;
36 using ::com::sun::star::uno::makeAny;
37 using ::com::sun::star::util::Duration;
38 using ::com::sun::star::util::Time;
40 //= VCLTimeHandler
41 VCLTimeHandler::VCLTimeHandler()
45 OUString VCLTimeHandler::getAttributeValue( const PropertyValues& /*i_propertyValues*/ ) const
47 OSL_ENSURE( false, "VCLTimeHandler::getAttributeValue: unexpected call!" );
48 return OUString();
51 OUString VCLTimeHandler::getAttributeValue( const Any& i_propertyValue ) const
53 css::util::Time aTime;
54 OSL_VERIFY( i_propertyValue >>= aTime );
56 Duration aDuration; // default-inited to 0
57 aDuration.Hours = aTime.Hours;
58 aDuration.Minutes = aTime.Minutes;
59 aDuration.Seconds = aTime.Seconds;
60 aDuration.NanoSeconds = aTime.NanoSeconds;
62 OUStringBuffer aBuffer;
63 ::sax::Converter::convertDuration( aBuffer, aDuration );
64 return aBuffer.makeStringAndClear();
67 bool VCLTimeHandler::getPropertyValues( const OUString& i_attributeValue, PropertyValues& o_propertyValues ) const
69 Duration aDuration;
70 css::util::Time aTime;
71 if (::sax::Converter::convertDuration( aDuration, i_attributeValue ))
73 aTime = Time(aDuration.NanoSeconds, aDuration.Seconds,
74 aDuration.Minutes, aDuration.Hours,
75 false);
77 else
79 // compatibility format, before we wrote those values in XML-schema compatible form
80 sal_Int64 nVCLTime(0);
81 if (!::sax::Converter::convertNumber64(nVCLTime, i_attributeValue))
83 OSL_ENSURE( false, "VCLTimeHandler::getPropertyValues: unknown time format (no XML-schema time, no legacy integer)!" );
84 return false;
86 // legacy integer was in centiseconds
87 nVCLTime *= ::tools::Time::nanoPerCenti;
88 aTime = ::tools::Time(nVCLTime).GetUNOTime();
91 const Any aPropertyValue( makeAny( aTime ) );
93 OSL_ENSURE( o_propertyValues.size() == 1, "VCLTimeHandler::getPropertyValues: time strings represent exactly one property - not more, not less!" );
94 for ( PropertyValues::iterator prop = o_propertyValues.begin();
95 prop != o_propertyValues.end();
96 ++prop
99 prop->second = aPropertyValue;
101 return true;
104 } // namespace xmloff
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */