LCOV - code coverage report
Current view: top level - sw/source/core/fields - flddat.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 39 127 30.7 %
Date: 2012-08-25 Functions: 8 16 50.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 21 128 16.4 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <tools/datetime.hxx>
      31                 :            : #include <svl/zforlist.hxx>
      32                 :            : #include <com/sun/star/util/DateTime.hpp>
      33                 :            : #include <doc.hxx>
      34                 :            : #include <fldbas.hxx>
      35                 :            : #include <flddat.hxx>
      36                 :            : #include <unofldmid.h>
      37                 :            : 
      38                 :            : using namespace ::com::sun::star;
      39                 :            : /*--------------------------------------------------
      40                 :            :     Beschreibung: Datum/Zeit-Typ
      41                 :            :  ---------------------------------------------------*/
      42                 :            : 
      43                 :       1549 : SwDateTimeFieldType::SwDateTimeFieldType(SwDoc* pInitDoc)
      44                 :       1549 :     : SwValueFieldType( pInitDoc, RES_DATETIMEFLD )
      45                 :       1549 : {}
      46                 :            : 
      47                 :          0 : SwFieldType* SwDateTimeFieldType::Copy() const
      48                 :            : {
      49         [ #  # ]:          0 :     SwDateTimeFieldType *pTmp = new SwDateTimeFieldType(GetDoc());
      50                 :          0 :     return pTmp;
      51                 :            : }
      52                 :            : 
      53                 :            : /*--------------------------------------------------------------------
      54                 :            :     Beschreibung: Datum/Zeit-Feld
      55                 :            :  --------------------------------------------------------------------*/
      56                 :            : 
      57                 :         63 : SwDateTimeField::SwDateTimeField(SwDateTimeFieldType* pInitType, sal_uInt16 nSub, sal_uLong nFmt, sal_uInt16 nLng)
      58                 :            :     : SwValueField(pInitType, nFmt, nLng, 0.0),
      59                 :            :     nSubType(nSub),
      60                 :         63 :     nOffset(0)
      61                 :            : {
      62         [ +  + ]:         63 :     if (!nFmt)
      63                 :            :     {
      64         [ +  - ]:          4 :         SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
      65         [ -  + ]:          4 :         if (nSubType & DATEFLD)
      66 [ #  # ][ #  # ]:          0 :             ChangeFormat(pFormatter->GetFormatIndex(NF_DATE_SYSTEM_SHORT, GetLanguage()));
      67                 :            :         else
      68 [ +  - ][ +  - ]:          4 :             ChangeFormat(pFormatter->GetFormatIndex(NF_TIME_HHMMSS, GetLanguage()));
      69                 :            :     }
      70 [ +  - ][ -  + ]:         63 :     if (IsFixed())
      71                 :            :     {
      72         [ #  # ]:          0 :         DateTime aDateTime( DateTime::SYSTEM );
      73         [ #  # ]:          0 :         SetDateTime(aDateTime);
      74                 :            :     }
      75                 :         63 : }
      76                 :            : 
      77                 :         22 : String SwDateTimeField::Expand() const
      78                 :            : {
      79                 :            :     double fVal;
      80                 :            : 
      81 [ +  - ][ +  - ]:         22 :     if (!(IsFixed()))
      82                 :            :     {
      83         [ +  - ]:         22 :         DateTime aDateTime( DateTime::SYSTEM );
      84         [ +  - ]:         22 :         fVal = GetDateTime(GetDoc(), aDateTime);
      85                 :            :     }
      86                 :            :     else
      87         [ #  # ]:          0 :         fVal = GetValue();
      88                 :            : 
      89         [ -  + ]:         22 :     if (nOffset)
      90                 :          0 :         fVal += (double)(nOffset * 60L) / 86400.0;
      91                 :            : 
      92         [ +  - ]:         22 :     return ExpandValue(fVal, GetFormat(), GetLanguage());
      93                 :            : }
      94                 :            : 
      95                 :         52 : SwField* SwDateTimeField::Copy() const
      96                 :            : {
      97                 :            :     SwDateTimeField *pTmp =
      98                 :         52 :         new SwDateTimeField((SwDateTimeFieldType*)GetTyp(), nSubType,
      99         [ +  - ]:         52 :                                             GetFormat(), GetLanguage());
     100                 :            : 
     101         [ +  - ]:         52 :     pTmp->SetValue(GetValue());
     102                 :         52 :     pTmp->SetOffset(nOffset);
     103                 :         52 :     pTmp->SetAutomaticLanguage(IsAutomaticLanguage());
     104                 :            : 
     105                 :         52 :     return pTmp;
     106                 :            : }
     107                 :            : 
     108                 :        141 : sal_uInt16 SwDateTimeField::GetSubType() const
     109                 :            : {
     110                 :        141 :     return nSubType;
     111                 :            : }
     112                 :            : 
     113                 :          0 : void SwDateTimeField::SetSubType(sal_uInt16 nType)
     114                 :            : {
     115                 :          0 :     nSubType = nType;
     116                 :          0 : }
     117                 :            : 
     118                 :          0 : void SwDateTimeField::SetPar2(const rtl::OUString& rStr)
     119                 :            : {
     120                 :          0 :     nOffset = rStr.toInt32();
     121                 :          0 : }
     122                 :            : 
     123                 :          0 : rtl::OUString SwDateTimeField::GetPar2() const
     124                 :            : {
     125         [ #  # ]:          0 :     if (nOffset)
     126                 :          0 :         return rtl::OUString::valueOf(static_cast<sal_Int32>(nOffset));
     127                 :          0 :     return rtl::OUString();
     128                 :            : }
     129                 :            : 
     130                 :          0 : void SwDateTimeField::SetDateTime(const DateTime& rDT)
     131                 :            : {
     132         [ #  # ]:          0 :     SetValue(GetDateTime(GetDoc(), rDT));
     133                 :          0 : }
     134                 :            : 
     135                 :         74 : double SwDateTimeField::GetDateTime(SwDoc* pDoc, const DateTime& rDT)
     136                 :            : {
     137                 :         74 :     SvNumberFormatter* pFormatter = pDoc->GetNumberFormatter();
     138                 :         74 :     Date* pNullDate = pFormatter->GetNullDate();
     139                 :            : 
     140         [ +  - ]:         74 :     double fResult = rDT - DateTime(*pNullDate);
     141                 :            : 
     142                 :         74 :     return fResult;
     143                 :            : }
     144                 :            : 
     145                 :         52 : double SwDateTimeField::GetValue() const
     146                 :            : {
     147         [ -  + ]:         52 :     if (IsFixed())
     148                 :          0 :         return SwValueField::GetValue();
     149                 :            :     else
     150         [ +  - ]:         52 :         return GetDateTime(GetDoc(), DateTime( DateTime::SYSTEM ));
     151                 :            : }
     152                 :            : 
     153                 :          0 : Date SwDateTimeField::GetDate(sal_Bool bUseOffset) const
     154                 :            : {
     155                 :          0 :     SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
     156                 :          0 :     Date* pNullDate = pFormatter->GetNullDate();
     157                 :            : 
     158                 :          0 :     long nVal = static_cast<long>( GetValue() );
     159                 :            : 
     160 [ #  # ][ #  # ]:          0 :     if (bUseOffset && nOffset)
     161                 :          0 :         nVal += nOffset / 60 / 24;
     162                 :            : 
     163                 :          0 :     Date aDate = *pNullDate + nVal;
     164                 :            : 
     165                 :          0 :     return aDate;
     166                 :            : }
     167                 :            : 
     168                 :          0 : Time SwDateTimeField::GetTime(sal_Bool bUseOffset) const
     169                 :            : {
     170                 :            :     double fDummy;
     171         [ #  # ]:          0 :     double fFract = modf(GetValue(), &fDummy);
     172         [ #  # ]:          0 :     DateTime aDT((long)fDummy, 0);
     173         [ #  # ]:          0 :     aDT += fFract;
     174         [ #  # ]:          0 :     if (bUseOffset)
     175 [ #  # ][ #  # ]:          0 :          aDT += Time(0, nOffset);
     176         [ #  # ]:          0 :     return (Time)aDT;
     177                 :            : }
     178                 :            : 
     179                 :          3 : bool SwDateTimeField::QueryValue( uno::Any& rVal, sal_uInt16 nWhichId ) const
     180                 :            : {
     181   [ -  -  +  -  :          3 :     switch( nWhichId )
                   -  - ]
     182                 :            :     {
     183                 :            :     case FIELD_PROP_BOOL1:
     184                 :            :         {
     185         [ #  # ]:          0 :             sal_Bool bTmp = IsFixed();
     186         [ #  # ]:          0 :             rVal.setValue(&bTmp, ::getCppuBooleanType());
     187                 :            :         }
     188                 :          0 :         break;
     189                 :            :     case FIELD_PROP_BOOL2:
     190                 :            :         {
     191                 :          0 :             sal_Bool bTmp = IsDate();
     192         [ #  # ]:          0 :             rVal.setValue(&bTmp, ::getCppuBooleanType());
     193                 :            :         }
     194                 :          0 :         break;
     195                 :            :     case FIELD_PROP_FORMAT:
     196         [ +  - ]:          3 :         rVal <<= (sal_Int32)GetFormat();
     197                 :          3 :         break;
     198                 :            :     case FIELD_PROP_SUBTYPE:
     199         [ #  # ]:          0 :         rVal <<= (sal_Int32)nOffset;
     200                 :          0 :         break;
     201                 :            :     case FIELD_PROP_DATE_TIME:
     202                 :            :         {
     203 [ #  # ][ #  # ]:          0 :             DateTime aDateTime(GetDate(), GetTime());
                 [ #  # ]
     204                 :            : 
     205                 :          0 :             util::DateTime DateTimeValue;
     206                 :          0 :             DateTimeValue.HundredthSeconds = aDateTime.Get100Sec();
     207                 :          0 :             DateTimeValue.Seconds = aDateTime.GetSec();
     208                 :          0 :             DateTimeValue.Minutes = aDateTime.GetMin();
     209                 :          0 :             DateTimeValue.Hours = aDateTime.GetHour();
     210                 :          0 :             DateTimeValue.Day = aDateTime.GetDay();
     211                 :          0 :             DateTimeValue.Month = aDateTime.GetMonth();
     212                 :          0 :             DateTimeValue.Year = aDateTime.GetYear();
     213         [ #  # ]:          0 :             rVal <<= DateTimeValue;
     214                 :            :         }
     215                 :          0 :         break;
     216                 :            :     default:
     217                 :          0 :         return SwField::QueryValue(rVal, nWhichId);
     218                 :            :     }
     219                 :          3 :     return true;
     220                 :            : }
     221                 :            : 
     222                 :          0 : bool SwDateTimeField::PutValue( const uno::Any& rVal, sal_uInt16 nWhichId )
     223                 :            : {
     224                 :          0 :     sal_Int32 nTmp = 0;
     225   [ #  #  #  #  :          0 :     switch( nWhichId )
                   #  # ]
     226                 :            :     {
     227                 :            :     case FIELD_PROP_BOOL1:
     228         [ #  # ]:          0 :         if(*(sal_Bool*)rVal.getValue())
     229                 :          0 :             nSubType |= FIXEDFLD;
     230                 :            :         else
     231                 :          0 :             nSubType &= ~FIXEDFLD;
     232                 :          0 :         break;
     233                 :            :     case FIELD_PROP_BOOL2:
     234                 :          0 :         nSubType &=  ~(DATEFLD|TIMEFLD);
     235         [ #  # ]:          0 :         nSubType |= *(sal_Bool*)rVal.getValue() ? DATEFLD : TIMEFLD;
     236                 :          0 :         break;
     237                 :            :     case FIELD_PROP_FORMAT:
     238                 :          0 :         rVal >>= nTmp;
     239         [ #  # ]:          0 :         ChangeFormat(nTmp);
     240                 :          0 :         break;
     241                 :            :     case FIELD_PROP_SUBTYPE:
     242                 :          0 :         rVal >>= nTmp;
     243                 :          0 :         nOffset = nTmp;
     244                 :          0 :         break;
     245                 :            :     case FIELD_PROP_DATE_TIME:
     246                 :            :         {
     247                 :          0 :             util::DateTime aDateTimeValue;
     248 [ #  # ][ #  # ]:          0 :             if(!(rVal >>= aDateTimeValue))
     249                 :          0 :                 return sal_False;
     250                 :          0 :             DateTime aDateTime( DateTime::EMPTY );
     251         [ #  # ]:          0 :             aDateTime.Set100Sec(aDateTimeValue.HundredthSeconds);
     252         [ #  # ]:          0 :             aDateTime.SetSec(aDateTimeValue.Seconds);
     253         [ #  # ]:          0 :             aDateTime.SetMin(aDateTimeValue.Minutes);
     254         [ #  # ]:          0 :             aDateTime.SetHour(aDateTimeValue.Hours);
     255         [ #  # ]:          0 :             aDateTime.SetDay(aDateTimeValue.Day);
     256         [ #  # ]:          0 :             aDateTime.SetMonth(aDateTimeValue.Month);
     257         [ #  # ]:          0 :             aDateTime.SetYear(aDateTimeValue.Year);
     258         [ #  # ]:          0 :             SetDateTime(aDateTime);
     259                 :            :         }
     260                 :          0 :         break;
     261                 :            :         default:
     262         [ #  # ]:          0 :             return SwField::PutValue(rVal, nWhichId);
     263                 :            :     }
     264                 :          0 :     return true;
     265                 :            : }
     266                 :            : 
     267                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10