summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2015-08-12 14:29:25 +0200
committerEike Rathke <erack@redhat.com>2015-08-12 14:34:28 +0200
commit9d370f2bb9f2af1b3acc1531f1e71b0ded36e40f (patch)
treecae00f9ac8dc70ff398167aad3bba66bbed53715
parentc1c142dc64f96791ebbaf03caeb3ff1852a7598f (diff)
move date/time guess work to SvNumberFormatter::GuessDateTimeFormat()
Change-Id: I26f7c47f5b3cf4a3c4274832448d9c8076981af0
-rw-r--r--chart2/source/tools/DiagramHelper.cxx33
-rw-r--r--include/svl/zforlist.hxx9
-rw-r--r--svl/source/numbers/zforlist.cxx86
3 files changed, 72 insertions, 56 deletions
diff --git a/chart2/source/tools/DiagramHelper.cxx b/chart2/source/tools/DiagramHelper.cxx
index 3dcbf4b2b17c..162bdf67169c 100644
--- a/chart2/source/tools/DiagramHelper.cxx
+++ b/chart2/source/tools/DiagramHelper.cxx
@@ -1202,38 +1202,9 @@ sal_Int32 DiagramHelper::getDateTimeInputNumberFormat( const Reference< util::XN
SAL_WARN("chart2", "DiagramHelper::getDateTimeInputNumberFormat - no SvNumberFormatter");
else
{
- // Categorize the format according to the implementation of
- // SvNumberFormatter::GetEditFormat(), making assumptions about what
- // would be time only.
- /* TODO: implement a method at SvNumberFormatter that does this and
- * call instead, if Chart isn't able transport the proper format of the
- * Axis, which of course would be much better.. */
short nType;
- if (0.0 <= fNumber && fNumber < 1.0)
- {
- // Clearly a time.
- nType = util::NumberFormat::TIME;
- nRet = pNumFormatter->GetFormatIndex( NF_TIME_HHMM, LANGUAGE_SYSTEM);
- }
- else if (fabs( fNumber) * 24 < 0x7fff)
- {
- // Assuming time within 32k hours or 3.7 years.
- nType = util::NumberFormat::TIME;
- nRet = pNumFormatter->GetFormatIndex( NF_TIME_HH_MMSS, LANGUAGE_SYSTEM);
- }
- else if (rtl::math::approxFloor( fNumber) != fNumber)
- {
- // Date+Time.
- nType = util::NumberFormat::DATETIME;
- nRet = pNumFormatter->GetFormatIndex( NF_DATETIME_SYS_DDMMYYYY_HHMMSS, LANGUAGE_SYSTEM);
- }
- else
- {
- // Date only.
- nType = util::NumberFormat::DATE;
- nRet = pNumFormatter->GetFormatIndex( NF_DATE_SYS_DDMMYYYY, LANGUAGE_SYSTEM);
- }
-
+ // Obtain best matching date, time or datetime format.
+ nRet = pNumFormatter->GuessDateTimeFormat( nType, fNumber, LANGUAGE_SYSTEM);
// Obtain the corresponding edit format.
nRet = pNumFormatter->GetEditFormat( fNumber, nRet, nType, LANGUAGE_SYSTEM, NULL);
}
diff --git a/include/svl/zforlist.hxx b/include/svl/zforlist.hxx
index b22aeef4ff0f..a6e8732618e3 100644
--- a/include/svl/zforlist.hxx
+++ b/include/svl/zforlist.hxx
@@ -572,6 +572,15 @@ public:
/// Whether nFIndex is a special builtin format
bool IsSpecialStandardFormat( sal_uInt32 nFIndex, LanguageType eLnge );
+ /** Return a time format that best matches fNumber. */
+ sal_uInt32 GetTimeFormat( double fNumber, LanguageType eLnge );
+
+ /** Return a format and type that best matches the value of fNumber if
+ fNumber is assumed to be a date, time or datetime value, but unknown
+ which. Originally introduced for Chart databrowser editor, probably
+ should not be used otherwise. */
+ sal_uInt32 GuessDateTimeFormat( short& rType, double fNumber, LanguageType eLnge );
+
/** Return the corresponding edit format of a format. */
sal_uInt32 GetEditFormat( double fNumber, sal_uInt32 nFIndex, short eType,
LanguageType eLnge, SvNumberformat* pFormat );
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 )