1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
2019-07-15 09:06:49 -07:00

30 lines
685 B
Go

// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT licese.
// Details in the LICENSE file.
package trello
import (
"strconv"
"time"
"github.com/pkg/errors"
)
// IDToTime is a convenience function. It takes a Trello ID string and
// extracts the encoded create time as time.Time or an error.
func IDToTime(id string) (t time.Time, err error) {
if id == "" {
return time.Time{}, nil
}
// The first 8 characters in the object ID are a Unix timestamp
ts, err := strconv.ParseUint(id[:8], 16, 64)
if err != nil {
err = errors.Wrapf(err, "ID '%s' failed to convert to timestamp.", id)
} else {
t = time.Unix(int64(ts), 0)
}
return
}