add date format
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
APP_NAME="libgofunc"
|
||||
VERSION="${1:-v0.1.7}"
|
||||
VERSION="${1:-v0.1.8}"
|
||||
OUTPUT_DIR="../assets"
|
||||
BUILD_DIR="../build"
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ func main() {
|
||||
<p style="padding-left:0px;font-size:18">Address: မင်္ဂလာပါ {{(index .sales 0).salePerson}}</p>
|
||||
<p style="padding-left:0px">Receipt: RCPT001</p>
|
||||
<p style="padding-left:0px">Phone: 0977777777</p>
|
||||
<p style="padding-left:0px">Date: 4 Jan 2026 15:38:38</p>
|
||||
<p style="padding-left:0px">Date: {{formatDateFromSec (index .sales 0).timeSec "2006-01-02 15:04:05"}}</p>
|
||||
<p style="padding-left:0px">Car No.: 3J/3883</p>
|
||||
<p style="padding-left:0px">Casher: မနှင်းနှင်း</p>
|
||||
<p style="padding-left:0px">MOP: B2B</p>
|
||||
|
||||
35
img.go
35
img.go
@@ -28,6 +28,7 @@ import (
|
||||
"log"
|
||||
"path"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"golang.org/x/text/language"
|
||||
"golang.org/x/text/message"
|
||||
@@ -114,8 +115,9 @@ func GenImg(width int, outputPath, payload, tmpl, workingDir string) string {
|
||||
}
|
||||
|
||||
var funcMap = template.FuncMap{
|
||||
"formatNumber": FormatNumber,
|
||||
"div": Div,
|
||||
"formatNumber": FormatNumber,
|
||||
"div": Div,
|
||||
"formatDateFromSec": formatDateFromSec,
|
||||
}
|
||||
|
||||
func renderTemplate(tmp string, data map[string]interface{}) (string, error) {
|
||||
@@ -518,3 +520,32 @@ func convertToFloat64(v any) float64 {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
func formatDateFromSec(input any, layout string) string {
|
||||
var sec int64
|
||||
switch v := input.(type) {
|
||||
case int64:
|
||||
sec = v
|
||||
case int:
|
||||
sec = int64(v)
|
||||
case float64:
|
||||
sec = int64(v)
|
||||
case float32:
|
||||
sec = int64(v)
|
||||
case string:
|
||||
parsed, err := strconv.ParseInt(v, 10, 64)
|
||||
if err != nil {
|
||||
if parsedFloat, errFloat := strconv.ParseFloat(v, 64); errFloat == nil {
|
||||
sec = int64(parsedFloat)
|
||||
} else {
|
||||
return fmt.Sprintf("[Error: invalid time string %q]", v)
|
||||
}
|
||||
} else {
|
||||
sec = parsed
|
||||
}
|
||||
default:
|
||||
return "[Error: unsupported time type]"
|
||||
}
|
||||
t := time.UnixMilli(sec * 1000)
|
||||
return t.Format(layout)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user