From ffeb1b1046ef240ee455183a502e450232416266 Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Thu, 21 Jul 2016 20:15:53 -0400 Subject: [PATCH] remove unneeded number formats and finish testing number format --- include/xlnt/styles/number_format.hpp | 9 +--- source/cell/cell.cpp | 2 +- source/detail/number_formatter.cpp | 2 +- source/styles/number_format.cpp | 50 ++-------------------- source/styles/tests/test_number_format.hpp | 39 +++++++++++++++++ 5 files changed, 46 insertions(+), 56 deletions(-) diff --git a/include/xlnt/styles/number_format.hpp b/include/xlnt/styles/number_format.hpp index dc32d02f..e3160911 100644 --- a/include/xlnt/styles/number_format.hpp +++ b/include/xlnt/styles/number_format.hpp @@ -47,7 +47,7 @@ public: static const number_format percentage(); static const number_format percentage_00(); static const number_format date_yyyymmdd2(); - static const number_format date_yyyymmdd(); + static const number_format date_yymmdd(); static const number_format date_ddmmyyyy(); static const number_format date_dmyslash(); static const number_format date_dmyminus(); @@ -65,13 +65,6 @@ public: static const number_format date_time4(); static const number_format date_time5(); static const number_format date_time6(); - static const number_format date_time7(); - static const number_format date_time8(); - static const number_format date_timedelta(); - static const number_format date_yyyymmddslash(); - static const number_format currency_usd_simple(); - static const number_format currency_usd(); - static const number_format currency_eur_simple(); static number_format from_builtin_id(std::size_t builtin_id); diff --git a/source/cell/cell.cpp b/source/cell/cell.cpp index d51d8d05..57d98eb8 100644 --- a/source/cell/cell.cpp +++ b/source/cell/cell.cpp @@ -383,7 +383,7 @@ XLNT_FUNCTION void cell::set_value(timedelta t) { d_->type_ = type::numeric; d_->value_numeric_ = t.to_number(); - set_number_format(number_format::date_timedelta()); + set_number_format(number_format("[hh]:mm:ss")); } row_t cell::get_row() const diff --git a/source/detail/number_formatter.cpp b/source/detail/number_formatter.cpp index 47d91efa..52b9a9df 100644 --- a/source/detail/number_formatter.cpp +++ b/source/detail/number_formatter.cpp @@ -1593,7 +1593,7 @@ std::string number_formatter::format_number(const format_code &format, long doub break; case template_part::template_type::bad: - throw std::runtime_error("bad state"); + throw std::runtime_error("bad format"); } } diff --git a/source/styles/number_format.cpp b/source/styles/number_format.cpp index 5200ae76..bf5abfd6 100644 --- a/source/styles/number_format.cpp +++ b/source/styles/number_format.cpp @@ -124,7 +124,7 @@ const number_format number_format::date_yyyymmdd2() return *format; } -const number_format number_format::date_yyyymmdd() +const number_format number_format::date_yymmdd() { static const number_format *format = new number_format("yy-mm-dd"); return *format; @@ -138,13 +138,13 @@ const number_format number_format::date_ddmmyyyy() const number_format number_format::date_dmyslash() { - static const number_format *format = new number_format("d/m/y"); + static const number_format *format = new number_format("d/m/yy"); return *format; } const number_format number_format::date_dmyminus() { - static const number_format *format = new number_format("d-m-y"); + static const number_format *format = new number_format("d-m-yy"); return *format; } @@ -156,7 +156,7 @@ const number_format number_format::date_dmminus() const number_format number_format::date_myminus() { - static const number_format *format = new number_format("m-y"); + static const number_format *format = new number_format("m-yy"); return *format; } @@ -232,48 +232,6 @@ const number_format number_format::date_time6() return *format; } -const number_format number_format::date_time7() -{ - static const number_format *format = new number_format("i:s.S"); - return *format; -} - -const number_format number_format::date_time8() -{ - static const number_format *format = new number_format("h:mm:ss@"); - return *format; -} - -const number_format number_format::date_timedelta() -{ - static const number_format *format = new number_format("[hh]:mm:ss"); - return *format; -} - -const number_format number_format::date_yyyymmddslash() -{ - static const number_format *format = new number_format("yy/mm/dd@"); - return *format; -} - -const number_format number_format::currency_usd_simple() -{ - static const number_format *format = new number_format("\"$\"#,##0.00_-"); - return *format; -} - -const number_format number_format::currency_usd() -{ - static const number_format *format = new number_format("$#,##0_-"); - return *format; -} - -const number_format number_format::currency_eur_simple() -{ - static const number_format *format = new number_format("[$EUR ]#,##0.00_-"); - return *format; -} - number_format::number_format() : number_format(general()) { } diff --git a/source/styles/tests/test_number_format.hpp b/source/styles/tests/test_number_format.hpp index 5014678c..ec0b127d 100644 --- a/source/styles/tests/test_number_format.hpp +++ b/source/styles/tests/test_number_format.hpp @@ -10,6 +10,21 @@ class test_number_format : public CxxTest::TestSuite { public: + void test_basic() + { + xlnt::number_format no_id("#\\x\\y\\z"); + TS_ASSERT_THROWS(no_id.get_id(), std::runtime_error); + + xlnt::number_format id("General", 200); + TS_ASSERT_EQUALS(id.get_id(), 200); + TS_ASSERT_EQUALS(id.get_format_string(), "General"); + + xlnt::number_format general(0); + TS_ASSERT_EQUALS(general, xlnt::number_format::general()); + TS_ASSERT_EQUALS(general.get_id(), 0); + TS_ASSERT_EQUALS(general.get_format_string(), "General"); + } + void test_simple_format() { xlnt::number_format nf; @@ -800,4 +815,28 @@ public: { format_and_test(xlnt::number_format::text(), {{"42503.1234", "-42503.1234", "0", "text"}}); } + + // yy-mm-dd + void test_builtin_format_date_yyyymmdd() + { + format_and_test(xlnt::number_format::date_yymmdd(), {{"16-05-13", "###########", "00-01-00", "text"}}); + } + + // d/m/y + void test_builtin_format_date_dmyslash() + { + format_and_test(xlnt::number_format::date_dmyslash(), {{"13/5/16", "###########", "0/1/00", "text"}}); + } + + // d-m-y + void test_builtin_format_date_dmyminus() + { + format_and_test(xlnt::number_format::date_dmyminus(), {{"13-5-16", "###########", "0-1-00", "text"}}); + } + + // d-m + void test_builtin_format_date_dmminus() + { + format_and_test(xlnt::number_format::date_dmminus(), {{"13-5", "###########", "0-1", "text"}}); + } };