LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svl/source/items - dateitem.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 59 0.0 %
Date: 2013-07-09 Functions: 0 15 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <svl/dateitem.hxx>
      21             : 
      22             : #include <unotools/intlwrapper.hxx>
      23             : #include <comphelper/processfactory.hxx>
      24             : 
      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>
      31             : 
      32             : // STATIC DATA -----------------------------------------------------------
      33             : 
      34             : DBG_NAME(SfxDateTimeItem)
      35             : 
      36             : 
      37             : // -----------------------------------------------------------------------
      38             : 
      39           0 : TYPEINIT1(SfxDateTimeItem, SfxPoolItem);
      40             : 
      41             : // -----------------------------------------------------------------------
      42             : 
      43           0 : SfxDateTimeItem::SfxDateTimeItem( sal_uInt16 which, const DateTime& rDT ) :
      44             :     SfxPoolItem( which ),
      45           0 :     aDateTime( rDT )
      46             : 
      47             : {
      48             :     DBG_CTOR(SfxDateTimeItem, 0);
      49           0 : }
      50             : 
      51             : // -----------------------------------------------------------------------
      52             : 
      53           0 : SfxDateTimeItem::SfxDateTimeItem( const SfxDateTimeItem& rItem ) :
      54             :     SfxPoolItem( rItem ),
      55           0 :     aDateTime( rItem.aDateTime )
      56             : {
      57             :     DBG_CTOR(SfxDateTimeItem, 0);
      58           0 : }
      59             : 
      60             : // -----------------------------------------------------------------------
      61             : 
      62           0 : int SfxDateTimeItem::operator==( const SfxPoolItem& rItem ) const
      63             : {
      64             :     DBG_CHKTHIS(SfxDateTimeItem, 0);
      65             :     DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
      66           0 :     return ( ( (SfxDateTimeItem&)rItem ).aDateTime == aDateTime );
      67             : }
      68             : 
      69             : // -----------------------------------------------------------------------
      70             : 
      71           0 : int SfxDateTimeItem::Compare( const SfxPoolItem& rItem ) const
      72             : {
      73             :     DBG_CHKTHIS(SfxDateTimeItem, 0);
      74             :     DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
      75             : 
      76             :     // da X.Compare( Y ) am String einem Compare( Y, X ) entspricht,
      77             :     // vergleichen wir hier Y mit X
      78           0 :     if ( ( (const SfxDateTimeItem&)rItem ).aDateTime < aDateTime )
      79           0 :         return -1;
      80           0 :     else if ( ( (const SfxDateTimeItem&)rItem ).aDateTime == aDateTime )
      81           0 :         return 0;
      82             :     else
      83           0 :         return 1;
      84             : }
      85             : 
      86             : // -----------------------------------------------------------------------
      87             : 
      88           0 : SfxPoolItem* SfxDateTimeItem::Create( SvStream& rStream, sal_uInt16 ) const
      89             : {
      90             :     DBG_CHKTHIS(SfxDateTimeItem, 0);
      91           0 :     sal_uInt32 nDate = 0;
      92           0 :     sal_Int32 nTime = 0;
      93           0 :     rStream >> nDate;
      94           0 :     rStream >> nTime;
      95           0 :     DateTime aDT(nDate, nTime);
      96           0 :     return new SfxDateTimeItem( Which(), aDT );
      97             : }
      98             : 
      99             : // -----------------------------------------------------------------------
     100             : 
     101           0 : SvStream& SfxDateTimeItem::Store( SvStream& rStream, sal_uInt16 ) const
     102             : {
     103             :     DBG_CHKTHIS(SfxDateTimeItem, 0);
     104           0 :     rStream << aDateTime.GetDate();
     105           0 :     rStream << static_cast<sal_Int32>(aDateTime.GetTime());
     106           0 :     return rStream;
     107             : }
     108             : 
     109             : // -----------------------------------------------------------------------
     110             : 
     111           0 : SfxPoolItem* SfxDateTimeItem::Clone( SfxItemPool* ) const
     112             : {
     113             :     DBG_CHKTHIS(SfxDateTimeItem, 0);
     114           0 :     return new SfxDateTimeItem( *this );
     115             : }
     116             : 
     117             : // -----------------------------------------------------------------------
     118             : 
     119           0 : SfxItemPresentation SfxDateTimeItem::GetPresentation
     120             : (
     121             :     SfxItemPresentation     /*ePresentation*/,
     122             :     SfxMapUnit              /*eCoreMetric*/,
     123             :     SfxMapUnit              /*ePresentationMetric*/,
     124             :     OUString&               rText,
     125             :     const IntlWrapper *   pIntlWrapper
     126             : )   const
     127             : {
     128             :     DBG_CHKTHIS(SfxDateTimeItem, 0);
     129           0 :     if (aDateTime.IsValidDate())
     130           0 :         if (pIntlWrapper)
     131             :         {
     132           0 :             rText = pIntlWrapper->getLocaleData()->getDate(aDateTime) +
     133           0 :                     ", " +
     134           0 :                     pIntlWrapper->getLocaleData()->getTime(aDateTime);
     135             :         }
     136             :         else
     137             :         {
     138             :             DBG_WARNING("SfxDateTimeItem::GetPresentation():"
     139             :                          " Using default en_US IntlWrapper");
     140           0 :             const IntlWrapper aIntlWrapper( LanguageTag( LANGUAGE_ENGLISH_US) );
     141           0 :             rText = aIntlWrapper.getLocaleData()->getDate(aDateTime) +
     142           0 :                     ", " +
     143           0 :                     aIntlWrapper.getLocaleData()->getTime(aDateTime);
     144             :         }
     145             :     else
     146           0 :         rText = OUString();
     147           0 :     return SFX_ITEM_PRESENTATION_NAMELESS;
     148             : }
     149             : 
     150             : //----------------------------------------------------------------------------
     151             : // virtual
     152           0 : bool SfxDateTimeItem::PutValue( const com::sun::star::uno::Any& rVal,
     153             :                                    sal_uInt8 nMemberId )
     154             : {
     155           0 :     nMemberId &= ~CONVERT_TWIPS;
     156           0 :     com::sun::star::util::DateTime aValue;
     157           0 :     if ( rVal >>= aValue )
     158             :     {
     159           0 :         aDateTime = DateTime( Date( aValue.Day,
     160             :                                       aValue.Month,
     161             :                                       aValue.Year ),
     162             :                               Time( aValue.Hours,
     163             :                                       aValue.Minutes,
     164             :                                       aValue.Seconds,
     165           0 :                                       aValue.NanoSeconds ) );
     166           0 :         return true;
     167             :     }
     168             : 
     169             :     OSL_FAIL( "SfxDateTimeItem::PutValue - Wrong type!" );
     170           0 :     return false;
     171             : }
     172             : 
     173             : //----------------------------------------------------------------------------
     174             : // virtual
     175           0 : bool SfxDateTimeItem::QueryValue( com::sun::star::uno::Any& rVal,
     176             :                                    sal_uInt8 nMemberId ) const
     177             : {
     178           0 :     nMemberId &= ~CONVERT_TWIPS;
     179           0 :     com::sun::star::util::DateTime aValue( aDateTime.GetNanoSec(),
     180           0 :                                            aDateTime.GetSec(),
     181           0 :                                               aDateTime.GetMin(),
     182           0 :                                            aDateTime.GetHour(),
     183           0 :                                            aDateTime.GetDay(),
     184           0 :                                            aDateTime.GetMonth(),
     185           0 :                                            aDateTime.GetYear() );
     186           0 :     rVal <<= aValue;
     187           0 :     return true;
     188             : }
     189             : 
     190             : 
     191             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10