diff --git a/pkg/email/funcs.go b/pkg/email/funcs.go
index 21365bd31f..c36bc8d17f 100644
--- a/pkg/email/funcs.go
+++ b/pkg/email/funcs.go
@@ -33,8 +33,9 @@ var defaultFuncs = template.FuncMap{
p := path.Join(elems...)
return documentationBaseURL + "/" + strings.TrimPrefix(p, "/")
},
- "relTime": relTime,
- "enumDesc": enumDesc,
+ "relDuration": relDuration,
+ "relTime": relTime,
+ "enumDesc": enumDesc,
}
const (
@@ -44,9 +45,17 @@ const (
year = 12 * month
)
-func relTime(d time.Duration) string {
+func relDuration(d time.Duration) string {
now := time.Now()
- return humanize.CustomRelTime(now.Add(d), now, "ago", "from now", []humanize.RelTimeMagnitude{
+ return relativeTime(now.Add(d), now)
+}
+
+func relTime(t time.Time) string {
+ return relativeTime(t, time.Now())
+}
+
+func relativeTime(a, b time.Time) string {
+ return humanize.CustomRelTime(a, b, "ago", "from now", []humanize.RelTimeMagnitude{
{D: time.Second, Format: "now", DivBy: time.Second},
{D: 2 * time.Second, Format: "a second %s", DivBy: 1},
diff --git a/pkg/email/templates/invitation.html.tmpl b/pkg/email/templates/invitation.html.tmpl
index 744f744fc3..92528354ed 100644
--- a/pkg/email/templates/invitation.html.tmpl
+++ b/pkg/email/templates/invitation.html.tmpl
@@ -19,7 +19,7 @@ Alternatively, you can use the invitation token
-Your invitation expires {{ relTime . }}, so register before then.
+Your invitation expires {{ relDuration . }}, so register before then.
diff --git a/pkg/email/templates/invitation.txt.tmpl b/pkg/email/templates/invitation.txt.tmpl
index f1f9f0d174..3db9468fec 100644
--- a/pkg/email/templates/invitation.txt.tmpl
+++ b/pkg/email/templates/invitation.txt.tmpl
@@ -6,7 +6,7 @@ You can now go to {{ .Network.IdentityServerURL }}/register?invitation_token={{
{{- with .TTL }}
-Your invitation expires {{ relTime . }}, so register before then.
+Your invitation expires {{ relDuration . }}, so register before then.
{{- end }}
After successful registration, you can go to {{ .Network.ConsoleURL }} to start adding devices and gateways.
diff --git a/pkg/email/templates/login_token.html.tmpl b/pkg/email/templates/login_token.html.tmpl
index fb6494b652..05c993b899 100644
--- a/pkg/email/templates/login_token.html.tmpl
+++ b/pkg/email/templates/login_token.html.tmpl
@@ -19,7 +19,7 @@ Alternatively, you can use the login token
-Your login token expires {{ relTime . }}, so if you don't log in before then, you'll have to request a new token if you still want to log in.
+Your login token expires {{ relDuration . }}, so if you don't log in before then, you'll have to request a new token if you still want to log in.
{{ .InvitationToken }}
{{- with .TTL }}
{{ .LoginToken }}
direct
-Your temporary password expires {{ relTime . }}, so if you don't change your password before then, you'll have to request a new temporary password if you still want to change your password. +Your temporary password expires {{ relDuration . }}, so if you don't change your password before then, you'll have to request a new temporary password if you still want to change your password.
{{- end }} {{- end -}} diff --git a/pkg/email/templates/temporary_password.txt.tmpl b/pkg/email/templates/temporary_password.txt.tmpl index 61b235e7fe..916d576362 100644 --- a/pkg/email/templates/temporary_password.txt.tmpl +++ b/pkg/email/templates/temporary_password.txt.tmpl @@ -8,5 +8,5 @@ Please note that this temporary password can only be used to change your passwor {{- with .TTL }} -Your temporary password expires {{ relTime . }}, so if you don't change your password before then, you'll have to request a new temporary password if you still want to change your password. +Your temporary password expires {{ relDuration . }}, so if you don't change your password before then, you'll have to request a new temporary password if you still want to change your password. {{- end }} diff --git a/pkg/email/templates/validate.html.tmpl b/pkg/email/templates/validate.html.tmpl index 4c2832de3e..4b535446d8 100644 --- a/pkg/email/templates/validate.html.tmpl +++ b/pkg/email/templates/validate.html.tmpl @@ -22,7 +22,7 @@ Alternatively, you can use the reference{{ .ID }}
and confirmation
{{- with .TTL }}
-The confirmation token expires {{ relTime . }}, so if you don't confirm your email address before then, you'll have to request a new confirmation if you still want to confirm your email address. +The confirmation token expires {{ relDuration . }}, so if you don't confirm your email address before then, you'll have to request a new confirmation if you still want to confirm your email address.
{{- end }} diff --git a/pkg/email/templates/validate.txt.tmpl b/pkg/email/templates/validate.txt.tmpl index 2f725d966c..83c270d1b2 100644 --- a/pkg/email/templates/validate.txt.tmpl +++ b/pkg/email/templates/validate.txt.tmpl @@ -9,5 +9,5 @@ Alternatively, you can use the reference "{{ .ID }}" and confirmation token "{{ {{- with .TTL }} -The confirmation token expires {{ relTime . }}, so if you don't confirm your email address before then, you'll have to request a new confirmation if you still want to confirm your email address. +The confirmation token expires {{ relDuration . }}, so if you don't confirm your email address before then, you'll have to request a new confirmation if you still want to confirm your email address. {{- end }}