-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce binary types to RFC3339 functions
Far too often I've found myself working with binaries, to then have to convert back and from to lists before I can use the RFC3339 functionality. So I'm adding here support for them.
- Loading branch information
1 parent
ea35529
commit 75182b0
Showing
4 changed files
with
144 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
%% | ||
%% %CopyrightBegin% | ||
%% | ||
%% Copyright Ericsson AB 2024. All Rights Reserved. | ||
%% | ||
%% Licensed under the Apache License, Version 2.0 (the "License"); | ||
%% you may not use this file except in compliance with the License. | ||
%% You may obtain a copy of the License at | ||
%% | ||
%% http://www.apache.org/licenses/LICENSE-2.0 | ||
%% | ||
%% Unless required by applicable law or agreed to in writing, software | ||
%% distributed under the License is distributed on an "AS IS" BASIS, | ||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
%% See the License for the specific language governing permissions and | ||
%% limitations under the License. | ||
%% | ||
%% %CopyrightEnd% | ||
%% | ||
-module(calendar_prop_SUITE). | ||
|
||
-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, | ||
init_per_group/2, end_per_group/2, | ||
rfc3339_lists_binaries/1]). | ||
|
||
suite() -> | ||
[{ct_hooks,[ts_install_cth]}]. | ||
|
||
all() -> | ||
[rfc3339_lists_binaries]. | ||
|
||
groups() -> | ||
[]. | ||
|
||
init_per_suite(Config) -> | ||
ct_property_test:init_per_suite(Config). | ||
|
||
end_per_suite(_Config) -> | ||
ok. | ||
|
||
init_per_group(_GroupName, Config) -> | ||
Config. | ||
|
||
end_per_group(_GroupName, Config) -> | ||
Config. | ||
|
||
rfc3339_lists_binaries(Config) when is_list(Config) -> | ||
ct_property_test:quickcheck( | ||
calendar_prop:rfc3339_lists_binaries(), | ||
Config). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
%% | ||
%% %CopyrightBegin% | ||
%% | ||
%% Copyright Ericsson AB 2024. All Rights Reserved. | ||
%% | ||
%% Licensed under the Apache License, Version 2.0 (the "License"); | ||
%% you may not use this file except in compliance with the License. | ||
%% You may obtain a copy of the License at | ||
%% | ||
%% http://www.apache.org/licenses/LICENSE-2.0 | ||
%% | ||
%% Unless required by applicable law or agreed to in writing, software | ||
%% distributed under the License is distributed on an "AS IS" BASIS, | ||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
%% See the License for the specific language governing permissions and | ||
%% limitations under the License. | ||
%% | ||
%% %CopyrightEnd% | ||
%% | ||
-module(calendar_prop). | ||
-compile([export_all, nowarn_export_all]). | ||
|
||
-include_lib("common_test/include/ct_property_test.hrl"). | ||
|
||
%%%%%%%%%%%%%%%%%% | ||
%%% Properties %%% | ||
%%%%%%%%%%%%%%%%%% | ||
|
||
between_40_years_ago_and_in_40_years() -> | ||
integer(erlang:system_time(millisecond) - 40*1000*60*60*24*365, | ||
erlang:system_time(millisecond) + 40*1000*60*60*24*365). | ||
|
||
rfc3339_lists_binaries() -> | ||
Ms = [{unit, millisecond}], | ||
?FORALL( | ||
TS, | ||
between_40_years_ago_and_in_40_years(), | ||
begin | ||
DateTimeString = calendar:system_time_to_rfc3339(TS, Ms), | ||
DateTimeBin = calendar:system_time_to_rfc3339(TS, [{return, binary} | Ms]), | ||
ListToBinary = erlang:list_to_binary(DateTimeString), | ||
FromStr = calendar:rfc3339_to_system_time(DateTimeString, Ms), | ||
FromBin = calendar:rfc3339_to_system_time(DateTimeBin, Ms), | ||
DateTimeBin =:= ListToBinary andalso FromStr =:= FromBin | ||
end | ||
). |