diff --git a/Gopkg.lock b/Gopkg.lock index a010383..6808cf7 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -9,7 +9,7 @@ [[projects]] name = "github.com/aws/aws-sdk-go" - packages = ["aws","aws/awserr","aws/awsutil","aws/client","aws/client/metadata","aws/credentials","aws/endpoints","aws/request","aws/signer/v4","internal/shareddefaults","private/protocol","private/protocol/query","private/protocol/query/queryutil","private/protocol/rest","private/protocol/restxml","private/protocol/xml/xmlutil","service/s3"] + packages = ["aws","aws/awserr","aws/awsutil","aws/client","aws/client/metadata","aws/corehandlers","aws/credentials","aws/credentials/ec2rolecreds","aws/credentials/endpointcreds","aws/credentials/stscreds","aws/defaults","aws/ec2metadata","aws/endpoints","aws/request","aws/session","aws/signer/v4","internal/shareddefaults","private/protocol","private/protocol/query","private/protocol/query/queryutil","private/protocol/rest","private/protocol/restxml","private/protocol/xml/xmlutil","service/s3","service/sts"] revision = "991fe2497a95d757bb53f95cbcebf3d26134c9fe" version = "v1.12.32" @@ -105,6 +105,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "2544efe6d7c15494a53f84f4639759ad68c124eadbd0608faebc66d767db2d3c" + inputs-digest = "d6eacc94cd9bd400bffbca99280d82e6e82fad1f84460edb4d4fc0fc78df83f1" solver-name = "gps-cdcl" solver-version = 1 diff --git a/filters/filter.go b/filters/filter.go index ebfeec8..0af4e6c 100644 --- a/filters/filter.go +++ b/filters/filter.go @@ -1,9 +1,15 @@ package filters -import "github.com/flosch/pongo2" +import ( + "time" + + humanize "github.com/flosch/go-humanize" + "github.com/flosch/pongo2" +) func init() { pongo2.RegisterFilter("lastNItems", filterLastNItems) + pongo2.RegisterFilter("naturaltime", filterTimeuntilTimesince) } func filterLastNItems(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) { @@ -18,3 +24,27 @@ func filterLastNItems(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *po return in.Slice(from, in.Len()), nil } + +func filterTimeuntilTimesince(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) { + basetime, isTime := in.Interface().(time.Time) + if !isTime { + return nil, &pongo2.Error{ + Sender: "filter:timeuntil/timesince", + ErrorMsg: "time-value is not a time.Time-instance", + } + } + var paramtime time.Time + if !param.IsNil() { + paramtime, isTime = param.Interface().(time.Time) + if !isTime { + return nil, &pongo2.Error{ + Sender: "filter:timeuntil/timesince", + ErrorMsg: "time-parameter is not a time.Time-instance", + } + } + } else { + paramtime = time.Now() + } + + return pongo2.AsValue(humanize.TimeDuration(basetime.Sub(paramtime))), nil +} diff --git a/main.go b/main.go index 068b30b..9f196a4 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,6 @@ import ( "github.com/gorilla/mux" _ "github.com/Luzifer/mondash/filters" - _ "github.com/flosch/pongo2-addons" ) var (