diff options
author | Erland Schönbeck <[email protected]> | 2015-03-17 11:56:14 +0100 |
---|---|---|
committer | Rickard Green <[email protected]> | 2015-03-20 15:28:54 +0100 |
commit | 7cdde7537deccd53d95d03860379f3d20ad2e265 (patch) | |
tree | 8d2c7cc5b86e6a57e840efcd781abe8067c9f614 /lib/inets/src/inets_app/inets_lib.erl | |
parent | 87ae700c7383b74b8ddade6bfe30481dcdc5b6c7 (diff) | |
download | otp-7cdde7537deccd53d95d03860379f3d20ad2e265.tar.gz otp-7cdde7537deccd53d95d03860379f3d20ad2e265.tar.bz2 otp-7cdde7537deccd53d95d03860379f3d20ad2e265.zip |
inets: Cleanup of multiple copies of functions
Add inets_lib with common functions used by multiple
modules
Diffstat (limited to 'lib/inets/src/inets_app/inets_lib.erl')
-rw-r--r-- | lib/inets/src/inets_app/inets_lib.erl | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/inets/src/inets_app/inets_lib.erl b/lib/inets/src/inets_app/inets_lib.erl new file mode 100644 index 0000000000..3f970e31cc --- /dev/null +++ b/lib/inets/src/inets_app/inets_lib.erl @@ -0,0 +1,49 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2015-2015. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% + +-module(inets_lib). + +-export([millisec_passed/1, formated_timestamp/0, format_timestamp/1]). + + + +%% Help function, elapsed milliseconds since T0 +millisec_passed({_,_,_} = T0 ) -> + %% OTP 17 and earlier + timer:now_diff(erlang:now(), T0) div 1000; + +millisec_passed(T0) -> + %% OTP 18 + erlang:convert_time_unit(erlang:monotonic_time() - T0, + native, + micro_seconds) div 1000. + +%% Return formated time stamp (e.g. 2015:03:16 10:05:23 1234) +formated_timestamp() -> + format_timestamp( os:timestamp() ). + +%% Return formated time stamp (e.g. 2015:03:16 10:05:23 1234) +format_timestamp({_N1, _N2, N3} = Tme) -> + {Date, Time} = calendar:now_to_datetime(Tme), + {YYYY,MM,DD} = Date, + {Hour,Min,Sec} = Time, + FormatDate = + io_lib:format("~.4w:~.2.0w:~.2.0w ~.2.0w:~.2.0w:~.2.0w 4~w", + [YYYY,MM,DD,Hour,Min,Sec,round(N3/1000)]), + lists:flatten(FormatDate). |