wip
This commit is contained in:
@@ -8,6 +8,8 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const StandartDateTimeFormat = "2006-01-02 15:04:05"
|
||||
|
||||
// check string pointer, if nil return default value
|
||||
func StrConvDefault(f *string, def string) string {
|
||||
if f == nil {
|
||||
@@ -96,20 +98,12 @@ func BoolToString(f *bool) *string {
|
||||
return &t
|
||||
}
|
||||
|
||||
func TimeToString(f *time.Time) *string {
|
||||
if f == nil {
|
||||
return nil
|
||||
}
|
||||
t := f.Format("2006-01-02 15:04:05")
|
||||
return &t
|
||||
}
|
||||
|
||||
// Handling gorm.DeletedAt
|
||||
func DeletedAtToString(deletedAt *gorm.DeletedAt) *string {
|
||||
if deletedAt == nil || !deletedAt.Valid {
|
||||
return nil
|
||||
}
|
||||
return TimeToString(&deletedAt.Time)
|
||||
return TimeToStringWithFormat(&deletedAt.Time, "")
|
||||
}
|
||||
|
||||
func BoolToFloat64(b bool) float64 {
|
||||
@@ -151,3 +145,17 @@ func StringToUint64(s string) *uint64 {
|
||||
}
|
||||
return &u
|
||||
}
|
||||
|
||||
func TimeToStringWithFormat(t *time.Time, format string) *string {
|
||||
result := ""
|
||||
if t == nil || t.IsZero() {
|
||||
return &result
|
||||
}
|
||||
|
||||
if format == "" {
|
||||
format = StandartDateTimeFormat
|
||||
}
|
||||
|
||||
result = t.Format(format)
|
||||
return &result
|
||||
}
|
||||
|
||||
@@ -208,3 +208,13 @@ func GetLastTwoPathSegments(s string) string {
|
||||
// fallback: return entire string if less than 2 segments
|
||||
return strings.Trim(path, "/")
|
||||
}
|
||||
|
||||
func FormatPlaceAndDate(place string, t time.Time) string {
|
||||
// Ensure place is uppercase
|
||||
place = strings.ToUpper(strings.TrimSpace(place))
|
||||
|
||||
// Format date: DD-MM-YYYY
|
||||
dateStr := t.Format("02-01-2006")
|
||||
|
||||
return place + ", " + dateStr
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user