adding a time helper
This commit is contained in:
parent
a418f5cb4b
commit
058076e94f
2 changed files with 12 additions and 0 deletions
|
@ -2,6 +2,7 @@ package torrent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// https://wiki.theory.org/BitTorrentSpecification#Metainfo_File_Structure
|
// https://wiki.theory.org/BitTorrentSpecification#Metainfo_File_Structure
|
||||||
|
@ -28,6 +29,10 @@ type File struct {
|
||||||
Encoding string `bencode:"encoding"`
|
Encoding string `bencode:"encoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f File) CreationDateTime() time.Time {
|
||||||
|
return time.Unix(f.CreationDate, 0)
|
||||||
|
}
|
||||||
|
|
||||||
type InfoSection struct {
|
type InfoSection struct {
|
||||||
// suggested file/directory name where the file(s) are to be saved
|
// suggested file/directory name where the file(s) are to be saved
|
||||||
Name string `bencode:"name,omitempty"`
|
Name string `bencode:"name,omitempty"`
|
||||||
|
|
|
@ -32,3 +32,10 @@ func TestFileMarshal(t *testing.T) {
|
||||||
t.Errorf("expected %q, got %q", len(f1.AnnounceList), len(f2.AnnounceList))
|
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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue