Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1d771a5

Browse files
committed
Update timestamps
No tests
1 parent 22549db commit 1d771a5

3 files changed

Lines changed: 93 additions & 0 deletions

File tree

source/expectations/matchers/ut_be_within.tpb

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,60 @@ create or replace type body ut_be_within as
5252
return l_result;
5353
end;
5454

55+
member procedure of_(self in ut_be_within, a_expected timestamp) is
56+
l_result ut_be_within := self;
57+
begin
58+
l_result.expected := ut_data_value_timestamp(a_expected);
59+
if l_result.is_negated_flag = 1 then
60+
l_result.expectation.not_to(l_result );
61+
else
62+
l_result.expectation.to_(l_result );
63+
end if;
64+
end;
65+
66+
member function of_(self in ut_be_within, a_expected timestamp) return ut_be_within is
67+
l_result ut_be_within := self;
68+
begin
69+
l_result.expected := ut_data_value_timestamp(a_expected);
70+
return l_result;
71+
end;
72+
73+
member procedure of_(self in ut_be_within, a_expected timestamp_tz_unconstrained) is
74+
l_result ut_be_within := self;
75+
begin
76+
l_result.expected := ut_data_value_timestamp_tz(a_expected);
77+
if l_result.is_negated_flag = 1 then
78+
l_result.expectation.not_to(l_result );
79+
else
80+
l_result.expectation.to_(l_result );
81+
end if;
82+
end;
83+
84+
member function of_(self in ut_be_within, a_expected timestamp_tz_unconstrained) return ut_be_within is
85+
l_result ut_be_within := self;
86+
begin
87+
l_result.expected := ut_data_value_timestamp_tz(a_expected);
88+
return l_result;
89+
end;
90+
91+
member procedure of_(self in ut_be_within, a_expected timestamp_ltz_unconstrained) is
92+
l_result ut_be_within := self;
93+
begin
94+
l_result.expected := ut_data_value_timestamp_ltz(a_expected);
95+
if l_result.is_negated_flag = 1 then
96+
l_result.expectation.not_to(l_result );
97+
else
98+
l_result.expectation.to_(l_result );
99+
end if;
100+
end;
101+
102+
member function of_(self in ut_be_within, a_expected timestamp_ltz_unconstrained) return ut_be_within is
103+
l_result ut_be_within := self;
104+
begin
105+
l_result.expected := ut_data_value_timestamp_ltz(a_expected);
106+
return l_result;
107+
end;
108+
55109
overriding member function run_matcher(self in out nocopy ut_be_within, a_actual ut_data_value) return boolean is
56110
l_result boolean;
57111
function l_result_from_number return boolean is
@@ -78,12 +132,39 @@ create or replace type body ut_be_within as
78132
end;
79133
end;
80134

135+
function l_result_from_timestamp (a_distance ut_data_value) return boolean is
136+
l_expected timestamp := case when self.expected is of ( ut_data_value_timestamp) then
137+
treat(self.expected as ut_data_value_timestamp).data_value
138+
when self.expected is of ( ut_data_value_timestamp_tz) then
139+
treat(self.expected as ut_data_value_timestamp_tz).data_value
140+
when self.expected is of ( ut_data_value_timestamp_ltz) then
141+
treat(self.expected as ut_data_value_timestamp_ltz).data_value
142+
end;
143+
l_actual timestamp with time zone := treat(a_actual as ut_data_value_date).data_value;
144+
l_distance_ym yminterval_unconstrained := case when self.distance_from_expected is of ( ut_data_value_yminterval)
145+
then treat(self.distance_from_expected as ut_data_value_yminterval).data_value
146+
end;
147+
l_distance_ds dsinterval_unconstrained := case when self.distance_from_expected is of ( ut_data_value_dsinterval)
148+
then treat(self.distance_from_expected as ut_data_value_dsinterval).data_value
149+
end;
150+
begin
151+
return case when l_distance_ym is not null
152+
then l_actual between l_expected - l_distance_ym and l_expected + l_distance_ym
153+
else l_actual between l_expected - l_distance_ds and l_expected + l_distance_ds
154+
end;
155+
end;
156+
157+
81158
begin
82159
if self.expected.data_type = a_actual.data_type then
83160
if self.expected is of (ut_data_value_number) then
84161
l_result := l_result_from_number;
85162
elsif self.expected is of (ut_data_value_date)then
86163
l_result := l_result_from_date(self.distance_from_expected);
164+
elsif self.expected is of (ut_data_value_timestamp_tz)then
165+
l_result := l_result_from_date(self.distance_from_expected);
166+
elsif self.expected is of (ut_data_value_timestamp_ltz)then
167+
l_result := l_result_from_date(self.distance_from_expected);
87168
end if;
88169
else
89170
l_result := (self as ut_matcher).run_matcher(a_actual);

source/expectations/matchers/ut_be_within.tps

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ create or replace type ut_be_within under ut_be_within_pct(
2222
constructor function ut_be_within(self in out nocopy ut_be_within, a_distance_from_expected yminterval_unconstrained) return self as result,
2323
member procedure of_(self in ut_be_within, a_expected date),
2424
member function of_(self in ut_be_within, a_expected date) return ut_be_within,
25+
member procedure of_(self in ut_be_within, a_expected timestamp),
26+
member function of_(self in ut_be_within, a_expected timestamp) return ut_be_within,
27+
member procedure of_(self in ut_be_within, a_expected timestamp_tz_unconstrained ),
28+
member function of_(self in ut_be_within, a_expected timestamp_tz_unconstrained) return ut_be_within,
29+
member procedure of_(self in ut_be_within, a_expected timestamp_ltz_unconstrained),
30+
member function of_(self in ut_be_within, a_expected timestamp_ltz_unconstrained) return ut_be_within,
2531
overriding member function run_matcher(self in out nocopy ut_be_within, a_actual ut_data_value) return boolean,
2632
overriding member function failure_message(a_actual ut_data_value) return varchar2,
2733
overriding member function failure_message_when_negated(a_actual ut_data_value) return varchar2

test/ut3_user/expectations/binary/test_to_be_within.pkb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ create or replace package body test_to_be_within is
7474
test_to_be_within_success('to_be_within','date', 'sysdate', 'sysdate+1','''1 0:00:11.333''','interval day to second');
7575
test_to_be_within_success('to_be_within','date', 'sysdate', 'sysdate+200','''1-0''','interval year to month');
7676
test_to_be_within_success('to_be_within','date', 'sysdate+200', 'sysdate','''1-0''','interval year to month');
77+
78+
test_to_be_within_success('to_be_within','timestamp_tz_unconstrained', q'[TIMESTAMP '2017-08-09 07:00:00 -7:00']', 'sysdate','''1 0:00:11.333''','interval day to second');
79+
test_to_be_within_success('to_be_within','timestamp_tz_unconstrained', q'[TIMESTAMP '2017-08-09 07:00:00 -7:00']', 'sysdate+1','''1 0:00:11.333''','interval day to second');
80+
test_to_be_within_success('to_be_within','timestamp_ltz_unconstrained', q'[TIMESTAMP '2017-08-09 07:00:00 -7:00']', 'sysdate+200','''1-0''','interval year to month');
81+
test_to_be_within_success('to_be_within','timestamp_ltz_unconstrained', 'sysdate+200', 'sysdate','''1-0''','interval year to month');
82+
7783
test_to_be_within_success('to_( ut3_develop.be_within','number', '2', '4','2','number', ')');
7884
test_to_be_within_success('to_( ut3_develop.be_within','number', '4', '2','2','number', ')');
7985
test_to_be_within_success('to_( ut3_develop.be_within','date', 'sysdate+1', 'sysdate','''1 0:00:11.333''','interval day to second', ')');

0 commit comments

Comments
 (0)