aboutsummaryrefslogtreecommitdiffstats
path: root/lib/format
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2021-11-06 17:32:38 +0100
committerRobin Jarry <robin@jarry.cc>2021-11-06 17:34:20 +0100
commit84146e23b384e42c63287e3519e70b0a6ea3100f (patch)
tree4b7994c45404e0dfcf85c5c9dfc1284fcc0eb6e0 /lib/format
parent02e7d8aca88d433062e00fa2988e533944a563f4 (diff)
downloadaerc-84146e23b384e42c63287e3519e70b0a6ea3100f.tar.gz
index: add this-week-time-format
Also allow specific time format for messages received within the last 7 days. Signed-off-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/format')
-rw-r--r--lib/format/format.go23
1 files changed, 16 insertions, 7 deletions
diff --git a/lib/format/format.go b/lib/format/format.go
index 1aba7627..8681de8e 100644
--- a/lib/format/format.go
+++ b/lib/format/format.go
@@ -48,7 +48,8 @@ type Ctx struct {
}
func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string,
- thisYearTimeFmt string, ctx Ctx) (string, []interface{}, error) {
+ thisWeekTimeFmt string, thisYearTimeFmt string, ctx Ctx) (
+ string, []interface{}, error) {
retval := make([]byte, 0, len(format))
var args []interface{}
@@ -141,7 +142,8 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string,
retval = append(retval, 's')
args = append(args,
dummyIfZeroDate(date.Local(),
- timeFmt, thisDayTimeFmt, thisYearTimeFmt))
+ timeFmt, thisDayTimeFmt,
+ thisWeekTimeFmt, thisYearTimeFmt))
case 'D':
date := envelope.Date
if date.IsZero() {
@@ -150,7 +152,8 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string,
retval = append(retval, 's')
args = append(args,
dummyIfZeroDate(date.Local(),
- timeFmt, thisDayTimeFmt, thisYearTimeFmt))
+ timeFmt, thisDayTimeFmt,
+ thisWeekTimeFmt, thisYearTimeFmt))
case 'f':
if len(envelope.From) == 0 {
return "", nil,
@@ -333,16 +336,22 @@ handle_end_error:
}
func dummyIfZeroDate(date time.Time, format string, todayFormat string,
- thisYearFormat string) string {
+ thisWeekFormat string, thisYearFormat string) string {
if date.IsZero() {
return strings.Repeat("?", len(format))
}
- year, month, day := date.Date()
- thisYear, thisMonth, thisDay := time.Now().Date()
+ year := date.Year()
+ day := date.YearDay()
+ now := time.Now()
+ thisYear := now.Year()
+ thisDay := now.YearDay()
if year == thisYear {
- if month == thisMonth && day == thisDay && todayFormat != "" {
+ if day == thisDay && todayFormat != "" {
return date.Format(todayFormat)
}
+ if day > thisDay-7 && thisWeekFormat != "" {
+ return date.Format(thisWeekFormat)
+ }
if thisYearFormat != "" {
return date.Format(thisYearFormat)
}