GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svl / source / items / dateitem.cxx
bloba734b3569f7793a7f2c2240ef537707743f3babe
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 <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 ) :
45 SfxPoolItem( which ),
46 aDateTime( rDT )
49 DBG_CTOR(SfxDateTimeItem, 0);
52 // -----------------------------------------------------------------------
54 SfxDateTimeItem::SfxDateTimeItem( const SfxDateTimeItem& rItem ) :
55 SfxPoolItem( 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 )
80 return -1;
81 else if ( ( (const SfxDateTimeItem&)rItem ).aDateTime == aDateTime )
82 return 0;
83 else
84 return 1;
87 // -----------------------------------------------------------------------
89 SfxPoolItem* SfxDateTimeItem::Create( SvStream& rStream, sal_uInt16 ) const
91 DBG_CHKTHIS(SfxDateTimeItem, 0);
92 sal_uInt32 nDate = 0;
93 sal_Int64 nTime = 0;
94 rStream >> nDate;
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());
107 return rStream;
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*/,
125 OUString& rText,
126 const IntlWrapper * pIntlWrapper
127 ) const
129 DBG_CHKTHIS(SfxDateTimeItem, 0);
130 if (aDateTime.IsValidDate())
131 if (pIntlWrapper)
133 rText = pIntlWrapper->getLocaleData()->getDate(aDateTime) +
134 ", " +
135 pIntlWrapper->getLocaleData()->getTime(aDateTime);
137 else
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) +
143 ", " +
144 aIntlWrapper.getLocaleData()->getTime(aDateTime);
146 else
147 rText = OUString();
148 return SFX_ITEM_PRESENTATION_NAMELESS;
151 // virtual
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,
160 aValue.Month,
161 aValue.Year ),
162 Time( aValue.Hours,
163 aValue.Minutes,
164 aValue.Seconds,
165 aValue.NanoSeconds ) );
166 return true;
169 OSL_FAIL( "SfxDateTimeItem::PutValue - Wrong type!" );
170 return false;
173 // virtual
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(),
179 aDateTime.GetSec(),
180 aDateTime.GetMin(),
181 aDateTime.GetHour(),
182 aDateTime.GetDay(),
183 aDateTime.GetMonth(),
184 aDateTime.GetYear(),
185 false);
186 rVal <<= aValue;
187 return true;
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */