-
Notifications
You must be signed in to change notification settings - Fork 304
/
Copy pathzcl_demo_abap_unit_dataprov.clas.abap
67 lines (59 loc) · 2.88 KB
/
zcl_demo_abap_unit_dataprov.clas.abap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"! <p class="shorttext"><strong>Class Supporting ABAP Unit Test Example</strong><br/>ABAP cheat sheet example class</p>
"!
"! <p>The example class represents a dependent-on-component (DOC) and supports an ABAP Unit test example.
"! Methods of this class are called in another class: {@link zcl_demo_abap_unit_tdf}. The DOCs are replaced
"! by test doubles when running ABAP Unit tests.<br/>
"! Choose F9 in ADT to run the class.</p>
"!
"! <h2>Information</h2>
"! <p>Find information on getting started with the example class and the disclaimer in
"! the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</p>
CLASS zcl_demo_abap_unit_dataprov DEFINITION
PUBLIC
CREATE PUBLIC .
PUBLIC SECTION.
METHODS get_discount RETURNING VALUE(discount) TYPE decfloat34.
METHODS get_discount_value IMPORTING day_value TYPE i
time_value TYPE i
RETURNING VALUE(discount_value) TYPE decfloat34.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_demo_abap_unit_dataprov IMPLEMENTATION.
METHOD get_discount.
"Getting the weekday
"1) Monday, 2) Tuesday, 3) Wednesday, 4) Thursday, 5) Friday, 6) Saturday, 7) Sunday
DATA(weekday) = ( 5 + CONV d( xco_cp=>sy->date( xco_cp_time=>time_zone->utc
)->as( xco_cp_time=>format->iso_8601_basic )->value ) MOD 7 ) MOD 7 + 1.
"- Standard discount is granted at the weekend (Saturday, Sunday)
"- On other weekdays, discount is granted depending on the daytime
IF weekday = 6 OR weekday = 7.
discount = '20'.
ELSE.
"Retrieving the current time in UTC
DATA(utc_time) = CONV t( xco_cp=>sy->time( xco_cp_time=>time_zone->utc
)->as( xco_cp_time=>format->iso_8601_basic )->value ).
discount = COND #( WHEN utc_time BETWEEN '000000' AND '045959' THEN '15' "Night discount
WHEN utc_time BETWEEN '220000' AND '235959' THEN '15' "Night discount
WHEN utc_time BETWEEN '050000' AND '115959' THEN '10' "Morning discount
WHEN utc_time BETWEEN '180000' AND '215959' THEN '5' "Evening discount
ELSE 0 "No discount
).
ENDIF.
ENDMETHOD.
METHOD get_discount_value.
CASE day_value.
"Standard discount is granted at the weekend (Saturday, Sunday)
WHEN 6 OR 7.
discount_value = '20'.
"On other weekdays, discount is granted depending on the daytime
WHEN OTHERS.
discount_value = SWITCH #( time_value
WHEN 1 THEN '15' "Night discount
WHEN 2 THEN '10' "Morning discount
WHEN 3 THEN '5' "Evening discount
ELSE '0' "No discount
).
ENDCASE.
ENDMETHOD.
ENDCLASS.