From 058076e94f67bffa50bd95963447a472590c73d5 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Thu, 14 Aug 2014 16:52:27 -0400 Subject: [PATCH] adding a time helper --- torrent/file.go | 5 +++++ torrent/file_test.go | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/torrent/file.go b/torrent/file.go index 8aaef09..d06f177 100644 --- a/torrent/file.go +++ b/torrent/file.go @@ -2,6 +2,7 @@ package torrent import ( "crypto/sha1" + "time" ) // https://wiki.theory.org/BitTorrentSpecification#Metainfo_File_Structure @@ -28,6 +29,10 @@ type File struct { Encoding string `bencode:"encoding"` } +func (f File) CreationDateTime() time.Time { + return time.Unix(f.CreationDate, 0) +} + type InfoSection struct { // suggested file/directory name where the file(s) are to be saved Name string `bencode:"name,omitempty"` diff --git a/torrent/file_test.go b/torrent/file_test.go index 91fea46..fdd3436 100644 --- a/torrent/file_test.go +++ b/torrent/file_test.go @@ -32,3 +32,10 @@ func TestFileMarshal(t *testing.T) { t.Errorf("expected %q, got %q", len(f1.AnnounceList), len(f2.AnnounceList)) } } + +func TestTime(t *testing.T) { + f1 := File{} + if f1.CreationDateTime().Unix() != 0 { + t.Errorf("%s -- %d", f1.CreationDateTime(), f1.CreationDateTime().Unix()) + } +}