Implement appointment reading

This commit is contained in:
daru
2022-05-14 13:55:22 +02:00
parent bbf99fadb4
commit 50e0defc28
6 changed files with 74 additions and 9 deletions

View File

@@ -5,6 +5,8 @@ import (
"encoding/binary"
"fmt"
"strconv"
"strings"
"time"
)
func Sauce(malid int64, username string) string {
@@ -24,3 +26,20 @@ func Int64ToByte(yes int64) []byte {
n := binary.PutVarint(buf, yes)
return buf[:n]
}
func BytesToInt64AndDate(bytes []byte) (int64, time.Time, error) {
split := strings.Split(string(bytes), AppointSplit)
if len(split) != 2 {
return 0, time.Time{}, fmt.Errorf("invalid appointment split %s", string(bytes))
}
num, err := strconv.ParseInt(split[0], 10, 64)
if err != nil {
return num, time.Time{}, err
}
appoint, err := time.Parse(time.RFC3339, split[1])
return num, appoint, err
}
func Int64AndDateToBytes(num int64, appoint time.Time) []byte {
return []byte(fmt.Sprintf("%d%s%s", num, AppointSplit, appoint.Format(time.RFC3339)))
}