diff options
Diffstat (limited to 'basic/source/runtime/methods.cxx')
-rw-r--r-- | basic/source/runtime/methods.cxx | 200 |
1 files changed, 194 insertions, 6 deletions
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx index fb01bdbfb989..048ca0c3a716 100644 --- a/basic/source/runtime/methods.cxx +++ b/basic/source/runtime/methods.cxx @@ -19,6 +19,7 @@ #include <tools/date.hxx> #include <basic/sbxvar.hxx> +#include <basic/sbuno.hxx> #include <osl/process.h> #include <vcl/dibtools.hxx> #include <vcl/svapp.hxx> @@ -1857,6 +1858,177 @@ sal_Int16 implGetDateMonth( double aDate ) return nRet; } +::com::sun::star::util::Date SbxDateToUNODate( const SbxValue* const pVal ) +{ + double aDate = pVal->GetDate(); + + com::sun::star::util::Date aUnoDate; + aUnoDate.Day = implGetDateDay ( aDate ); + aUnoDate.Month = implGetDateMonth( aDate ); + aUnoDate.Year = implGetDateYear ( aDate ); + + return aUnoDate; +} + +void SbxDateFromUNODate( SbxValue *pVal, const ::com::sun::star::util::Date& aUnoDate) +{ + double dDate; + if( implDateSerial( aUnoDate.Year, aUnoDate.Month, aUnoDate.Day, dDate ) ) + { + pVal->PutDate( dDate ); + } +} + +// Function to convert date to UNO date (com.sun.star.util.Date) +RTLFUNC(CDateToUnoDate) +{ + (void)pBasic; + (void)bWrite; + + if ( rPar.Count() != 2 ) + { + StarBASIC::Error( SbERR_BAD_ARGUMENT ); + return; + } + + unoToSbxValue(rPar.Get(0), Any(SbxDateToUNODate(rPar.Get(1)))); +} + +// Function to convert date from UNO date (com.sun.star.util.Date) +RTLFUNC(CDateFromUnoDate) +{ + (void)pBasic; + (void)bWrite; + + if ( rPar.Count() != 2 || rPar.Get(1)->GetType() != SbxOBJECT ) + { + StarBASIC::Error( SbERR_BAD_ARGUMENT ); + return; + } + + Any aAny (sbxToUnoValue(rPar.Get(1), ::getCppuType( (com::sun::star::util::Date*)0 ))); + com::sun::star::util::Date aUnoDate; + if(aAny >>= aUnoDate) + SbxDateFromUNODate(rPar.Get(0), aUnoDate); + else + SbxBase::SetError( SbxERR_CONVERSION ); +} + +::com::sun::star::util::Time SbxDateToUNOTime( const SbxValue* const pVal ) +{ + double aDate = pVal->GetDate(); + + com::sun::star::util::Time aUnoTime; + aUnoTime.Hours = implGetHour ( aDate ); + aUnoTime.Minutes = implGetMinute ( aDate ); + aUnoTime.Seconds = implGetSecond ( aDate ); + aUnoTime.NanoSeconds = 0; + + return aUnoTime; +} + +void SbxDateFromUNOTime( SbxValue *pVal, const ::com::sun::star::util::Time& aUnoTime) +{ + pVal->PutDate( implTimeSerial(aUnoTime.Hours, aUnoTime.Minutes, aUnoTime.Seconds) ); +} + +// Function to convert date to UNO time (com.sun.star.util.Time) +RTLFUNC(CDateToUnoTime) +{ + (void)pBasic; + (void)bWrite; + + if ( rPar.Count() != 2 ) + { + StarBASIC::Error( SbERR_BAD_ARGUMENT ); + return; + } + + unoToSbxValue(rPar.Get(0), Any(SbxDateToUNOTime(rPar.Get(1)))); +} + +// Function to convert date from UNO time (com.sun.star.util.Time) +RTLFUNC(CDateFromUnoTime) +{ + (void)pBasic; + (void)bWrite; + + if ( rPar.Count() != 2 || rPar.Get(1)->GetType() != SbxOBJECT ) + { + StarBASIC::Error( SbERR_BAD_ARGUMENT ); + return; + } + + Any aAny (sbxToUnoValue(rPar.Get(1), ::getCppuType( (com::sun::star::util::Time*)0 ))); + com::sun::star::util::Time aUnoTime; + if(aAny >>= aUnoTime) + SbxDateFromUNOTime(rPar.Get(0), aUnoTime); + else + SbxBase::SetError( SbxERR_CONVERSION ); +} + +::com::sun::star::util::DateTime SbxDateToUNODateTime( const SbxValue* const pVal ) +{ + double aDate = pVal->GetDate(); + + com::sun::star::util::DateTime aUnoDT; + aUnoDT.Day = implGetDateDay ( aDate ); + aUnoDT.Month = implGetDateMonth( aDate ); + aUnoDT.Year = implGetDateYear ( aDate ); + aUnoDT.Hours = implGetHour ( aDate ); + aUnoDT.Minutes = implGetMinute ( aDate ); + aUnoDT.Seconds = implGetSecond ( aDate ); + aUnoDT.NanoSeconds = 0; + + return aUnoDT; +} + +void SbxDateFromUNODateTime( SbxValue *pVal, const ::com::sun::star::util::DateTime& aUnoDT) +{ + double dDate; + if( implDateTimeSerial( aUnoDT.Year, aUnoDT.Month, aUnoDT.Day, + aUnoDT.Hours, aUnoDT.Minutes, aUnoDT.Seconds, + dDate ) ) + { + pVal->PutDate( dDate ); + } +} + +// Function to convert date to UNO date (com.sun.star.util.Date) +RTLFUNC(CDateToUnoDateTime) +{ + (void)pBasic; + (void)bWrite; + + if ( rPar.Count() != 2 ) + { + StarBASIC::Error( SbERR_BAD_ARGUMENT ); + return; + } + + unoToSbxValue(rPar.Get(0), Any(SbxDateToUNODateTime(rPar.Get(1)))); +} + +// Function to convert date from UNO date (com.sun.star.util.Date) +RTLFUNC(CDateFromUnoDateTime) +{ + (void)pBasic; + (void)bWrite; + + if ( rPar.Count() != 2 || rPar.Get(1)->GetType() != SbxOBJECT ) + { + StarBASIC::Error( SbERR_BAD_ARGUMENT ); + return; + } + + Any aAny (sbxToUnoValue(rPar.Get(1), ::getCppuType( (com::sun::star::util::DateTime*)0 ))); + com::sun::star::util::DateTime aUnoDT; + if(aAny >>= aUnoDT) + SbxDateFromUNODateTime(rPar.Get(0), aUnoDT); + else + SbxBase::SetError( SbxERR_CONVERSION ); +} + // Function to convert date to ISO 8601 date format RTLFUNC(CDateToIso) { @@ -1954,12 +2126,7 @@ RTLFUNC(TimeSerial) return; } - sal_Int32 nSeconds = nHour; - nSeconds *= 3600; - nSeconds += nMinute * 60; - nSeconds += nSecond; - double nDays = ((double)nSeconds) / (double)(86400.0); - rPar.Get(0)->PutDate( nDays ); // JSM + rPar.Get(0)->PutDate( implTimeSerial(nHour, nMinute, nSecond) ); // JSM } RTLFUNC(DateValue) @@ -4809,6 +4976,27 @@ bool implDateSerial( sal_Int16 nYear, sal_Int16 nMonth, sal_Int16 nDay, double& return true; } +double implTimeSerial( sal_Int16 nHours, sal_Int16 nMinutes, sal_Int16 nSeconds ) +{ + return + static_cast<double>( nHours * ::Time::secondPerHour + + nMinutes * ::Time::secondPerMinute + + nSeconds) + / + static_cast<double>( ::Time::secondPerDay ); +} + +bool implDateTimeSerial( sal_Int16 nYear, sal_Int16 nMonth, sal_Int16 nDay, + sal_Int16 nHour, sal_Int16 nMinute, sal_Int16 nSecond, + double& rdRet ) +{ + double dDate; + if(!implDateSerial(nYear, nMonth, nDay, dDate)) + return false; + rdRet += dDate + implTimeSerial(nHour, nMinute, nSecond); + return true; +} + sal_Int16 implGetMinute( double dDate ) { if( dDate < 0.0 ) |