summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMatteo Casalin <matteo.casalin@yahoo.com>2015-10-27 23:14:31 +0100
committerMatteo Casalin <matteo.casalin@yahoo.com>2015-10-28 14:08:33 +0100
commit24c28ac7b08848f80001d6e69595804d3ab64b47 (patch)
treee953cfe5eba5a87bf8702d78199766314d6f65ec /tools
parent8e369625a442324d5a639fefc2481d421cd9b706 (diff)
Date: use support function for mapping years to days
and reduce scope for other local support functions. Change-Id: Id0d6b9a04ff67620f6dca39d62443a3f191d75ee
Diffstat (limited to 'tools')
-rw-r--r--tools/source/datetime/tdate.cxx19
1 files changed, 13 insertions, 6 deletions
diff --git a/tools/source/datetime/tdate.cxx b/tools/source/datetime/tdate.cxx
index b970d51da5ba..b957441864f1 100644
--- a/tools/source/datetime/tdate.cxx
+++ b/tools/source/datetime/tdate.cxx
@@ -31,6 +31,15 @@ static const sal_uInt16 aDaysInMonth[12] = { 31, 28, 31, 30, 31, 30,
#define MAX_DAYS 3636532
+namespace
+{
+
+inline long ImpYearToDays( sal_uInt16 nYear )
+{
+ const long nYr(static_cast<long>(nYear) - 1);
+ return nYr*365 + nYr/4 - nYr/100 + nYr/400;
+}
+
inline bool ImpIsLeapYear( sal_uInt16 nYear )
{
return ( ( ((nYear % 4) == 0) && ((nYear % 100) != 0) ) ||
@@ -51,6 +60,8 @@ inline sal_uInt16 ImplDaysInMonth( sal_uInt16 nMonth, sal_uInt16 nYear )
}
}
+}
+
// static
sal_uInt16 Date::GetDaysInMonth( sal_uInt16 nMonth, sal_uInt16 nYear )
{
@@ -75,12 +86,9 @@ long Date::GetAsNormalizedDays() const
long Date::DateToDays( sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear )
{
- long nDays;
-
Normalize( nDay, nMonth, nYear);
- nDays = ((sal_uIntPtr)nYear-1) * 365;
- nDays += ((nYear-1) / 4) - ((nYear-1) / 100) + ((nYear-1) / 400);
+ long nDays = ImpYearToDays(nYear);
for( sal_uInt16 i = 1; i < nMonth; i++ )
nDays += ImplDaysInMonth(i,nYear);
nDays += nDay;
@@ -98,8 +106,7 @@ static void DaysToDate( long nDays,
{
nTempDays = (long)nDays;
rYear = (sal_uInt16)((nTempDays / 365) - i);
- nTempDays -= ((sal_uIntPtr)rYear-1) * 365;
- nTempDays -= ((rYear-1) / 4) - ((rYear-1) / 100) + ((rYear-1) / 400);
+ nTempDays -= ImpYearToDays(rYear);
bCalc = false;
if ( nTempDays < 1 )
{