
class zcl_tool_time_slices definition
public
create public .
public section.
types:
begin of ty_period,
date_from type d,
time_from type t,
date_to type d,
time_to type t,
end of ty_period .
class-methods intersect
importing
first_period type ty_period
second_period type ty_period
returning
value(r_intersect) type ty_period.
protected section.
private section.
ENDCLASS.
CLASS ZCL_TOOL_TIME_SLICES IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_TOOL_TIME_SLICES=>INTERSECT
* +-------------------------------------------------------------------------------------------------+
* | [--->] FIRST_PERIOD TYPE TY_PERIOD
* | [--->] SECOND_PERIOD TYPE TY_PERIOD
* | [<-()] R_INTERSECT TYPE TY_PERIOD
* +--------------------------------------------------------------------------------------</SIGNATURE>
method intersect.
r_intersect = cond #(
let
" concatenate date and time for easier comparison
first_from = first_period-date_from && first_period-time_from
second_from = second_period-date_from && second_period-time_from
first_to = first_period-date_to && first_period-time_to
second_to = second_period-date_to && second_period-time_to in
when
" very slim decision wether an intersection exists or not
first_from < second_to and
second_from < first_to
then value #(
let
from = cond #(
when first_from > second_from then first_from else second_from )
to = cond #(
when first_to > second_to then second_to else first_to ) in
date_from = from(8)
time_from = from+8
date_to = to(8)
time_to = to+8 ) ).
endmethod.
ENDCLASS.
report zp_tmp_intersect.
parameters:
p1_datef type d, p1_timef type t, p1_datet type d, p1_timet type t,
p2_datef type d, p2_timef type t, p2_datet type d, p2_timet type t.
start-of-selection.
cl_demo_output=>display( zcl_tool_time_slices=>intersect(
first_period = value #(
date_from = p1_datef
time_from = p1_timef
date_to = p1_datet
time_to = p1_timet )
second_period = value #(
date_from = p2_datef
time_from = p2_timef
date_to = p2_datet
time_to = p2_timet ) ) ).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
16 | |
5 | |
3 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
2 |