This commit is contained in:
dpurbosakti
2025-11-25 15:52:07 +07:00
parent 250b446c37
commit 8cf750c63f
8 changed files with 305 additions and 131 deletions
+17 -9
View File
@@ -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
}
+10
View File
@@ -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
}