From 3bb877e17f210b2aeb96a6817831e1a249719ac6 Mon Sep 17 00:00:00 2001 From: Gregor Wolf Date: Tue, 1 May 2012 18:36:19 +0000 Subject: [PATCH] ready to test #166 corrected excel_string_to_date and extended the unit test git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@310 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049 --- ZA2X/CLAS/ZCL_EXCEL_COMMON.slnk | 43 ++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/ZA2X/CLAS/ZCL_EXCEL_COMMON.slnk b/ZA2X/CLAS/ZCL_EXCEL_COMMON.slnk index 1e387c7..72870e3 100644 --- a/ZA2X/CLAS/ZCL_EXCEL_COMMON.slnk +++ b/ZA2X/CLAS/ZCL_EXCEL_COMMON.slnk @@ -532,6 +532,37 @@ CLASS lcl_excel_common_test IMPLEMENTATION. level = if_aunit_constants=>critical " Error Severity ). ENDTRY. +* Check around the "Excel Leap Year" 1900 + TRY. + ep_value = zcl_excel_common=>excel_string_to_date( '59' ). + + cl_abap_unit_assert=>assert_equals( + act = ep_value + exp = '19000228' + msg = 'Wrong date conversion' + level = if_aunit_constants=>critical + ). + CATCH zcx_excel INTO lx_excel. + cl_abap_unit_assert=>fail( + msg = 'unexpected exception' + level = if_aunit_constants=>critical " Error Severity + ). + ENDTRY. + TRY. + ep_value = zcl_excel_common=>excel_string_to_date( '61' ). + + cl_abap_unit_assert=>assert_equals( + act = ep_value + exp = '19000301' + msg = 'Wrong date conversion' + level = if_aunit_constants=>critical + ). + CATCH zcx_excel INTO lx_excel. + cl_abap_unit_assert=>fail( + msg = 'unexpected exception' + level = if_aunit_constants=>critical " Error Severity + ). + ENDTRY. * Test 2. Simple test TRY. @@ -1062,18 +1093,24 @@ endmethod. - method EXCEL_STRING_TO_DATE. + METHOD excel_string_to_date. DATA: lv_date_int TYPE i. - TRY . + TRY. lv_date_int = ip_value. ep_value = lv_date_int + c_excel_baseline_date - 2. + " Needed hack caused by the problem that: + " Excel 2000 incorrectly assumes that the year 1900 is a leap year + " http://support.microsoft.com/kb/214326/en-us + IF ep_value < c_excel_1900_leap_year. + ep_value = ep_value + 1. + ENDIF. CATCH cx_sy_conversion_error. RAISE EXCEPTION TYPE zcx_excel EXPORTING error = 'Index out of bounds'. ENDTRY. -endmethod. +ENDMETHOD.