From 710a9e752a81e9a377c5fb7943609825f4d40fb2 Mon Sep 17 00:00:00 2001
From: Abhiranjan Kumar <abhiranjan.kumar00@gmail.com>
Date: Sat, 11 Apr 2015 18:42:54 +0530
Subject: [PATCH] Fixes 21

---
 src/FuncTorrent/Metainfo.hs | 11 +++++++----
 test/Test.hs                |  2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/FuncTorrent/Metainfo.hs b/src/FuncTorrent/Metainfo.hs
index 61699a3..dfedb59 100644
--- a/src/FuncTorrent/Metainfo.hs
+++ b/src/FuncTorrent/Metainfo.hs
@@ -25,7 +25,7 @@ data Info = Info { pieceLength :: !Integer
 
 data Metainfo = Metainfo { info :: !Info
                          , announceList :: ![String]
-                         , creationDate :: !(Maybe String)
+                         , creationDate :: !(Maybe Integer)
                          , comment :: !(Maybe String)
                          , createdBy :: !(Maybe String)
                          , encoding :: !(Maybe String)
@@ -50,19 +50,22 @@ maybeBstrToString :: Maybe BVal -> Maybe String
 maybeBstrToString (Just (Bstr bs)) = Just $ unpack bs
 maybeBstrToString _ = Nothing
 
+maybeBstrToInteger :: Maybe BVal -> Maybe Integer
+maybeBstrToInteger (Just (Bint bs)) = Just  bs
+maybeBstrToInteger _ = Nothing
+
 mkMetaInfo :: BVal -> Maybe Metainfo
 mkMetaInfo (Bdict m) = let (Just info') = mkInfo $ m ! "info"
                            announce' = lookup "announce" m
                            announceList' = lookup "announce-list" m
-                           -- creationDate = lookup (Bstr (pack "creation date")) m
-                           creationDate' = Nothing
+                           creationDate' = lookup "creation date" m
                            comment' = lookup "comment" m
                            createdBy' = lookup "created by" m
                            encoding' = lookup "encoding" m
                        in Just Metainfo { info = info'
                                         , announceList = maybeToList (announce' >>= bstrToString)
                                                          ++ getAnnounceList announceList'
-                                        , creationDate = creationDate'
+                                        , creationDate = maybeBstrToInteger creationDate'
                                         , comment = maybeBstrToString comment'
                                         , createdBy = maybeBstrToString createdBy'
                                         , encoding = maybeBstrToString encoding'
diff --git a/test/Test.hs b/test/Test.hs
index 8a4649e..3ead970 100644
--- a/test/Test.hs
+++ b/test/Test.hs
@@ -39,7 +39,7 @@ hello = Metainfo {
             md5sum = Nothing
           },
           announceList = ["http://9.rarbg.com:2710/announce"],
-          creationDate = Nothing,
+          creationDate = Just 1428717851,
           comment = Just "hello world",
           createdBy = Just "Jaseem Abid",
           encoding = Just "UTF-8"
-- 
2.45.2