1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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_date_handler.hxx"
22 #include <rtl/ustrbuf.hxx>
24 #include <com/sun/star/util/DateTime.hpp>
25 #include <com/sun/star/util/Date.hpp>
27 #include <sax/tools/converter.hxx>
29 #include <osl/diagnose.h>
30 #include <tools/date.hxx>
35 using ::com::sun::star::uno::Any
;
36 using ::com::sun::star::util::DateTime
;
37 using ::com::sun::star::util::Date
;
40 VCLDateHandler::VCLDateHandler()
44 OUString
VCLDateHandler::getAttributeValue( const Any
& i_propertyValue
) const
47 OSL_VERIFY( i_propertyValue
>>= aDate
);
49 DateTime aDateTime
; // default-inited to 0
50 aDateTime
.Day
= aDate
.Day
;
51 aDateTime
.Month
= aDate
.Month
;
52 aDateTime
.Year
= aDate
.Year
;
54 OUStringBuffer aBuffer
;
55 ::sax::Converter::convertDateTime( aBuffer
, aDateTime
, nullptr );
56 return aBuffer
.makeStringAndClear();
59 bool VCLDateHandler::getPropertyValues( const OUString
& i_attributeValue
, PropertyValues
& o_propertyValues
) const
63 if (::sax::Converter::parseDateTime( aDateTime
, i_attributeValue
))
65 aDate
.Day
= aDateTime
.Day
;
66 aDate
.Month
= aDateTime
.Month
;
67 aDate
.Year
= aDateTime
.Year
;
71 // compatibility format, before we wrote those values in XML-schema compatible form
72 sal_Int32
nVCLDate(0);
73 if (!::sax::Converter::convertNumber(nVCLDate
, i_attributeValue
))
75 OSL_ENSURE( false, "VCLDateHandler::getPropertyValues: unknown date format (no XML-schema date, no legacy integer)!" );
78 aDate
= ::Date(nVCLDate
).GetUNODate();
81 const Any
aPropertyValue( aDate
);
83 OSL_ENSURE( o_propertyValues
.size() == 1, "VCLDateHandler::getPropertyValues: date strings represent exactly one property - not more, not less!" );
84 for ( auto& prop
: o_propertyValues
)
86 prop
.second
= aPropertyValue
;
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */