1 %%%-------------------------------------------------------------------
2 %%% File : etorrent_date.erl
3 %%% Author : Jesper Louis Andersen <jlouis@ogre.home>
4 %%% Description : Library functions for date manipulation
6 %%% Created : 19 Jul 2008 by Jesper Louis Andersen <jlouis@ogre.home>
7 %%%-------------------------------------------------------------------
8 -module(etorrent_time
).
11 -export([now_add_seconds
/2, now_subtract_seconds
/2]).
13 %%====================================================================
15 %%====================================================================
16 %%--------------------------------------------------------------------
17 %% Function: now_subtract(NT, Millisecs) -> NT
18 %% Args: NT ::= {Megasecs, Secs, Millisecs}
19 %% Megasecs = Secs = Millisecs = integer()
20 %% Description: Subtract a time delta in millsecs from a now() triple
21 %%--------------------------------------------------------------------
22 now_subtract_seconds({Megasecs
, Secs
, Ms
}, Subsecs
) ->
23 case Secs
- Subsecs
of
27 Needed
= abs(N
) div
1000000 + 1,
28 {Megasecs
- Needed
, N
+ (Needed
* 1000000), Ms
}
31 now_add_seconds({Megasecs
, Secs
, Ms
}, Add
) ->
36 {Megasecs
+ K div
1000000, K rem
1000000, Ms
}
39 %%====================================================================
41 %%====================================================================