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 <svl/dateitem.hxx>
22 #include <unotools/intlwrapper.hxx>
23 #include <comphelper/processfactory.hxx>
25 #include <tools/stream.hxx>
26 #include <tools/debug.hxx>
27 #include <tools/datetime.hxx>
28 #include <com/sun/star/uno/Any.hxx>
29 #include <com/sun/star/util/DateTime.hpp>
30 #include <com/sun/star/lang/Locale.hpp>
33 // STATIC DATA -----------------------------------------------------------
35 DBG_NAME(SfxDateTimeItem
)
38 // -----------------------------------------------------------------------
40 TYPEINIT1(SfxDateTimeItem
, SfxPoolItem
);
42 // -----------------------------------------------------------------------
44 SfxDateTimeItem::SfxDateTimeItem( sal_uInt16 which
, const DateTime
& rDT
) :
49 DBG_CTOR(SfxDateTimeItem
, 0);
52 // -----------------------------------------------------------------------
54 SfxDateTimeItem::SfxDateTimeItem( const SfxDateTimeItem
& rItem
) :
56 aDateTime( rItem
.aDateTime
)
58 DBG_CTOR(SfxDateTimeItem
, 0);
61 // -----------------------------------------------------------------------
63 int SfxDateTimeItem::operator==( const SfxPoolItem
& rItem
) const
65 DBG_CHKTHIS(SfxDateTimeItem
, 0);
66 DBG_ASSERT( SfxPoolItem::operator==( rItem
), "unequal type" );
67 return ( ( (SfxDateTimeItem
&)rItem
).aDateTime
== aDateTime
);
70 // -----------------------------------------------------------------------
72 int SfxDateTimeItem::Compare( const SfxPoolItem
& rItem
) const
74 DBG_CHKTHIS(SfxDateTimeItem
, 0);
75 DBG_ASSERT( SfxPoolItem::operator==( rItem
), "unequal type" );
77 // da X.Compare( Y ) am String einem Compare( Y, X ) entspricht,
78 // vergleichen wir hier Y mit X
79 if ( ( (const SfxDateTimeItem
&)rItem
).aDateTime
< aDateTime
)
81 else if ( ( (const SfxDateTimeItem
&)rItem
).aDateTime
== aDateTime
)
87 // -----------------------------------------------------------------------
89 SfxPoolItem
* SfxDateTimeItem::Create( SvStream
& rStream
, sal_uInt16
) const
91 DBG_CHKTHIS(SfxDateTimeItem
, 0);
95 rStream
.ReadInt64(nTime
);
96 DateTime
aDT(nDate
, nTime
);
97 return new SfxDateTimeItem( Which(), aDT
);
100 // -----------------------------------------------------------------------
102 SvStream
& SfxDateTimeItem::Store( SvStream
& rStream
, sal_uInt16
) const
104 DBG_CHKTHIS(SfxDateTimeItem
, 0);
105 rStream
<< aDateTime
.GetDate();
106 rStream
.WriteInt64(aDateTime
.GetTime());
110 // -----------------------------------------------------------------------
112 SfxPoolItem
* SfxDateTimeItem::Clone( SfxItemPool
* ) const
114 DBG_CHKTHIS(SfxDateTimeItem
, 0);
115 return new SfxDateTimeItem( *this );
118 // -----------------------------------------------------------------------
120 SfxItemPresentation
SfxDateTimeItem::GetPresentation
122 SfxItemPresentation
/*ePresentation*/,
123 SfxMapUnit
/*eCoreMetric*/,
124 SfxMapUnit
/*ePresentationMetric*/,
126 const IntlWrapper
* pIntlWrapper
129 DBG_CHKTHIS(SfxDateTimeItem
, 0);
130 if (aDateTime
.IsValidDate())
133 rText
= pIntlWrapper
->getLocaleData()->getDate(aDateTime
) +
135 pIntlWrapper
->getLocaleData()->getTime(aDateTime
);
139 DBG_WARNING("SfxDateTimeItem::GetPresentation():"
140 " Using default en_US IntlWrapper");
141 const IntlWrapper
aIntlWrapper( LanguageTag( LANGUAGE_ENGLISH_US
) );
142 rText
= aIntlWrapper
.getLocaleData()->getDate(aDateTime
) +
144 aIntlWrapper
.getLocaleData()->getTime(aDateTime
);
148 return SFX_ITEM_PRESENTATION_NAMELESS
;
152 bool SfxDateTimeItem::PutValue( const com::sun::star::uno::Any
& rVal
,
153 sal_uInt8 nMemberId
)
155 nMemberId
&= ~CONVERT_TWIPS
;
156 com::sun::star::util::DateTime aValue
;
157 if ( rVal
>>= aValue
)
159 aDateTime
= DateTime( Date( aValue
.Day
,
165 aValue
.NanoSeconds
) );
169 OSL_FAIL( "SfxDateTimeItem::PutValue - Wrong type!" );
174 bool SfxDateTimeItem::QueryValue( com::sun::star::uno::Any
& rVal
,
175 sal_uInt8 nMemberId
) const
177 nMemberId
&= ~CONVERT_TWIPS
;
178 com::sun::star::util::DateTime
aValue( aDateTime
.GetNanoSec(),
183 aDateTime
.GetMonth(),
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */