Skip to content

Commit de08f48

Browse files
committed
added json_to_abap for time
1 parent 4c0e2f2 commit de08f48

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/core/zcl_ajson.clas.locals_imp.abap

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,14 @@ class lcl_json_to_abap definition final.
663663
raising
664664
zcx_ajson_error.
665665

666+
methods to_time
667+
IMPORTING
668+
iv_value TYPE z2ui5_if_ajson_types=>ty_node-value
669+
RETURNING
670+
VALUE(rv_result) TYPE t
671+
RAISING
672+
z2ui5_cx_ajson_error.
673+
666674
private section.
667675

668676
types:
@@ -977,6 +985,8 @@ class lcl_json_to_abap implementation.
977985
" TODO: check type ?
978986
if is_node_type-type_kind = lif_kind=>date and is_node-value is not initial.
979987
<container> = to_date( is_node-value ).
988+
elseif is_node_type-type_kind = lif_kind=>time and is_node-value is not initial.
989+
<container> = to_time( is_node-value ).
980990
elseif is_node_type-type_kind = lif_kind=>packed and is_node-value is not initial.
981991
<container> = to_timestamp( is_node-value ).
982992
else.
@@ -1086,6 +1096,22 @@ class lcl_json_to_abap implementation.
10861096

10871097
endmethod.
10881098

1099+
method to_time.
1100+
1101+
DATA lv_h TYPE c LENGTH 2.
1102+
DATA lv_m TYPE c LENGTH 2.
1103+
DATA lv_s TYPE c LENGTH 2.
1104+
1105+
FIND FIRST OCCURRENCE OF REGEX '^(\d{2}):(\d{2}):(\d{2})(T|$)' "#EC NOTEXT
1106+
IN iv_value
1107+
SUBMATCHES lv_h lv_m lv_s.
1108+
IF sy-subrc <> 0.
1109+
z2ui5_cx_ajson_error=>raise( 'Unexpected time format' ).
1110+
ENDIF.
1111+
CONCATENATE lv_h lv_m lv_s INTO rv_result.
1112+
1113+
endmethod.
1114+
10891115
endclass.
10901116

10911117
**********************************************************************

src/core/zcl_ajson.clas.testclasses.abap

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,9 @@ class ltcl_json_to_abap definition
14571457
methods to_abap_corresponding_pub_neg
14581458
for testing
14591459
raising zcx_ajson_error.
1460-
1460+
methods to_abap_time
1461+
FOR TESTING
1462+
reaising cx_static_check.
14611463
endclass.
14621464

14631465
class zcl_ajson definition local friends ltcl_json_to_abap.
@@ -1534,6 +1536,28 @@ class ltcl_json_to_abap implementation.
15341536

15351537
endmethod.
15361538

1539+
METHOD to_abap_time.
1540+
1541+
DATA lo_cut TYPE REF TO lcl_json_to_abap.
1542+
DATA lv_mock TYPE t.
1543+
DATA lo_nodes TYPE REF TO lcl_nodes_helper.
1544+
1545+
CREATE OBJECT lo_nodes.
1546+
lo_nodes->add( ' | |str |11:11:11| ' ).
1547+
1548+
CREATE OBJECT lo_cut.
1549+
lo_cut->to_abap(
1550+
EXPORTING
1551+
it_nodes = lo_nodes->sorted( )
1552+
CHANGING
1553+
c_container = lv_mock ).
1554+
1555+
cl_abap_unit_assert=>assert_equals(
1556+
act = lv_mock
1557+
exp = '111111' ).
1558+
1559+
ENDMETHOD.
1560+
15371561
method to_abap_value.
15381562

15391563
data lo_cut type ref to lcl_json_to_abap.

0 commit comments

Comments
 (0)