summaryrefslogtreecommitdiff
path: root/svl/source/numbers/zforlist.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'svl/source/numbers/zforlist.cxx')
-rw-r--r--svl/source/numbers/zforlist.cxx86
1 files changed, 61 insertions, 25 deletions
diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx
index 69ec74d7269e..4f18a0998bb4 100644
--- a/svl/source/numbers/zforlist.cxx
+++ b/svl/source/numbers/zforlist.cxx
@@ -1208,6 +1208,33 @@ sal_uInt32 SvNumberFormatter::GetStandardFormat( sal_uInt32 nFIndex, short eType
return GetStandardFormat( eType, eLnge );
}
+sal_uInt32 SvNumberFormatter::GetTimeFormat( double fNumber, LanguageType eLnge )
+{
+ bool bSign;
+ if ( fNumber < 0.0 )
+ {
+ bSign = true;
+ fNumber = -fNumber;
+ }
+ else
+ bSign = false;
+ double fSeconds = fNumber * 86400;
+ if ( floor( fSeconds + 0.5 ) * 100 != floor( fSeconds * 100 + 0.5 ) )
+ { // with 100th seconds
+ if ( bSign || fSeconds >= 3600 )
+ return GetFormatIndex( NF_TIME_HH_MMSS00, eLnge );
+ else
+ return GetFormatIndex( NF_TIME_MMSS00, eLnge );
+ }
+ else
+ {
+ if ( bSign || fNumber >= 1.0 )
+ return GetFormatIndex( NF_TIME_HH_MMSS, eLnge );
+ else
+ return GetStandardFormat( css::util::NumberFormat::TIME, eLnge );
+ }
+}
+
sal_uInt32 SvNumberFormatter::GetStandardFormat( double fNumber, sal_uInt32 nFIndex,
short eType, LanguageType eLnge )
{
@@ -1217,36 +1244,45 @@ sal_uInt32 SvNumberFormatter::GetStandardFormat( double fNumber, sal_uInt32 nFIn
switch( eType )
{
case css::util::NumberFormat::TIME :
- {
- bool bSign;
- if ( fNumber < 0.0 )
- {
- bSign = true;
- fNumber = -fNumber;
- }
- else
- bSign = false;
- double fSeconds = fNumber * 86400;
- if ( floor( fSeconds + 0.5 ) * 100 != floor( fSeconds * 100 + 0.5 ) )
- { // with 100th seconds
- if ( bSign || fSeconds >= 3600 )
- return GetFormatIndex( NF_TIME_HH_MMSS00, eLnge );
- else
- return GetFormatIndex( NF_TIME_MMSS00, eLnge );
- }
- else
- {
- if ( bSign || fNumber >= 1.0 )
- return GetFormatIndex( NF_TIME_HH_MMSS, eLnge );
- else
- return GetStandardFormat( eType, eLnge );
- }
- }
+ return GetTimeFormat( fNumber, eLnge);
default:
return GetStandardFormat( eType, eLnge );
}
}
+sal_uInt32 SvNumberFormatter::GuessDateTimeFormat( short& rType, double fNumber, LanguageType eLnge )
+{
+ // Categorize the format according to the implementation of
+ // SvNumberFormatter::GetEditFormat(), making assumptions about what
+ // would be time only.
+ sal_uInt32 nRet;
+ if (0.0 <= fNumber && fNumber < 1.0)
+ {
+ // Clearly a time.
+ rType = util::NumberFormat::TIME;
+ nRet = GetTimeFormat( fNumber, eLnge);
+ }
+ else if (fabs( fNumber) * 24 < 0x7fff)
+ {
+ // Assuming time within 32k hours or 3.7 years.
+ rType = util::NumberFormat::TIME;
+ nRet = GetTimeFormat( fNumber, eLnge);
+ }
+ else if (rtl::math::approxFloor( fNumber) != fNumber)
+ {
+ // Date+Time.
+ rType = util::NumberFormat::DATETIME;
+ nRet = GetFormatIndex( NF_DATETIME_SYS_DDMMYYYY_HHMMSS, eLnge);
+ }
+ else
+ {
+ // Date only.
+ rType = util::NumberFormat::DATE;
+ nRet = GetFormatIndex( NF_DATE_SYS_DDMMYYYY, eLnge);
+ }
+ return nRet;
+}
+
sal_uInt32 SvNumberFormatter::GetEditFormat( double fNumber, sal_uInt32 nFIndex,
short eType, LanguageType eLang,
SvNumberformat* pFormat )