mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-09 17:44:59 +09:00
GO-4408 Rename date util pkg
This commit is contained in:
parent
48342d4d66
commit
7032f73206
9 changed files with 19 additions and 19 deletions
33
util/dateutil/util.go
Normal file
33
util/dateutil/util.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package dateutil
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/anyproto/anytype-heart/pkg/lib/localstore/addr"
|
||||
)
|
||||
|
||||
const (
|
||||
dateIdLayout = "2006-01-02"
|
||||
dateNameLayout = "02 Jan 2006"
|
||||
)
|
||||
|
||||
func TimeToDateId(t time.Time) string {
|
||||
return addr.DatePrefix + t.Format(dateIdLayout)
|
||||
}
|
||||
|
||||
func ParseDateId(id string) (time.Time, error) {
|
||||
return time.Parse(dateIdLayout, strings.TrimPrefix(id, addr.DatePrefix))
|
||||
}
|
||||
|
||||
func TimeToDateName(t time.Time) string {
|
||||
return t.Format(dateNameLayout)
|
||||
}
|
||||
|
||||
func DateNameToId(name string) (string, error) {
|
||||
t, err := time.Parse(dateNameLayout, name)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return TimeToDateId(t), nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue