Current section
Files
Jump to
Current section
Files
src/jobs_lib.erl
%%==============================================================================
%% Copyright 2014 Ulf Wiger
%%
%% 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.
%%==============================================================================
-module(jobs_lib).
%% We don't want warnings about the use of erlang:now/0 in
%% this module.
-compile(nowarn_deprecated_function).
-export([timestamp/0,
timestamp_to_datetime/1,
time_compat/0]).
timestamp() ->
%% Invented epoc is {1258,0,0}, or 2009-11-12, 4:26:40
{MS,S,US} = time_compat(),
(MS-1258)*1000000000 + S*1000 + US div 1000.
timestamp_to_datetime(TS) ->
%% Our internal timestamps are relative to Now = {1258,0,0}
%% It doesn't really matter much how we construct a now()-like tuple,
%% as long as the weighted sum of the three numbers is correct.
S = TS div 1000,
MS = TS rem 1000,
%% return {Datetime, Milliseconds}
{calendar:now_to_datetime({1258,S,0}), MS}.
%% create the jobs_time_compat module for efficiency
time_compat() ->
case erlang:is_builtin(erlang,timestamp,0) of
true -> erlang:timestamp();
false -> erlang:now()
end.