diff options
author | Eike Rathke <erack@redhat.com> | 2017-05-02 20:52:02 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2017-05-02 21:12:11 +0200 |
commit | 1edd4229904575ea103730ac15254b402eb86709 (patch) | |
tree | 18dd2cbb7ae9567899d910eaa2886dbd87388876 /tools/source | |
parent | 246a2a54662eb52468f9a411b315a4300aaa17c0 (diff) |
Date::Normalize: handle day 0 and empty date
* Empty date (initialized with Date::EMPTY == all 0) stays empty.
* Day 0 is normalized to the last day of the previous month.
* Day 0 AND month 0 is also normalized to the last day of the previous month
(and not the last day of the previous-1 month).
* Before,
* all day 0 cases weren't handled at all and day 0 stayed day 0, which
doesn't make sense in a Normalize() context
* empty date wasn't detected and resulted in nonsense date -0001-12-00
Change-Id: Ib12ff7694e1adb17724af038a266f6f284285f36
Diffstat (limited to 'tools/source')
-rw-r--r-- | tools/source/datetime/tdate.cxx | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tools/source/datetime/tdate.cxx b/tools/source/datetime/tdate.cxx index 9815716ebe3f..3dd8f68b3ced 100644 --- a/tools/source/datetime/tdate.cxx +++ b/tools/source/datetime/tdate.cxx @@ -493,6 +493,18 @@ bool Date::Normalize( sal_uInt16 & rDay, sal_uInt16 & rMonth, sal_Int16 & rYear if (IsValidDate( rDay, rMonth, rYear)) return false; + if (rDay == 0 && rMonth == 0 && rYear == 0) + return false; // empty date + + if (rDay == 0) + { + if (rMonth == 0) + ; // nothing, handled below + else + --rMonth; + // Last day of month is determined at the end. + } + if (rMonth > 12) { rYear += rMonth / 12; @@ -550,6 +562,10 @@ bool Date::Normalize( sal_uInt16 & rDay, sal_uInt16 & rMonth, sal_Int16 & rYear } } } + + if (rDay == 0) + rDay = ImplDaysInMonth( rMonth, rYear); + return true; } |