Replace with NullDate

This commit is contained in:
Melon 2024-04-15 20:02:44 +01:00
parent 0b4f866cd0
commit ef20622785
Signed by: melon
GPG Key ID: 6C9D970C50D26A25
2 changed files with 7 additions and 7 deletions

View File

@ -1,11 +1,11 @@
package database package database
import ( import (
"database/sql"
"fmt" "fmt"
"github.com/1f349/tulip/database/types" "github.com/1f349/tulip/database/types"
"github.com/MrMelon54/pronouns" "github.com/MrMelon54/pronouns"
"github.com/go-oauth2/oauth2/v4" "github.com/go-oauth2/oauth2/v4"
"github.com/hardfinhq/go-date"
"golang.org/x/text/language" "golang.org/x/text/language"
"net/url" "net/url"
"time" "time"
@ -16,7 +16,7 @@ type UserPatch struct {
Picture string Picture string
Website string Website string
Pronouns types.UserPronoun Pronouns types.UserPronoun
Birthdate sql.NullTime Birthdate date.NullDate
ZoneInfo types.UserZone ZoneInfo types.UserZone
Locale types.UserLocale Locale types.UserLocale
} }
@ -35,10 +35,10 @@ func (u *UserPatch) ParseFromForm(v url.Values) (safeErrs []error) {
} }
} }
if v.Has("reset_birthdate") || v.Get("birthdate") == "" { if v.Has("reset_birthdate") || v.Get("birthdate") == "" {
u.Birthdate = sql.NullTime{} u.Birthdate = date.NullDate{}
} else { } else {
u.Birthdate = sql.NullTime{Valid: true} u.Birthdate = date.NullDate{Valid: true}
u.Birthdate.Time, err = time.Parse(time.DateOnly, v.Get("birthdate")) u.Birthdate.Date, err = date.FromString(v.Get("birthdate"))
if err != nil { if err != nil {
safeErrs = append(safeErrs, fmt.Errorf("invalid time selected")) safeErrs = append(safeErrs, fmt.Errorf("invalid time selected"))
} }

View File

@ -220,10 +220,10 @@ func NewHttpServer(conf Conf, db *database.Queries, signingKey mjwt.Signer) *htt
m["email_verified"] = userData.EmailVerified m["email_verified"] = userData.EmailVerified
} }
if claims["birthdate"] && userData.Birthdate.Valid { if claims["birthdate"] && userData.Birthdate.Valid {
m["birthdate"] = userData.Birthdate.Time.String() m["birthdate"] = userData.Birthdate.Date.String()
} }
if claims["age"] { if claims["age"] {
m["age"] = CalculateAge(userData.Birthdate.Time.In(userData.Zoneinfo.Location)) m["age"] = CalculateAge(userData.Birthdate.Date.ToTime().In(userData.Zoneinfo.Location))
} }
if claims["zoneinfo"] { if claims["zoneinfo"] {
m["zoneinfo"] = userData.Zoneinfo.Location.String() m["zoneinfo"] = userData.Zoneinfo.Location.String()