LCOV - code coverage report
Current view: top level - connectivity/source/drivers/file - FDateFunctions.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 155 0.0 %
Date: 2014-04-14 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             : 
      21             : #include "file/FDateFunctions.hxx"
      22             : #include <tools/date.hxx>
      23             : #include <tools/time.hxx>
      24             : #include <tools/datetime.hxx>
      25             : 
      26             : using namespace connectivity;
      27             : using namespace connectivity::file;
      28             : 
      29           0 : ORowSetValue OOp_DayOfWeek::operate(const ORowSetValue& lhs) const
      30             : {
      31           0 :     if ( lhs.isNull() )
      32           0 :         return lhs;
      33             : 
      34           0 :     sal_Int32 nRet = 0;
      35           0 :     ::com::sun::star::util::Date aD = lhs;
      36           0 :     Date aDate(aD.Day,aD.Month,aD.Year);
      37           0 :     DayOfWeek eDayOfWeek = aDate.GetDayOfWeek();
      38           0 :     switch(eDayOfWeek)
      39             :     {
      40             :         case MONDAY:
      41           0 :             nRet = 2;
      42           0 :             break;
      43             :         case TUESDAY:
      44           0 :             nRet = 3;
      45           0 :             break;
      46             :         case WEDNESDAY:
      47           0 :             nRet = 4;
      48           0 :             break;
      49             :         case THURSDAY:
      50           0 :             nRet = 5;
      51           0 :             break;
      52             :         case FRIDAY:
      53           0 :             nRet = 6;
      54           0 :             break;
      55             :         case SATURDAY:
      56           0 :             nRet = 7;
      57           0 :             break;
      58             :         case SUNDAY:
      59           0 :             nRet = 1;
      60           0 :             break;
      61             :         default:
      62             :             OSL_FAIL("Error in enum values for date");
      63             :     }
      64           0 :     return nRet;
      65             : }
      66             : 
      67           0 : ORowSetValue OOp_DayOfMonth::operate(const ORowSetValue& lhs) const
      68             : {
      69           0 :     if ( lhs.isNull() )
      70           0 :         return lhs;
      71             : 
      72           0 :     ::com::sun::star::util::Date aD = lhs;
      73           0 :     return static_cast<sal_Int16>(aD.Day);
      74             : }
      75             : 
      76           0 : ORowSetValue OOp_DayOfYear::operate(const ORowSetValue& lhs) const
      77             : {
      78           0 :     if ( lhs.isNull() )
      79           0 :         return lhs;
      80             : 
      81           0 :     ::com::sun::star::util::Date aD = lhs;
      82           0 :     Date aDate(aD.Day,aD.Month,aD.Year);
      83           0 :     return static_cast<sal_Int16>(aDate.GetDayOfYear());
      84             : }
      85             : 
      86           0 : ORowSetValue OOp_Month::operate(const ORowSetValue& lhs) const
      87             : {
      88           0 :     if ( lhs.isNull() )
      89           0 :         return lhs;
      90             : 
      91           0 :     ::com::sun::star::util::Date aD = lhs;
      92           0 :     return static_cast<sal_Int16>(aD.Month);
      93             : }
      94             : 
      95           0 : ORowSetValue OOp_DayName::operate(const ORowSetValue& lhs) const
      96             : {
      97           0 :     if ( lhs.isNull() )
      98           0 :         return lhs;
      99             : 
     100           0 :     OUString sRet;
     101           0 :     ::com::sun::star::util::Date aD = lhs;
     102           0 :     Date aDate(aD.Day,aD.Month,aD.Year);
     103           0 :     DayOfWeek eDayOfWeek = aDate.GetDayOfWeek();
     104           0 :     switch(eDayOfWeek)
     105             :     {
     106             :         case MONDAY:
     107           0 :             sRet = "Monday";
     108           0 :             break;
     109             :         case TUESDAY:
     110           0 :             sRet = "Tuesday";
     111           0 :             break;
     112             :         case WEDNESDAY:
     113           0 :             sRet = "Wednesday";
     114           0 :             break;
     115             :         case THURSDAY:
     116           0 :             sRet = "Thursday";
     117           0 :             break;
     118             :         case FRIDAY:
     119           0 :             sRet = "Friday";
     120           0 :             break;
     121             :         case SATURDAY:
     122           0 :             sRet = "Saturday";
     123           0 :             break;
     124             :         case SUNDAY:
     125           0 :             sRet = "Sunday";
     126           0 :             break;
     127             :         default:
     128             :             OSL_FAIL("Error in enum values for date");
     129             :     }
     130           0 :     return sRet;
     131             : }
     132             : 
     133           0 : ORowSetValue OOp_MonthName::operate(const ORowSetValue& lhs) const
     134             : {
     135           0 :     if ( lhs.isNull() )
     136           0 :         return lhs;
     137             : 
     138           0 :     OUString sRet;
     139           0 :     ::com::sun::star::util::Date aD = lhs;
     140           0 :     switch(aD.Month)
     141             :     {
     142             :         case 1:
     143           0 :             sRet = "January";
     144           0 :             break;
     145             :         case 2:
     146           0 :             sRet = "February";
     147           0 :             break;
     148             :         case 3:
     149           0 :             sRet = "March";
     150           0 :             break;
     151             :         case 4:
     152           0 :             sRet = "April";
     153           0 :             break;
     154             :         case 5:
     155           0 :             sRet = "May";
     156           0 :             break;
     157             :         case 6:
     158           0 :             sRet = "June";
     159           0 :             break;
     160             :         case 7:
     161           0 :             sRet = "July";
     162           0 :             break;
     163             :         case 8:
     164           0 :             sRet = "August";
     165           0 :             break;
     166             :         case 9:
     167           0 :             sRet = "September";
     168           0 :             break;
     169             :         case 10:
     170           0 :             sRet = "October";
     171           0 :             break;
     172             :         case 11:
     173           0 :             sRet = "November";
     174           0 :             break;
     175             :         case 12:
     176           0 :             sRet = "December";
     177           0 :             break;
     178             :     }
     179           0 :     return sRet;
     180             : }
     181             : 
     182           0 : ORowSetValue OOp_Quarter::operate(const ORowSetValue& lhs) const
     183             : {
     184           0 :     if ( lhs.isNull() )
     185           0 :         return lhs;
     186             : 
     187           0 :     sal_Int32 nRet = 1;
     188           0 :     ::com::sun::star::util::Date aD = lhs;
     189           0 :     if ( aD.Month >= 4 && aD.Month < 7 )
     190           0 :         nRet = 2;
     191           0 :     else if ( aD.Month >= 7 && aD.Month < 10 )
     192           0 :         nRet = 3;
     193           0 :     else if ( aD.Month >= 10 && aD.Month <= 12 )
     194           0 :         nRet = 4;
     195           0 :     return nRet;
     196             : }
     197             : 
     198           0 : ORowSetValue OOp_Week::operate(const ::std::vector<ORowSetValue>& lhs) const
     199             : {
     200           0 :     if ( lhs.empty() || lhs.size() > 2 )
     201           0 :         return ORowSetValue();
     202             : 
     203           0 :     size_t nSize = lhs.size();
     204             : 
     205           0 :     ::com::sun::star::util::Date aD = lhs[nSize-1];
     206           0 :     Date aDate(aD.Day,aD.Month,aD.Year);
     207             : 
     208           0 :     sal_Int16 nStartDay = SUNDAY;
     209           0 :     if ( nSize == 2 && !lhs[0].isNull() )
     210           0 :         nStartDay = lhs[0];
     211             : 
     212           0 :     return static_cast<sal_Int16>(aDate.GetWeekOfYear(static_cast<DayOfWeek>(nStartDay)));
     213             : }
     214             : 
     215           0 : ORowSetValue OOp_Year::operate(const ORowSetValue& lhs) const
     216             : {
     217           0 :     if ( lhs.isNull() )
     218           0 :         return lhs;
     219             : 
     220           0 :     ::com::sun::star::util::Date aD = lhs;
     221           0 :     return static_cast<sal_Int16>(aD.Year);
     222             : }
     223             : 
     224           0 : ORowSetValue OOp_Hour::operate(const ORowSetValue& lhs) const
     225             : {
     226           0 :     if ( lhs.isNull() )
     227           0 :         return lhs;
     228             : 
     229           0 :     ::com::sun::star::util::Time aT = lhs;
     230           0 :     return static_cast<sal_Int16>(aT.Hours);
     231             : }
     232             : 
     233           0 : ORowSetValue OOp_Minute::operate(const ORowSetValue& lhs) const
     234             : {
     235           0 :     if ( lhs.isNull() )
     236           0 :         return lhs;
     237             : 
     238           0 :     ::com::sun::star::util::Time aT = lhs;
     239           0 :     return static_cast<sal_Int16>(aT.Minutes);
     240             : }
     241             : 
     242           0 : ORowSetValue OOp_Second::operate(const ORowSetValue& lhs) const
     243             : {
     244           0 :     if ( lhs.isNull() )
     245           0 :         return lhs;
     246             : 
     247           0 :     ::com::sun::star::util::Time aT = lhs;
     248           0 :     return static_cast<sal_Int16>(aT.Seconds);
     249             : }
     250             : 
     251           0 : ORowSetValue OOp_CurDate::operate(const ::std::vector<ORowSetValue>& lhs) const
     252             : {
     253           0 :     if ( !lhs.empty() )
     254           0 :         return ORowSetValue();
     255             : 
     256           0 :     Date aCurDate( Date::SYSTEM );
     257           0 :     return ::com::sun::star::util::Date(aCurDate.GetDay(),aCurDate.GetMonth(),aCurDate.GetYear());
     258             : }
     259             : 
     260           0 : ORowSetValue OOp_CurTime::operate(const ::std::vector<ORowSetValue>& lhs) const
     261             : {
     262           0 :     if ( !lhs.empty() )
     263           0 :         return ORowSetValue();
     264             : 
     265           0 :     Time aCurTime( Time::SYSTEM );
     266           0 :     return ::com::sun::star::util::Time(aCurTime.GetNanoSec(),
     267           0 :             aCurTime.GetSec(), aCurTime.GetMin(), aCurTime.GetHour(),
     268           0 :             false);
     269             : }
     270             : 
     271           0 : ORowSetValue OOp_Now::operate(const ::std::vector<ORowSetValue>& lhs) const
     272             : {
     273           0 :     if ( !lhs.empty() )
     274           0 :         return ORowSetValue();
     275             : 
     276           0 :     DateTime aCurTime( DateTime::SYSTEM );
     277           0 :     return ::com::sun::star::util::DateTime(aCurTime.GetNanoSec(),
     278           0 :             aCurTime.GetSec(), aCurTime.GetMin(), aCurTime.GetHour(),
     279           0 :             aCurTime.GetDay(), aCurTime.GetMonth(), aCurTime.GetYear(),
     280           0 :             false);
     281             : }
     282             : 
     283             : 
     284             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10