summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2018-11-13 15:04:02 +0100
committerEike Rathke <erack@redhat.com>2018-11-13 21:51:25 +0100
commit9950e50a0f304362f569d4dc0bd9ca30b7b6291d (patch)
treee5dbfa92aaac607b7ef4423de21f33f146b70ad6 /basic
parentd3368c174f3e2cfed76f93cc149f80a76605d431 (diff)
Set error also in non-UNO/UCB case file date failures, tdf#121337 follow-up
And do not attempt to format an odd date in case of failure. Change-Id: I82e93f9e473f42735b6a7e7b634b14ee7f09941d Reviewed-on: https://gerrit.libreoffice.org/63331 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Jenkins
Diffstat (limited to 'basic')
-rw-r--r--basic/source/runtime/methods.cxx83
1 files changed, 55 insertions, 28 deletions
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index b2f639e1a6c4..84202c8d4e45 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -3035,43 +3035,70 @@ void SbRtl_FileDateTime(StarBASIC *, SbxArray & rPar, bool)
}
else
{
- DirectoryItem aItem;
- DirectoryItem::get( getFullPath( aPath ), aItem );
- FileStatus aFileStatus( osl_FileStatus_Mask_ModifyTime );
- aItem.getFileStatus( aFileStatus );
- TimeValue aTimeVal = aFileStatus.getModifyTime();
- oslDateTime aDT;
- osl_getDateTimeFromTimeValue( &aTimeVal, &aDT );
+ bool bSuccess = false;
+ do
+ {
+ DirectoryItem aItem;
+ if (DirectoryItem::get( getFullPath( aPath ), aItem ) != FileBase::E_None)
+ break;
- aTime = tools::Time( aDT.Hours, aDT.Minutes, aDT.Seconds, aDT.NanoSeconds );
- aDate = Date( aDT.Day, aDT.Month, aDT.Year );
- }
+ FileStatus aFileStatus( osl_FileStatus_Mask_ModifyTime );
+ if (aItem.getFileStatus( aFileStatus ) != FileBase::E_None)
+ break;
- double fSerial = aDate.IsEmpty() ? 0 : static_cast<double>(GetDayDiff( aDate ));
- long nSeconds = aTime.GetHour();
- nSeconds *= 3600;
- nSeconds += aTime.GetMin() * 60;
- nSeconds += aTime.GetSec();
- double nDays = static_cast<double>(nSeconds) / (24.0*3600.0);
- fSerial += nDays;
+ TimeValue aTimeVal = aFileStatus.getModifyTime();
+ oslDateTime aDT;
+ if (!osl_getDateTimeFromTimeValue( &aTimeVal, &aDT ))
+ // Strictly spoken this is not an i/o error but some other failure.
+ break;
- Color* pCol;
+ aTime = tools::Time( aDT.Hours, aDT.Minutes, aDT.Seconds, aDT.NanoSeconds );
+ aDate = Date( aDT.Day, aDT.Month, aDT.Year );
+ bSuccess = true;
+ }
+ while(false);
- std::shared_ptr<SvNumberFormatter> pFormatter;
- sal_uInt32 nIndex;
- if( GetSbData()->pInst )
+ if (!bSuccess)
+ StarBASIC::Error( ERRCODE_IO_GENERAL );
+ }
+
+ // An empty date shall not result in a formatted null-date (1899-12-30
+ // or 1900-01-01) or even worse -0001-12-03 or some such due to how
+ // GetDayDiff() treats things. There should be an error set in this
+ // case anyway because of a missing file or other error above, but.. so
+ // do not even bother to use the number formatter.
+ OUString aRes;
+ if (aDate.IsEmpty())
{
- pFormatter = GetSbData()->pInst->GetNumberFormatter();
- nIndex = GetSbData()->pInst->GetStdDateTimeIdx();
+ aRes = "0000-00-00 00:00:00";
}
else
{
- sal_uInt32 n;
- pFormatter = SbiInstance::PrepareNumberFormatter( n, n, nIndex );
- }
+ double fSerial = static_cast<double>(GetDayDiff( aDate ));
+ long nSeconds = aTime.GetHour();
+ nSeconds *= 3600;
+ nSeconds += aTime.GetMin() * 60;
+ nSeconds += aTime.GetSec();
+ double nDays = static_cast<double>(nSeconds) / (24.0*3600.0);
+ fSerial += nDays;
- OUString aRes;
- pFormatter->GetOutputString( fSerial, nIndex, aRes, &pCol );
+ Color* pCol;
+
+ std::shared_ptr<SvNumberFormatter> pFormatter;
+ sal_uInt32 nIndex;
+ if( GetSbData()->pInst )
+ {
+ pFormatter = GetSbData()->pInst->GetNumberFormatter();
+ nIndex = GetSbData()->pInst->GetStdDateTimeIdx();
+ }
+ else
+ {
+ sal_uInt32 n;
+ pFormatter = SbiInstance::PrepareNumberFormatter( n, n, nIndex );
+ }
+
+ pFormatter->GetOutputString( fSerial, nIndex, aRes, &pCol );
+ }
rPar.Get(0)->PutString( aRes );
}
}