mirror of
https://github.com/abap2xlsx/abap2xlsx.git
synced 2025-05-05 16:46:11 +08:00
Convert fields with date
Ignore decimals when coverting to date and ignore integer when converting to time
This commit is contained in:
parent
35425c3220
commit
aae48fe71a
|
@ -864,7 +864,7 @@ CLASS zcl_excel_common IMPLEMENTATION.
|
|||
CHECK ip_value IS NOT INITIAL AND ip_value CN ' 0'.
|
||||
|
||||
TRY.
|
||||
lv_date_int = ip_value.
|
||||
lv_date_int = floor( ip_value ).
|
||||
IF lv_date_int NOT BETWEEN 1 AND 2958465.
|
||||
zcx_excel=>raise_text( 'Unable to interpret date' ).
|
||||
ENDIF.
|
||||
|
@ -898,7 +898,7 @@ CLASS zcl_excel_common IMPLEMENTATION.
|
|||
|
||||
TRY.
|
||||
|
||||
lv_day_fraction = ip_value.
|
||||
lv_day_fraction = ip_value - floor( ip_value ).
|
||||
lv_seconds_in_day = lv_day_fraction * lc_seconds_in_day.
|
||||
|
||||
ep_value = lv_seconds_in_day.
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
CLASS lcl_excel_common_test DEFINITION DEFERRED.
|
||||
CLASS zcl_excel_common DEFINITION LOCAL FRIENDS lcl_excel_common_test.
|
||||
CLASS lcl_string_to_date_and_time DEFINITION DEFERRED.
|
||||
CLASS zcl_excel_common DEFINITION
|
||||
LOCAL FRIENDS lcl_excel_common_test
|
||||
lcl_string_to_date_and_time.
|
||||
|
||||
*----------------------------------------------------------------------*
|
||||
* CLASS lcl_Excel_Common_Test DEFINITION
|
||||
|
@ -1757,3 +1760,115 @@ CLASS lcl_excel_common_test IMPLEMENTATION.
|
|||
ENDMETHOD.
|
||||
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
|
||||
CLASS lcl_string_to_date_and_time DEFINITION FINAL FOR TESTING
|
||||
DURATION SHORT
|
||||
RISK LEVEL HARMLESS.
|
||||
|
||||
PRIVATE SECTION.
|
||||
CONSTANTS date_20230803 TYPE d VALUE '20230803'.
|
||||
CONSTANTS dbs1900_initial TYPE d VALUE '18991230'. "Serial date 0 in (default) 1900 date base system
|
||||
CONSTANTS dbs1900bc_initial TYPE d VALUE '18991231'. "Serial date 0 in 1900 backwards compatibility date base system
|
||||
CONSTANTS dbs1904bc_initial TYPE d VALUE '19040101'. "Serial date 0 in 1904 backwards compatibility date base system
|
||||
CONSTANTS time_140711 TYPE t VALUE '140711'.
|
||||
CONSTANTS time_initial TYPE t VALUE '000000'.
|
||||
CONSTANTS dbs1900_20230803_000000 TYPE string VALUE `45141.000000000000`. "Serial date 2023-08-03 time zero
|
||||
CONSTANTS dbs1900_00000000_140711 TYPE string VALUE `0.588321759256`. "Serial date zero time 14:07:11
|
||||
CONSTANTS dbs1900_20230803_140711 TYPE string VALUE `45141.588321759256`. "Serial date 2023-08-03 time 14:07:11
|
||||
|
||||
DATA cut TYPE REF TO zcl_excel_common.
|
||||
DATA excel_error TYPE REF TO zcx_excel.
|
||||
|
||||
METHODS:
|
||||
setup,
|
||||
teardown.
|
||||
|
||||
METHODS:
|
||||
date_to_date FOR TESTING RAISING cx_static_check,
|
||||
time_to_time FOR TESTING RAISING cx_static_check,
|
||||
datetime_to_date FOR TESTING RAISING cx_static_check,
|
||||
datetime_to_time FOR TESTING RAISING cx_static_check,
|
||||
date_to_time FOR TESTING RAISING cx_static_check,
|
||||
time_to_date FOR TESTING RAISING cx_static_check.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
|
||||
CLASS lcl_string_to_date_and_time IMPLEMENTATION.
|
||||
|
||||
METHOD setup.
|
||||
CREATE OBJECT cut.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD teardown.
|
||||
CLEAR cut.
|
||||
CLEAR excel_error.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD date_to_date.
|
||||
TRY.
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = cut->excel_string_to_date( dbs1900_20230803_000000 )
|
||||
exp = date_20230803 ).
|
||||
CATCH zcx_excel INTO excel_error.
|
||||
cl_abap_unit_assert=>fail( excel_error->get_text( ) ).
|
||||
ENDTRY.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD time_to_time.
|
||||
TRY.
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = cut->excel_string_to_time( dbs1900_00000000_140711 )
|
||||
exp = time_140711 ).
|
||||
CATCH zcx_excel INTO excel_error.
|
||||
cl_abap_unit_assert=>fail( excel_error->get_text( ) ).
|
||||
ENDTRY.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD datetime_to_date.
|
||||
TRY.
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = cut->excel_string_to_date( dbs1900_20230803_140711 )
|
||||
exp = date_20230803 ).
|
||||
CATCH zcx_excel INTO excel_error.
|
||||
cl_abap_unit_assert=>fail( excel_error->get_text( ) ).
|
||||
ENDTRY.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD datetime_to_time.
|
||||
TRY.
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = cut->excel_string_to_time( dbs1900_20230803_140711 )
|
||||
exp = time_140711 ).
|
||||
CATCH zcx_excel INTO excel_error.
|
||||
cl_abap_unit_assert=>fail( excel_error->get_text( ) ).
|
||||
ENDTRY.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD date_to_time.
|
||||
TRY.
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = cut->excel_string_to_time( dbs1900_20230803_000000 )
|
||||
exp = time_initial ).
|
||||
CATCH zcx_excel INTO excel_error.
|
||||
cl_abap_unit_assert=>fail( excel_error->get_text( ) ).
|
||||
ENDTRY.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD time_to_date.
|
||||
TRY.
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = cut->excel_string_to_date( dbs1900_00000000_140711 )
|
||||
exp = dbs1900_initial ).
|
||||
cl_abap_unit_assert=>fail( 'Until dates before 1900-01-01 are supported, an exception is expected' ).
|
||||
CATCH zcx_excel INTO excel_error.
|
||||
* cl_abap_unit_assert=>fail( excel_error->get_text( ) ).
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = excel_error->get_text( )
|
||||
exp = 'Unable to interpret date' ).
|
||||
ENDTRY.
|
||||
ENDMETHOD.
|
||||
|
||||
ENDCLASS.
|
||||
|
|
|
@ -120,11 +120,6 @@
|
|||
<LANGU>I</LANGU>
|
||||
<DESCRIPT>Excel baseline date</DESCRIPT>
|
||||
</SEOCOMPOTX>
|
||||
<SEOCOMPOTX>
|
||||
<CMPNAME>C_EXCEL_BASELINE_DATE</CMPNAME>
|
||||
<LANGU>E</LANGU>
|
||||
<DESCRIPT>Excel baseline date</DESCRIPT>
|
||||
</SEOCOMPOTX>
|
||||
<SEOCOMPOTX>
|
||||
<CMPNAME>C_EXCEL_BASELINE_DATE</CMPNAME>
|
||||
<LANGU>I</LANGU>
|
||||
|
|
Loading…
Reference in New Issue
Block a user