fix(templates/certificates): Remove 'km' suffix from formatted distance output and calculate the suffix dynamicly
This commit is contained in:
parent
14795e1831
commit
76d982fa04
@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"math"
|
||||
"strings"
|
||||
|
||||
"go.uber.org/zap"
|
||||
@ -91,7 +92,15 @@ func (t *DefaultTemplater) FormatUnit(unit string, locale string, amount int) (s
|
||||
var formatted string
|
||||
switch unit {
|
||||
case "kilometer":
|
||||
formatted = fmt.Sprintf("%.3f", float64(amount)/1000)
|
||||
if amount < 1000 {
|
||||
formatted = fmt.Sprintf("%dm", amount)
|
||||
} else if (amount % 1000) == 0 {
|
||||
formatted = fmt.Sprintf("%dkm", amount/1000)
|
||||
} else {
|
||||
kilometers := math.Floor(float64(amount) / 1000)
|
||||
meters := amount - int(kilometers)*1000
|
||||
formatted = fmt.Sprintf("%dkm %dm", int(kilometers), meters)
|
||||
}
|
||||
case "euro":
|
||||
formatted = fmt.Sprintf("%.2f", float64(amount)/100)
|
||||
default:
|
||||
|
@ -56,7 +56,7 @@
|
||||
{{ .MiddleName }} {{ .LastName }}
|
||||
</p>
|
||||
<p style="font-size: 1cm; margin-bottom: 0;">hat beim {{ $.EventName }}</p>
|
||||
<p style="font-size: 2cm; font-weight: bold; margin-bottom: 0;">{{formatUnit "kilometer" $.Locale .Distance}}km</p>
|
||||
<p style="font-size: 2cm; font-weight: bold; margin-bottom: 0;">{{formatUnit "kilometer" $.Locale .Distance}}</p>
|
||||
<p style="font-size: 1cm;">für den guten Zweck zurückgelegt.</p>
|
||||
</main>
|
||||
<footer class="certificate-footer">
|
||||
|
@ -56,7 +56,7 @@
|
||||
{{ .MiddleName }} {{ .LastName }}
|
||||
</p>
|
||||
<p style="font-size: 1cm; margin-bottom: 0;">Ran</p>
|
||||
<p style="font-size: 2cm; font-weight: bold; margin-bottom: 0;">{{formatUnit "kilometer" $.Locale .Distance}}km</p>
|
||||
<p style="font-size: 2cm; font-weight: bold; margin-bottom: 0;">{{formatUnit "kilometer" $.Locale .Distance}}</p>
|
||||
<p style="font-size: 1cm;">for our good cause at the {{ $.EventName }}.</p>
|
||||
</main>
|
||||
<footer class="certificate-footer">
|
||||
|
Loading…
x
Reference in New Issue
Block a user