Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:26
erlang
2825-snmp-Types-and-specs-for-snmp-date_and_tim...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 2825-snmp-Types-and-specs-for-snmp-date_and_time_to_strin.patch of Package erlang
From 843adb5aacef2d6611b7f0bba8c29827d0481433 Mon Sep 17 00:00:00 2001 From: Micael Karlberg <bmk@erlang.org> Date: Tue, 9 Jan 2024 18:22:43 +0100 Subject: [PATCH 05/67] [snmp] Types and specs for snmp:date_and_time_to_string/1,2 --- lib/snmp/doc/src/snmp.xml | 73 ++++++++++++++++++++++++++++++--------- lib/snmp/src/app/snmp.erl | 33 +++++++++++++++--- 2 files changed, 84 insertions(+), 22 deletions(-) diff --git a/lib/snmp/doc/src/snmp.xml b/lib/snmp/doc/src/snmp.xml index e067e5a4fa..8b616bf3c1 100644 --- a/lib/snmp/doc/src/snmp.xml +++ b/lib/snmp/doc/src/snmp.xml @@ -71,6 +71,46 @@ --> </datatype> + <datatype> + <name name="rfc1903_date_and_time"/> + <desc> + <p> + The data type DateAndTime, an OCTET STRING, as specified in RFC1903. + </p> + </desc> + </datatype> + + <datatype> + <name name="date_and_time_validator_kind"/> + <!-- + <desc> + <p> + TBD. + </p> + </desc> + --> + </datatype> + + <datatype> + <name name="date_and_time_validator"/> + <desc> + <p>The input to the validator fun looks like this: </p> + <pre> + Kind Data + -------------- ---------------------- + year {Year1, Year2} + month Month + day Day + hour Hour + minute Minute + seconds Seconds + deci_seconds DeciSeconds + diff [Sign, Hour, Minute] + valid_date {Year, Month, Day} + </pre> + </desc> + </datatype> + <!-- <datatype> <name name="void"/> @@ -208,27 +248,26 @@ calendar(3). </p> <marker id="dat2s"></marker> + <marker id="date_and_time_to_string"></marker> + <marker id="date_and_time_to_string1"></marker> + <marker id="date_and_time_to_string2"></marker> </desc> </func> <func> - <name since="">date_and_time_to_string(DateAndTime) -> string()</name> - <name since="">date_and_time_to_string(DateAndTime, Validate) -> string()</name> + <name name="date_and_time_to_string" arity="1" clause_i="1" since=""/> + <name name="date_and_time_to_string" arity="2" clause_i="1" since=""/> <fsummary>Convert a DateAndTime value to a string</fsummary> - <type> - <v>DateAndTime = [int()]</v> - <v>Validate = fun(Kind, Data) -> boolean()</v> - </type> <desc> - <p>Converts a DateAndTime list to a printable string, according - to the DISPLAY-HINT definition in RFC2579.</p> + <p>Converts a DateAndTime list to a printable string, according + to the DISPLAY-HINT definition in RFC2579.</p> <p>The validation fun, <c>Validate</c>, allows for a more "flexible" - validation of the <c>DateAndTime</c> argument. Whenever the data - is found to not follow RFC2579, the fun is called to allow a more - "lax" validation. - See the <seeerl marker="#vdat">validate_date_and_time/2</seeerl> - function for more info on the <c>Validate</c> fun. </p> + validation of the <c>DateAndTime</c> argument. Whenever the data + is found to not follow RFC2579, the fun is called to allow a more + "lax" validation. + See the <seeerl marker="#vdat">validate_date_and_time/2</seeerl> + function for more info on the <c>Validate</c> fun. </p> <marker id="dat2s2"></marker> </desc> @@ -296,10 +335,10 @@ <p>The validation fun, <c>Validate</c>, allows for a more "flexible" - validation of the <c>DateAndTime</c> argument. Whenever the data - is found to not follow RFC2579, the fun is called to allow a more - "lax" validation. - The input to the validation fun looks like this: </p> + validation of the <c>DateAndTime</c> argument. Whenever the data + is found to not follow RFC2579, the fun is called to allow a more + "lax" validation. + The input to the validation fun looks like this: </p> <pre> Kind Data diff --git a/lib/snmp/src/app/snmp.erl b/lib/snmp/src/app/snmp.erl index c4508ebd1a..19c69b53ac 100644 --- a/lib/snmp/src/app/snmp.erl +++ b/lib/snmp/src/app/snmp.erl @@ -64,6 +64,10 @@ bits/0, octet/0, octet_string/0, + rfc1903_date_and_time/0, + + date_and_time_validator_kind/0, + date_and_time_validator/0, dir/0, snmp_timer/0, @@ -108,7 +112,7 @@ %% ]). --define(APPLICATION, snmp). +-define(APPLICATION, snmp). -define(ATL_BLOCK_DEFAULT, true). -include_lib("snmp/include/snmp_types.hrl"). @@ -118,9 +122,18 @@ %% Types %%----------------------------------------------------------------- --type bits() :: integer(). --type octet() :: 0..255. --type octet_string() :: [octet()]. +-type bits() :: integer(). +-type octet() :: 0..255. +-type octet_string() :: [octet()]. +-type rfc1903_date_and_time() :: octet_string(). + +-type date_and_time_validator_kind() :: year | month | day | + hour | minute | seconds | deci_seconds | + diff | valid_date. + +-type date_and_time_validator() :: + fun((Kind :: date_and_time_validator_kind(), + Data :: term()) -> boolean()). -type dir() :: string(). -type snmp_timer() :: #snmp_incr_timer{}. @@ -670,7 +683,7 @@ ms2() -> %%----------------------------------------------------------------- -spec date_and_time() -> DateAndTime when - DateAndTime :: octet_string(). + DateAndTime :: rfc1903_date_and_time(). date_and_time() -> UTC = calendar:universal_time(), @@ -712,9 +725,19 @@ date_and_time_to_string2(DAT) -> Validate = fun(What, Data) -> kiribati_validation(What, Data) end, date_and_time_to_string(DAT, Validate). + +-spec date_and_time_to_string(DAT) -> string() when + DAT :: rfc1903_date_and_time(). + date_and_time_to_string(DAT) -> Validate = fun(What, Data) -> strict_validation(What, Data) end, date_and_time_to_string(DAT, Validate). + + +-spec date_and_time_to_string(DAT, Validate) -> string() when + DAT :: rfc1903_date_and_time(), + Validate :: date_and_time_validator(). + date_and_time_to_string(DAT, Validate) when is_function(Validate) -> case validate_date_and_time(DAT, Validate) of true -> -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor