Handle HAVE_ALL and HAVE_NONE. Cleanup the BITFIELD message.
[etorrent.git] / lib / etorrent-1.0 / src / etorrent_time.erl
blob12a86274431e3180f8a3ff3a9bddef08b435970c
1 %%%-------------------------------------------------------------------
2 %%% File : etorrent_date.erl
3 %%% Author : Jesper Louis Andersen <jlouis@ogre.home>
4 %%% Description : Library functions for date manipulation
5 %%%
6 %%% Created : 19 Jul 2008 by Jesper Louis Andersen <jlouis@ogre.home>
7 %%%-------------------------------------------------------------------
8 -module(etorrent_time).
10 %% API
11 -export([now_add_seconds/2, now_subtract_seconds/2]).
13 %%====================================================================
14 %% API
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
24 N when N >= 0 ->
25 {Megasecs, N, Ms};
26 N ->
27 Needed = abs(N) div 1000000 + 1,
28 {Megasecs - Needed, N + (Needed * 1000000), Ms}
29 end.
31 now_add_seconds({Megasecs, Secs, Ms}, Add) ->
32 case Secs + Add of
33 K when K < 1000000 ->
34 {Megasecs, K, Ms};
35 K ->
36 {Megasecs + K div 1000000, K rem 1000000, Ms}
37 end.
39 %%====================================================================
40 %% Internal functions
41 %%====================================================================