1 module pastemyst.time;
2 
3 import std.conv;
4 import vibe.d;
5 import pastemyst.info;
6 import pastemyst.expires;
7 
8 /++
9  + converts an expiresIn value to a specific unix timestamp when a paste should expire
10  +/
11 public ulong getExpiresInToUnixTime(ulong createdAt, ExpiresIn expiresIn)
12 {
13     ulong time = 0;
14 
15     const reqstring = TIME_EXPIRES_IN_TO_UNIX ~ "?createdAt=" ~ createdAt.to!string() ~
16                       "&expiresIn=" ~ expiresIn;
17 
18     requestHTTP(reqstring,
19         (scope req)
20         {
21             req.method = HTTPMethod.GET;
22         },
23         (scope res)
24         {
25             time = parseJsonString(res.bodyReader.readAllUTF8())["result"].get!ulong();
26         }
27     );
28 
29     return time;
30 }
31 
32 @("converting expires in value")
33 unittest
34 {
35     assert(getExpiresInToUnixTime(1_588_441_258, ExpiresIn.oneWeek) == 1_589_046_058);
36 }