mirror of https://github.com/mvdan/fdroidcl.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
897 B
47 lines
897 B
|
11 years ago
|
// Copyright (c) 2015, Daniel Martí <mvdan@mvdan.cc>
|
||
|
|
// See LICENSE for licensing information
|
||
|
|
|
||
|
7 years ago
|
package fdroid
|
||
|
11 years ago
|
|
||
|
|
import (
|
||
|
|
"encoding/hex"
|
||
|
8 years ago
|
"strconv"
|
||
|
11 years ago
|
"time"
|
||
|
|
)
|
||
|
|
|
||
|
|
type HexVal []byte
|
||
|
|
|
||
|
|
func (hv *HexVal) String() string {
|
||
|
|
return hex.EncodeToString(*hv)
|
||
|
|
}
|
||
|
|
|
||
|
10 years ago
|
func (hv *HexVal) UnmarshalText(text []byte) error {
|
||
|
10 years ago
|
b, err := hex.DecodeString(string(text))
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
*hv = b
|
||
|
|
return nil
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
8 years ago
|
// UnixDate is F-Droid's timestamp format. It's a unix time, but in
|
||
|
|
// milliseconds. We can ignore the extra digits, as they're always zero, and
|
||
|
|
// won't be displayed anyway.
|
||
|
|
type UnixDate struct {
|
||
|
11 years ago
|
time.Time
|
||
|
|
}
|
||
|
|
|
||
|
8 years ago
|
func (ud *UnixDate) String() string {
|
||
|
|
return ud.Format("2006-01-02")
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
8 years ago
|
func (ud *UnixDate) UnmarshalJSON(data []byte) error {
|
||
|
|
msec, err := strconv.ParseInt(string(data), 10, 64)
|
||
|
10 years ago
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
8 years ago
|
t := time.Unix(msec/1000, 0).UTC()
|
||
|
|
*ud = UnixDate{t}
|
||
|
10 years ago
|
return nil
|
||
|
11 years ago
|
}
|