Compare commits
	
		
			10 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 8ea9b3f79f | |||
| a4b2a0589f | |||
| 4ef5f6059b | |||
| b23a444aa2 | |||
| 09932046f8 | |||
| 37e52595a2 | |||
| 95d7c90492 | |||
| 23a3235c7e | |||
| 506d276962 | |||
| 2a0cf84416 | 
| @@ -183,6 +183,10 @@ func (id {{.Name}}) CheckString() string { | ||||
| 	return getCheckString(prefix{{.Name}}, string(id)) | ||||
| } | ||||
|  | ||||
| func (id {{.Name}}) IsZero() bool { | ||||
| 	return id == "" | ||||
| } | ||||
|  | ||||
| func (id {{.Name}}) Regex() rext.Regex { | ||||
| 	return regex{{.Name}} | ||||
| } | ||||
|   | ||||
| @@ -6,11 +6,11 @@ import ( | ||||
| 	"encoding/json" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"go/format" | ||||
| 	"git.blackforestbytes.com/BlackForestBytes/goext" | ||||
| 	"git.blackforestbytes.com/BlackForestBytes/goext/cryptext" | ||||
| 	"git.blackforestbytes.com/BlackForestBytes/goext/langext" | ||||
| 	"git.blackforestbytes.com/BlackForestBytes/goext/rext" | ||||
| 	"go/format" | ||||
| 	"io" | ||||
| 	"os" | ||||
| 	"path" | ||||
| @@ -46,7 +46,7 @@ var rexEnumPackage = rext.W(regexp.MustCompile(`^package\s+(?P<name>[A-Za-z0-9_] | ||||
|  | ||||
| var rexEnumDef = rext.W(regexp.MustCompile(`^\s*type\s+(?P<name>[A-Za-z0-9_]+)\s+(?P<type>[A-Za-z0-9_]+)\s*//\s*(@enum:type).*$`)) | ||||
|  | ||||
| var rexEnumValueDef = rext.W(regexp.MustCompile(`^\s*(?P<name>[A-Za-z0-9_]+)\s+(?P<type>[A-Za-z0-9_]+)\s*=\s*(?P<value>("[A-Za-z0-9_:\s\-.]*"|[0-9]+))\s*(//(?P<comm>.*))?.*$`)) | ||||
| var rexEnumValueDef = rext.W(regexp.MustCompile(`^\s*(?P<name>[A-Za-z0-9_]+)\s+(?P<type>[A-Za-z0-9_]+)\s*=\s*(?P<value>("[/@A-Za-z0-9_:\s\-.]*"|[0-9]+))\s*(//(?P<comm>.*))?.*$`)) | ||||
|  | ||||
| var rexEnumChecksumConst = rext.W(regexp.MustCompile(`const ChecksumEnumGenerator = "(?P<cs>[A-Za-z0-9_]*)"`)) | ||||
|  | ||||
|   | ||||
| @@ -45,6 +45,10 @@ func (i {{.Name}}) AsAnyPtr() *{{$.AnyDef.Name}} { | ||||
| } | ||||
| {{end}} | ||||
|  | ||||
| func (i {{.Name}}) IsZero() bool { | ||||
| 	return i == "" | ||||
| } | ||||
|  | ||||
| func New{{.Name}}() {{.Name}} { | ||||
| 	return {{.Name}}(primitive.NewObjectID().Hex()) | ||||
| } | ||||
|   | ||||
| @@ -2,8 +2,9 @@ package ginext | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"github.com/gin-gonic/gin" | ||||
| 	"git.blackforestbytes.com/BlackForestBytes/goext/exerr" | ||||
| 	"github.com/gin-gonic/gin" | ||||
| 	"net/http" | ||||
| ) | ||||
|  | ||||
| type WHandlerFunc func(PreContext) HTTPResponse | ||||
| @@ -58,3 +59,31 @@ func Wrap(w *GinWrapper, fn WHandlerFunc) gin.HandlerFunc { | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func WrapHTTPHandler(w *GinWrapper, fn http.Handler) gin.HandlerFunc { | ||||
| 	return func(g *gin.Context) { | ||||
| 		for _, lstr := range w.listenerBeforeRequest { | ||||
| 			lstr(g) | ||||
| 		} | ||||
|  | ||||
| 		fn.ServeHTTP(g.Writer, g.Request) | ||||
|  | ||||
| 		for _, lstr := range w.listenerAfterRequest { | ||||
| 			lstr(g, nil) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func WrapHTTPHandlerFunc(w *GinWrapper, fn http.HandlerFunc) gin.HandlerFunc { | ||||
| 	return func(g *gin.Context) { | ||||
| 		for _, lstr := range w.listenerBeforeRequest { | ||||
| 			lstr(g) | ||||
| 		} | ||||
|  | ||||
| 		fn(g.Writer, g.Request) | ||||
|  | ||||
| 		for _, lstr := range w.listenerAfterRequest { | ||||
| 			lstr(g, nil) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| package ginext | ||||
|  | ||||
| import ( | ||||
| 	"github.com/gin-gonic/gin" | ||||
| 	"git.blackforestbytes.com/BlackForestBytes/goext/langext" | ||||
| 	"github.com/gin-gonic/gin" | ||||
| 	"net/http" | ||||
| 	"path" | ||||
| 	"reflect" | ||||
| @@ -148,6 +148,68 @@ func (w *GinRouteBuilder) Handle(handler WHandlerFunc) { | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| func (w *GinRouteBuilder) HandleRawHTTPHandler(f http.Handler) { | ||||
| 	if w.routes.wrapper.bufferBody { | ||||
| 		arr := make([]gin.HandlerFunc, 0, len(w.handlers)+1) | ||||
| 		arr = append(arr, BodyBuffer) | ||||
| 		arr = append(arr, w.handlers...) | ||||
| 		w.handlers = arr | ||||
| 	} | ||||
|  | ||||
| 	middlewareNames := langext.ArrMap(w.handlers, func(v gin.HandlerFunc) string { return nameOfFunction(v) }) | ||||
|  | ||||
| 	w.handlers = append(w.handlers, WrapHTTPHandler(w.routes.wrapper, f)) | ||||
|  | ||||
| 	methodName := w.method | ||||
|  | ||||
| 	if w.method == "*" { | ||||
| 		methodName = "ANY" | ||||
| 		for _, method := range anyMethods { | ||||
| 			w.routes.routes.Handle(method, w.relPath, w.handlers...) | ||||
| 		} | ||||
| 	} else { | ||||
| 		w.routes.routes.Handle(w.method, w.relPath, w.handlers...) | ||||
| 	} | ||||
|  | ||||
| 	w.routes.wrapper.routeSpecs = append(w.routes.wrapper.routeSpecs, ginRouteSpec{ | ||||
| 		Method:      methodName, | ||||
| 		URL:         w.absPath, | ||||
| 		Middlewares: middlewareNames, | ||||
| 		Handler:     "[HTTPHandler]", | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| func (w *GinRouteBuilder) HandleRawHTTPHandlerFunc(f http.HandlerFunc) { | ||||
| 	if w.routes.wrapper.bufferBody { | ||||
| 		arr := make([]gin.HandlerFunc, 0, len(w.handlers)+1) | ||||
| 		arr = append(arr, BodyBuffer) | ||||
| 		arr = append(arr, w.handlers...) | ||||
| 		w.handlers = arr | ||||
| 	} | ||||
|  | ||||
| 	middlewareNames := langext.ArrMap(w.handlers, func(v gin.HandlerFunc) string { return nameOfFunction(v) }) | ||||
|  | ||||
| 	w.handlers = append(w.handlers, WrapHTTPHandlerFunc(w.routes.wrapper, f)) | ||||
|  | ||||
| 	methodName := w.method | ||||
|  | ||||
| 	if w.method == "*" { | ||||
| 		methodName = "ANY" | ||||
| 		for _, method := range anyMethods { | ||||
| 			w.routes.routes.Handle(method, w.relPath, w.handlers...) | ||||
| 		} | ||||
| 	} else { | ||||
| 		w.routes.routes.Handle(w.method, w.relPath, w.handlers...) | ||||
| 	} | ||||
|  | ||||
| 	w.routes.wrapper.routeSpecs = append(w.routes.wrapper.routeSpecs, ginRouteSpec{ | ||||
| 		Method:      methodName, | ||||
| 		URL:         w.absPath, | ||||
| 		Middlewares: middlewareNames, | ||||
| 		Handler:     "[HTTPHandlerFunc]", | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| func (w *GinWrapper) NoRoute(handler WHandlerFunc) { | ||||
|  | ||||
| 	handlers := make([]gin.HandlerFunc, 0) | ||||
|   | ||||
							
								
								
									
										24
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								go.mod
									
									
									
									
									
								
							| @@ -11,20 +11,20 @@ require ( | ||||
| 	github.com/rs/xid v1.6.0 | ||||
| 	github.com/rs/zerolog v1.34.0 | ||||
| 	go.mongodb.org/mongo-driver v1.17.4 | ||||
| 	golang.org/x/crypto v0.39.0 | ||||
| 	golang.org/x/sys v0.33.0 | ||||
| 	golang.org/x/term v0.32.0 | ||||
| 	golang.org/x/crypto v0.40.0 | ||||
| 	golang.org/x/sys v0.34.0 | ||||
| 	golang.org/x/term v0.33.0 | ||||
| ) | ||||
|  | ||||
| require ( | ||||
| 	github.com/disintegration/imaging v1.6.2 | ||||
| 	github.com/jung-kurt/gofpdf v1.16.2 | ||||
| 	golang.org/x/sync v0.15.0 | ||||
| 	golang.org/x/sync v0.16.0 | ||||
| ) | ||||
|  | ||||
| require ( | ||||
| 	github.com/bytedance/sonic v1.13.3 // indirect | ||||
| 	github.com/bytedance/sonic/loader v0.2.4 // indirect | ||||
| 	github.com/bytedance/sonic/loader v0.3.0 // indirect | ||||
| 	github.com/cloudwego/base64x v0.1.5 // indirect | ||||
| 	github.com/cloudwego/iasm v0.2.0 // indirect | ||||
| 	github.com/dustin/go-humanize v1.0.1 // indirect | ||||
| @@ -32,13 +32,13 @@ require ( | ||||
| 	github.com/gin-contrib/sse v1.1.0 // indirect | ||||
| 	github.com/go-playground/locales v0.14.1 // indirect | ||||
| 	github.com/go-playground/universal-translator v0.18.1 // indirect | ||||
| 	github.com/go-playground/validator/v10 v10.26.0 // indirect | ||||
| 	github.com/go-playground/validator/v10 v10.27.0 // indirect | ||||
| 	github.com/goccy/go-json v0.10.5 // indirect | ||||
| 	github.com/golang/snappy v1.0.0 // indirect | ||||
| 	github.com/google/uuid v1.5.0 // indirect | ||||
| 	github.com/json-iterator/go v1.1.12 // indirect | ||||
| 	github.com/klauspost/compress v1.18.0 // indirect | ||||
| 	github.com/klauspost/cpuid/v2 v2.2.10 // indirect | ||||
| 	github.com/klauspost/cpuid/v2 v2.3.0 // indirect | ||||
| 	github.com/leodido/go-urn v1.4.0 // indirect | ||||
| 	github.com/mattn/go-colorable v0.1.14 // indirect | ||||
| 	github.com/mattn/go-isatty v0.0.20 // indirect | ||||
| @@ -48,15 +48,15 @@ require ( | ||||
| 	github.com/pelletier/go-toml/v2 v2.2.4 // indirect | ||||
| 	github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect | ||||
| 	github.com/twitchyliquid64/golang-asm v0.15.1 // indirect | ||||
| 	github.com/ugorji/go/codec v1.2.14 // indirect | ||||
| 	github.com/ugorji/go/codec v1.3.0 // indirect | ||||
| 	github.com/xdg-go/pbkdf2 v1.0.0 // indirect | ||||
| 	github.com/xdg-go/scram v1.1.2 // indirect | ||||
| 	github.com/xdg-go/stringprep v1.0.4 // indirect | ||||
| 	github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect | ||||
| 	golang.org/x/arch v0.18.0 // indirect | ||||
| 	golang.org/x/image v0.28.0 // indirect | ||||
| 	golang.org/x/net v0.41.0 // indirect | ||||
| 	golang.org/x/text v0.26.0 // indirect | ||||
| 	golang.org/x/arch v0.19.0 // indirect | ||||
| 	golang.org/x/image v0.29.0 // indirect | ||||
| 	golang.org/x/net v0.42.0 // indirect | ||||
| 	golang.org/x/text v0.27.0 // indirect | ||||
| 	google.golang.org/protobuf v1.36.6 // indirect | ||||
| 	gopkg.in/yaml.v3 v3.0.1 // indirect | ||||
| 	modernc.org/libc v1.37.6 // indirect | ||||
|   | ||||
							
								
								
									
										26
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								go.sum
									
									
									
									
									
								
							| @@ -34,6 +34,8 @@ github.com/bytedance/sonic/loader v0.2.3 h1:yctD0Q3v2NOGfSWPLPvG2ggA2kV6TS6s4wio | ||||
| github.com/bytedance/sonic/loader v0.2.3/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI= | ||||
| github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY= | ||||
| github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI= | ||||
| github.com/bytedance/sonic/loader v0.3.0 h1:dskwH8edlzNMctoruo8FPTJDF3vLtDT0sXZwvZJyqeA= | ||||
| github.com/bytedance/sonic/loader v0.3.0/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI= | ||||
| github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= | ||||
| github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= | ||||
| github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4= | ||||
| @@ -86,6 +88,8 @@ github.com/go-playground/validator/v10 v10.25.0 h1:5Dh7cjvzR7BRZadnsVOzPhWsrwUr0 | ||||
| github.com/go-playground/validator/v10 v10.25.0/go.mod h1:GGzBIJMuE98Ic/kJsBXbz1x/7cByt++cQ+YOuDM5wus= | ||||
| github.com/go-playground/validator/v10 v10.26.0 h1:SP05Nqhjcvz81uJaRfEV0YBSSSGMc/iMaVtFbr3Sw2k= | ||||
| github.com/go-playground/validator/v10 v10.26.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo= | ||||
| github.com/go-playground/validator/v10 v10.27.0 h1:w8+XrWVMhGkxOaaowyKH35gFydVHOvC0/uWoy2Fzwn4= | ||||
| github.com/go-playground/validator/v10 v10.27.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo= | ||||
| github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= | ||||
| github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= | ||||
| github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA= | ||||
| @@ -126,6 +130,10 @@ github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kK | ||||
| github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK4QwQ3WMXF8= | ||||
| github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE= | ||||
| github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= | ||||
| github.com/klauspost/cpuid/v2 v2.2.11 h1:0OwqZRYI2rFrjS4kvkDnqJkKHdHaRnCm68/DY4OxRzU= | ||||
| github.com/klauspost/cpuid/v2 v2.2.11/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= | ||||
| github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y= | ||||
| github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= | ||||
| github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= | ||||
| github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= | ||||
| github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= | ||||
| @@ -187,6 +195,8 @@ github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65E | ||||
| github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= | ||||
| github.com/ugorji/go/codec v1.2.14 h1:yOQvXCBc3Ij46LRkRoh4Yd5qK6LVOgi0bYOXfb7ifjw= | ||||
| github.com/ugorji/go/codec v1.2.14/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= | ||||
| github.com/ugorji/go/codec v1.3.0 h1:Qd2W2sQawAfG8XSvzwhBeoGq71zXOC/Q1E9y/wUcsUA= | ||||
| github.com/ugorji/go/codec v1.3.0/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4= | ||||
| github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= | ||||
| github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= | ||||
| github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= | ||||
| @@ -220,6 +230,8 @@ golang.org/x/arch v0.17.0 h1:4O3dfLzd+lQewptAHqjewQZQDyEdejz3VwgeYwkZneU= | ||||
| golang.org/x/arch v0.17.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk= | ||||
| golang.org/x/arch v0.18.0 h1:WN9poc33zL4AzGxqf8VtpKUnGvMi8O9lhNyBMF/85qc= | ||||
| golang.org/x/arch v0.18.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk= | ||||
| golang.org/x/arch v0.19.0 h1:LmbDQUodHThXE+htjrnmVD73M//D9GTH6wFZjyDkjyU= | ||||
| golang.org/x/arch v0.19.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk= | ||||
| golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||||
| golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= | ||||
| golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= | ||||
| @@ -244,6 +256,8 @@ golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8= | ||||
| golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw= | ||||
| golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM= | ||||
| golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U= | ||||
| golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM= | ||||
| golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY= | ||||
| golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= | ||||
| golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= | ||||
| golang.org/x/image v0.21.0 h1:c5qV36ajHpdj4Qi0GnE0jUc/yuo33OLFaa0d+crTD5s= | ||||
| @@ -262,6 +276,8 @@ golang.org/x/image v0.27.0 h1:C8gA4oWU/tKkdCfYT6T2u4faJu3MeNS5O8UPWlPF61w= | ||||
| golang.org/x/image v0.27.0/go.mod h1:xbdrClrAUway1MUTEZDq9mz/UpRwYAkFFNUslZtcB+g= | ||||
| golang.org/x/image v0.28.0 h1:gdem5JW1OLS4FbkWgLO+7ZeFzYtL3xClb97GaUzYMFE= | ||||
| golang.org/x/image v0.28.0/go.mod h1:GUJYXtnGKEUgggyzh+Vxt+AviiCcyiwpsl8iQ8MvwGY= | ||||
| golang.org/x/image v0.29.0 h1:HcdsyR4Gsuys/Axh0rDEmlBmB68rW1U9BUdB3UVHsas= | ||||
| golang.org/x/image v0.29.0/go.mod h1:RVJROnf3SLK8d26OW91j4FrIHGbsJ8QnbEocVTOWQDA= | ||||
| golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= | ||||
| golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= | ||||
| golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= | ||||
| @@ -288,6 +304,8 @@ golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY= | ||||
| golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds= | ||||
| golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw= | ||||
| golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA= | ||||
| golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs= | ||||
| golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8= | ||||
| golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||||
| golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||||
| golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= | ||||
| @@ -306,6 +324,8 @@ golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ= | ||||
| golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= | ||||
| golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8= | ||||
| golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= | ||||
| golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw= | ||||
| golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= | ||||
| golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||||
| golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||||
| @@ -331,6 +351,8 @@ golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= | ||||
| golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= | ||||
| golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= | ||||
| golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= | ||||
| golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA= | ||||
| golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= | ||||
| golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | ||||
| golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= | ||||
| golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24= | ||||
| @@ -349,6 +371,8 @@ golang.org/x/term v0.31.0 h1:erwDkOK1Msy6offm1mOgvspSkslFnIGsFnxOKoufg3o= | ||||
| golang.org/x/term v0.31.0/go.mod h1:R4BeIy7D95HzImkxGkTW1UQTtP54tio2RyHz7PwK0aw= | ||||
| golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg= | ||||
| golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ= | ||||
| golang.org/x/term v0.33.0 h1:NuFncQrRcaRvVmgRkvM3j/F00gWIAlcmlB8ACEKmGIg= | ||||
| golang.org/x/term v0.33.0/go.mod h1:s18+ql9tYWp1IfpV9DmCtQDDSRBUjKaw9M1eAv5UeF0= | ||||
| golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||||
| golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||||
| golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= | ||||
| @@ -369,6 +393,8 @@ golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= | ||||
| golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA= | ||||
| golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M= | ||||
| golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA= | ||||
| golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4= | ||||
| golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU= | ||||
| golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||||
| golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= | ||||
| golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| package goext | ||||
|  | ||||
| const GoextVersion = "0.0.579" | ||||
| const GoextVersion = "0.0.589" | ||||
|  | ||||
| const GoextVersionTimestamp = "2025-06-13T16:53:24+0200" | ||||
| const GoextVersionTimestamp = "2025-07-15T13:46:36+0200" | ||||
|   | ||||
							
								
								
									
										23
									
								
								langext/base64.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								langext/base64.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,23 @@ | ||||
| package langext | ||||
|  | ||||
| import ( | ||||
| 	"encoding/base64" | ||||
| 	"strings" | ||||
| ) | ||||
|  | ||||
| // DecodeBase64Any decodes a base64 encoded string | ||||
| // Works with all variants (std, url, imap), padded and unpadded and even ignores linrebreaks and indents | ||||
| func DecodeBase64Any(data string) ([]byte, error) { | ||||
| 	data = strings.ReplaceAll(data, "\n", "") // remove linebreaks and indents | ||||
| 	data = strings.ReplaceAll(data, "\t", "") // remove linebreaks and indents | ||||
| 	data = strings.ReplaceAll(data, " ", "")  // remove linebreaks and indents | ||||
|  | ||||
| 	data = strings.ReplaceAll(data, ",", "/") // base64_imap --> base64_std | ||||
|  | ||||
| 	data = strings.ReplaceAll(data, "_", "/") // base64_url --> base64_std | ||||
| 	data = strings.ReplaceAll(data, "-", "+") // base64_url --> base64_std | ||||
|  | ||||
| 	data = strings.ReplaceAll(data, "=", "") // no padding | ||||
|  | ||||
| 	return base64.RawStdEncoding.DecodeString(data) | ||||
| } | ||||
							
								
								
									
										246
									
								
								langext/base64_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										246
									
								
								langext/base64_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,246 @@ | ||||
| package langext | ||||
|  | ||||
| import ( | ||||
| 	"testing" | ||||
| ) | ||||
|  | ||||
| func TestDecodeBase64Any_StandardPadded(t *testing.T) { | ||||
| 	input := "SGVsbG8gV29ybGQ=" // "Hello World" in standard Base64 (padded) | ||||
| 	expected := "Hello World" | ||||
|  | ||||
| 	result, err := DecodeBase64Any(input) | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("unexpected error: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if string(result) != expected { | ||||
| 		t.Errorf("expected %q, got %q", expected, string(result)) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestDecodeBase64Any_StandardUnpadded(t *testing.T) { | ||||
| 	input := "SGVsbG8gV29ybGQ" // "Hello World" in standard Base64 (unpadded) | ||||
| 	expected := "Hello World" | ||||
|  | ||||
| 	result, err := DecodeBase64Any(input) | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("unexpected error: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if string(result) != expected { | ||||
| 		t.Errorf("expected %q, got %q", expected, string(result)) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestDecodeBase64Any_URLPadded(t *testing.T) { | ||||
| 	input := "SGVsbG8tV29ybGQ=" // "Hello-World" in Base64 URL (padded) | ||||
| 	expected := "Hello-World" | ||||
|  | ||||
| 	result, err := DecodeBase64Any(input) | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("unexpected error: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if string(result) != expected { | ||||
| 		t.Errorf("expected %q, got %q", expected, string(result)) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestDecodeBase64Any_URLUnpadded(t *testing.T) { | ||||
| 	input := "SGVsbG8tV29ybGQ" // "Hello-World" in Base64 URL (unpadded) | ||||
| 	expected := "Hello-World" | ||||
|  | ||||
| 	result, err := DecodeBase64Any(input) | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("unexpected error: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if string(result) != expected { | ||||
| 		t.Errorf("expected %q, got %q", expected, string(result)) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestDecodeBase64Any_IMAPPadded(t *testing.T) { | ||||
| 	input := "SGVsbG8,V29ybGQ=" // "Hello/World" in Base64 IMAP (padded) | ||||
| 	expected := "Hello?World" | ||||
|  | ||||
| 	result, err := DecodeBase64Any(input) | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("unexpected error: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if string(result) != expected { | ||||
| 		t.Errorf("expected %q, got %q", expected, string(result)) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestDecodeBase64Any_IMAPUnpadded(t *testing.T) { | ||||
| 	input := "SGVsbG8,V29ybGQ" // "Hello/World" in Base64 IMAP (unpadded) | ||||
| 	expected := "Hello?World" | ||||
|  | ||||
| 	result, err := DecodeBase64Any(input) | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("unexpected error: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if string(result) != expected { | ||||
| 		t.Errorf("expected %q, got %q", expected, string(result)) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestDecodeBase64Any_InvalidInput(t *testing.T) { | ||||
| 	input := "Invalid@@Base64" // Invalid Base64 input | ||||
|  | ||||
| 	_, err := DecodeBase64Any(input) | ||||
| 	if err == nil { | ||||
| 		t.Fatal("expected an error, but got none") | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestDecodeBase64Any_EmptyInput(t *testing.T) { | ||||
| 	input := "" // Empty input | ||||
|  | ||||
| 	result, err := DecodeBase64Any(input) | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("unexpected error: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if len(result) != 0 { | ||||
| 		t.Errorf("expected empty result, got %q", string(result)) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestDecodeBase64Any_WhitespaceInput(t *testing.T) { | ||||
| 	input := "  SGVsbG8gV29ybGQ=  " // Input with leading and trailing spaces | ||||
| 	expected := "Hello World" | ||||
|  | ||||
| 	result, err := DecodeBase64Any(input) | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("unexpected error: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if string(result) != expected { | ||||
| 		t.Errorf("expected %q, got %q", expected, string(result)) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestDecodeBase64Any_LineBreaksInput(t *testing.T) { | ||||
| 	input := "SGVs\nbG8g\nV29y\nbGQ=" // Input with line breaks | ||||
| 	expected := "Hello World" | ||||
|  | ||||
| 	result, err := DecodeBase64Any(input) | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("unexpected error: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if string(result) != expected { | ||||
| 		t.Errorf("expected %q, got %q", expected, string(result)) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestDecodeBase64Any_TabCharactersInput(t *testing.T) { | ||||
| 	input := "SGVsbG8g\tV29ybGQ=" // Input with tab characters | ||||
| 	expected := "Hello World" | ||||
|  | ||||
| 	result, err := DecodeBase64Any(input) | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("unexpected error: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if string(result) != expected { | ||||
| 		t.Errorf("expected %q, got %q", expected, string(result)) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestDecodeBase64Any_SpecialCharactersIgnored(t *testing.T) { | ||||
| 	input := "SGVsbG8gV29ybGQ=!!" // Input with ignored special characters | ||||
|  | ||||
| 	_, err := DecodeBase64Any(input) | ||||
| 	if err == nil { | ||||
| 		t.Fatal("expected an error, but got none") | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestDecodeBase64Any_SingleCharacterInput(t *testing.T) { | ||||
| 	input := "QQ==" // "A" in Base64 | ||||
| 	expected := "A" | ||||
|  | ||||
| 	result, err := DecodeBase64Any(input) | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("unexpected error: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if string(result) != expected { | ||||
| 		t.Errorf("expected %q, got %q", expected, string(result)) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestDecodeBase64Any_LongInput(t *testing.T) { | ||||
| 	input := "U29tZSB2ZXJ5IGxvbmcgc3RyaW5nIHdpdGggbXVsdGlwbGUgbGluZXMgYW5kIHNwYWNlcy4=" // Long Base64 string | ||||
| 	expected := "Some very long string with multiple lines and spaces." | ||||
|  | ||||
| 	result, err := DecodeBase64Any(input) | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("unexpected error: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if string(result) != expected { | ||||
| 		t.Errorf("expected %q, got %q", expected, string(result)) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestDecodeBase64Any_Standard63And64(t *testing.T) { | ||||
| 	input := "Pz8/Pw==" // "???" in standard Base64 (63 = '+', 64 = '/') | ||||
| 	expected := "????" | ||||
|  | ||||
| 	result, err := DecodeBase64Any(input) | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("unexpected error: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if string(result) != expected { | ||||
| 		t.Errorf("expected %q, got %q", expected, string(result)) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestDecodeBase64Any_Standard63And64_NoPad(t *testing.T) { | ||||
| 	input := "Pz8/Pw" // "???" in standard Base64 (63 = '+', 64 = '/') | ||||
| 	expected := "????" | ||||
|  | ||||
| 	result, err := DecodeBase64Any(input) | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("unexpected error: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if string(result) != expected { | ||||
| 		t.Errorf("expected %q, got %q", expected, string(result)) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestDecodeBase64Any_URL63And64(t *testing.T) { | ||||
| 	input := "Pz8_Pw==" // "???" in Base64 URL-safe (63 = '_', 64 = '-') | ||||
| 	expected := "????" | ||||
|  | ||||
| 	result, err := DecodeBase64Any(input) | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("unexpected error: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if string(result) != expected { | ||||
| 		t.Errorf("expected %q, got %q", expected, string(result)) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestDecodeBase64Any_URL63And64_NoPad(t *testing.T) { | ||||
| 	input := "Pz8_Pw==" // "???" in Base64 URL-safe (63 = '_', 64 = '-') | ||||
| 	expected := "????" | ||||
|  | ||||
| 	result, err := DecodeBase64Any(input) | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("unexpected error: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if string(result) != expected { | ||||
| 		t.Errorf("expected %q, got %q", expected, string(result)) | ||||
| 	} | ||||
| } | ||||
| @@ -1,57 +1,51 @@ | ||||
| package mongoext | ||||
|  | ||||
| import ( | ||||
| 	"go.mongodb.org/mongo-driver/bson" | ||||
| 	"go.mongodb.org/mongo-driver/bson/bsoncodec" | ||||
| 	"go.mongodb.org/mongo-driver/bson/bsontype" | ||||
| 	"go.mongodb.org/mongo-driver/bson/primitive" | ||||
| 	"git.blackforestbytes.com/BlackForestBytes/goext/exerr" | ||||
| 	"git.blackforestbytes.com/BlackForestBytes/goext/langext" | ||||
| 	"git.blackforestbytes.com/BlackForestBytes/goext/rfctime" | ||||
| 	"go.mongodb.org/mongo-driver/bson" | ||||
| 	"go.mongodb.org/mongo-driver/bson/bsoncodec" | ||||
| 	"go.mongodb.org/mongo-driver/bson/primitive" | ||||
| 	"reflect" | ||||
| ) | ||||
|  | ||||
| func CreateGoExtBsonRegistry() *bsoncodec.Registry { | ||||
| 	rb := bsoncodec.NewRegistryBuilder() | ||||
| 	reg := bson.NewRegistry() | ||||
|  | ||||
| 	rb.RegisterTypeDecoder(reflect.TypeOf(rfctime.RFC3339Time{}), rfctime.RFC3339Time{}) | ||||
| 	rb.RegisterTypeDecoder(reflect.TypeOf(&rfctime.RFC3339Time{}), rfctime.RFC3339Time{}) | ||||
| 	reg.RegisterTypeDecoder(reflect.TypeOf(rfctime.RFC3339Time{}), rfctime.RFC3339Time{}) | ||||
| 	reg.RegisterTypeDecoder(reflect.TypeOf(&rfctime.RFC3339Time{}), rfctime.RFC3339Time{}) | ||||
|  | ||||
| 	rb.RegisterTypeDecoder(reflect.TypeOf(rfctime.RFC3339NanoTime{}), rfctime.RFC3339NanoTime{}) | ||||
| 	rb.RegisterTypeDecoder(reflect.TypeOf(&rfctime.RFC3339NanoTime{}), rfctime.RFC3339NanoTime{}) | ||||
| 	reg.RegisterTypeDecoder(reflect.TypeOf(rfctime.RFC3339NanoTime{}), rfctime.RFC3339NanoTime{}) | ||||
| 	reg.RegisterTypeDecoder(reflect.TypeOf(&rfctime.RFC3339NanoTime{}), rfctime.RFC3339NanoTime{}) | ||||
|  | ||||
| 	rb.RegisterTypeDecoder(reflect.TypeOf(rfctime.UnixTime{}), rfctime.UnixTime{}) | ||||
| 	rb.RegisterTypeDecoder(reflect.TypeOf(&rfctime.UnixTime{}), rfctime.UnixTime{}) | ||||
| 	reg.RegisterTypeDecoder(reflect.TypeOf(rfctime.UnixTime{}), rfctime.UnixTime{}) | ||||
| 	reg.RegisterTypeDecoder(reflect.TypeOf(&rfctime.UnixTime{}), rfctime.UnixTime{}) | ||||
|  | ||||
| 	rb.RegisterTypeDecoder(reflect.TypeOf(rfctime.UnixMilliTime{}), rfctime.UnixMilliTime{}) | ||||
| 	rb.RegisterTypeDecoder(reflect.TypeOf(&rfctime.UnixMilliTime{}), rfctime.UnixMilliTime{}) | ||||
| 	reg.RegisterTypeDecoder(reflect.TypeOf(rfctime.UnixMilliTime{}), rfctime.UnixMilliTime{}) | ||||
| 	reg.RegisterTypeDecoder(reflect.TypeOf(&rfctime.UnixMilliTime{}), rfctime.UnixMilliTime{}) | ||||
|  | ||||
| 	rb.RegisterTypeDecoder(reflect.TypeOf(rfctime.UnixNanoTime{}), rfctime.UnixNanoTime{}) | ||||
| 	rb.RegisterTypeDecoder(reflect.TypeOf(&rfctime.UnixNanoTime{}), rfctime.UnixNanoTime{}) | ||||
| 	reg.RegisterTypeDecoder(reflect.TypeOf(rfctime.UnixNanoTime{}), rfctime.UnixNanoTime{}) | ||||
| 	reg.RegisterTypeDecoder(reflect.TypeOf(&rfctime.UnixNanoTime{}), rfctime.UnixNanoTime{}) | ||||
|  | ||||
| 	rb.RegisterTypeDecoder(reflect.TypeOf(rfctime.Date{}), rfctime.Date{}) | ||||
| 	rb.RegisterTypeDecoder(reflect.TypeOf(&rfctime.Date{}), rfctime.Date{}) | ||||
| 	reg.RegisterTypeDecoder(reflect.TypeOf(rfctime.Date{}), rfctime.Date{}) | ||||
| 	reg.RegisterTypeDecoder(reflect.TypeOf(&rfctime.Date{}), rfctime.Date{}) | ||||
|  | ||||
| 	rb.RegisterTypeDecoder(reflect.TypeOf(rfctime.SecondsF64(0)), rfctime.SecondsF64(0)) | ||||
| 	rb.RegisterTypeDecoder(reflect.TypeOf(langext.Ptr(rfctime.SecondsF64(0))), rfctime.SecondsF64(0)) | ||||
| 	reg.RegisterTypeDecoder(reflect.TypeOf(rfctime.SecondsF64(0)), rfctime.SecondsF64(0)) | ||||
| 	reg.RegisterTypeDecoder(reflect.TypeOf(langext.Ptr(rfctime.SecondsF64(0))), rfctime.SecondsF64(0)) | ||||
|  | ||||
| 	rb.RegisterTypeDecoder(reflect.TypeOf(exerr.ErrorCategory{}), exerr.ErrorCategory{}) | ||||
| 	rb.RegisterTypeDecoder(reflect.TypeOf(langext.Ptr(exerr.ErrorCategory{})), exerr.ErrorCategory{}) | ||||
| 	reg.RegisterTypeDecoder(reflect.TypeOf(exerr.ErrorCategory{}), exerr.ErrorCategory{}) | ||||
| 	reg.RegisterTypeDecoder(reflect.TypeOf(langext.Ptr(exerr.ErrorCategory{})), exerr.ErrorCategory{}) | ||||
|  | ||||
| 	rb.RegisterTypeDecoder(reflect.TypeOf(exerr.ErrorSeverity{}), exerr.ErrorSeverity{}) | ||||
| 	rb.RegisterTypeDecoder(reflect.TypeOf(langext.Ptr(exerr.ErrorSeverity{})), exerr.ErrorSeverity{}) | ||||
| 	reg.RegisterTypeDecoder(reflect.TypeOf(exerr.ErrorSeverity{}), exerr.ErrorSeverity{}) | ||||
| 	reg.RegisterTypeDecoder(reflect.TypeOf(langext.Ptr(exerr.ErrorSeverity{})), exerr.ErrorSeverity{}) | ||||
|  | ||||
| 	rb.RegisterTypeDecoder(reflect.TypeOf(exerr.ErrorType{}), exerr.ErrorType{}) | ||||
| 	rb.RegisterTypeDecoder(reflect.TypeOf(langext.Ptr(exerr.ErrorType{})), exerr.ErrorType{}) | ||||
|  | ||||
| 	bsoncodec.DefaultValueEncoders{}.RegisterDefaultEncoders(rb) | ||||
| 	bsoncodec.DefaultValueDecoders{}.RegisterDefaultDecoders(rb) | ||||
|  | ||||
| 	bson.PrimitiveCodecs{}.RegisterPrimitiveCodecs(rb) | ||||
| 	reg.RegisterTypeDecoder(reflect.TypeOf(exerr.ErrorType{}), exerr.ErrorType{}) | ||||
| 	reg.RegisterTypeDecoder(reflect.TypeOf(langext.Ptr(exerr.ErrorType{})), exerr.ErrorType{}) | ||||
|  | ||||
| 	// otherwise we get []primitve.E when unmarshalling into any | ||||
| 	// which will result in {'key': .., 'value': ...}[] json when json-marshalling | ||||
| 	rb.RegisterTypeMapEntry(bsontype.EmbeddedDocument, reflect.TypeOf(primitive.M{})) | ||||
| 	reg.RegisterTypeMapEntry(bson.TypeEmbeddedDocument, reflect.TypeOf(primitive.M{})) | ||||
|  | ||||
| 	return rb.Build() | ||||
| 	return reg | ||||
| } | ||||
|   | ||||
| @@ -4,11 +4,11 @@ import ( | ||||
| 	"encoding/json" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"git.blackforestbytes.com/BlackForestBytes/goext/langext" | ||||
| 	"go.mongodb.org/mongo-driver/bson" | ||||
| 	"go.mongodb.org/mongo-driver/bson/bsoncodec" | ||||
| 	"go.mongodb.org/mongo-driver/bson/bsonrw" | ||||
| 	"go.mongodb.org/mongo-driver/bson/bsontype" | ||||
| 	"git.blackforestbytes.com/BlackForestBytes/goext/langext" | ||||
| 	"reflect" | ||||
| 	"time" | ||||
| ) | ||||
| @@ -142,7 +142,13 @@ func (t RFC3339Time) Before(u AnyTime) bool { | ||||
| 	return t.Time().Before(tt(u)) | ||||
| } | ||||
|  | ||||
| func (t RFC3339Time) Equal(u AnyTime) bool { | ||||
| func (t *RFC3339Time) Equal(u AnyTime) bool { | ||||
| 	if t == nil && u == nil { | ||||
| 		return true | ||||
| 	} | ||||
| 	if t == nil || u == nil { | ||||
| 		return false | ||||
| 	} | ||||
| 	return t.Time().Equal(tt(u)) | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -4,11 +4,11 @@ import ( | ||||
| 	"encoding/json" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"git.blackforestbytes.com/BlackForestBytes/goext/langext" | ||||
| 	"go.mongodb.org/mongo-driver/bson" | ||||
| 	"go.mongodb.org/mongo-driver/bson/bsoncodec" | ||||
| 	"go.mongodb.org/mongo-driver/bson/bsonrw" | ||||
| 	"go.mongodb.org/mongo-driver/bson/bsontype" | ||||
| 	"git.blackforestbytes.com/BlackForestBytes/goext/langext" | ||||
| 	"reflect" | ||||
| 	"time" | ||||
| ) | ||||
| @@ -142,7 +142,13 @@ func (t RFC3339NanoTime) Before(u AnyTime) bool { | ||||
| 	return t.Time().Before(tt(u)) | ||||
| } | ||||
|  | ||||
| func (t RFC3339NanoTime) Equal(u AnyTime) bool { | ||||
| func (t *RFC3339NanoTime) Equal(u AnyTime) bool { | ||||
| 	if t == nil && u == nil { | ||||
| 		return true | ||||
| 	} | ||||
| 	if t == nil || u == nil { | ||||
| 		return false | ||||
| 	} | ||||
| 	return t.Time().Equal(tt(u)) | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -4,11 +4,11 @@ import ( | ||||
| 	"encoding/json" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"git.blackforestbytes.com/BlackForestBytes/goext/langext" | ||||
| 	"go.mongodb.org/mongo-driver/bson" | ||||
| 	"go.mongodb.org/mongo-driver/bson/bsoncodec" | ||||
| 	"go.mongodb.org/mongo-driver/bson/bsonrw" | ||||
| 	"go.mongodb.org/mongo-driver/bson/bsontype" | ||||
| 	"git.blackforestbytes.com/BlackForestBytes/goext/langext" | ||||
| 	"reflect" | ||||
| 	"strconv" | ||||
| 	"time" | ||||
| @@ -136,7 +136,13 @@ func (t UnixTime) Before(u AnyTime) bool { | ||||
| 	return t.Time().Before(tt(u)) | ||||
| } | ||||
|  | ||||
| func (t UnixTime) Equal(u AnyTime) bool { | ||||
| func (t *UnixTime) Equal(u AnyTime) bool { | ||||
| 	if t == nil && u == nil { | ||||
| 		return true | ||||
| 	} | ||||
| 	if t == nil || u == nil { | ||||
| 		return false | ||||
| 	} | ||||
| 	return t.Time().Equal(tt(u)) | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -4,11 +4,11 @@ import ( | ||||
| 	"encoding/json" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"git.blackforestbytes.com/BlackForestBytes/goext/langext" | ||||
| 	"go.mongodb.org/mongo-driver/bson" | ||||
| 	"go.mongodb.org/mongo-driver/bson/bsoncodec" | ||||
| 	"go.mongodb.org/mongo-driver/bson/bsonrw" | ||||
| 	"go.mongodb.org/mongo-driver/bson/bsontype" | ||||
| 	"git.blackforestbytes.com/BlackForestBytes/goext/langext" | ||||
| 	"reflect" | ||||
| 	"strconv" | ||||
| 	"time" | ||||
| @@ -136,7 +136,13 @@ func (t UnixMilliTime) Before(u AnyTime) bool { | ||||
| 	return t.Time().Before(tt(u)) | ||||
| } | ||||
|  | ||||
| func (t UnixMilliTime) Equal(u AnyTime) bool { | ||||
| func (t *UnixMilliTime) Equal(u AnyTime) bool { | ||||
| 	if t == nil && u == nil { | ||||
| 		return true | ||||
| 	} | ||||
| 	if t == nil || u == nil { | ||||
| 		return false | ||||
| 	} | ||||
| 	return t.Time().Equal(tt(u)) | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -4,11 +4,11 @@ import ( | ||||
| 	"encoding/json" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"git.blackforestbytes.com/BlackForestBytes/goext/langext" | ||||
| 	"go.mongodb.org/mongo-driver/bson" | ||||
| 	"go.mongodb.org/mongo-driver/bson/bsoncodec" | ||||
| 	"go.mongodb.org/mongo-driver/bson/bsonrw" | ||||
| 	"go.mongodb.org/mongo-driver/bson/bsontype" | ||||
| 	"git.blackforestbytes.com/BlackForestBytes/goext/langext" | ||||
| 	"reflect" | ||||
| 	"strconv" | ||||
| 	"time" | ||||
| @@ -136,7 +136,13 @@ func (t UnixNanoTime) Before(u AnyTime) bool { | ||||
| 	return t.Time().Before(tt(u)) | ||||
| } | ||||
|  | ||||
| func (t UnixNanoTime) Equal(u AnyTime) bool { | ||||
| func (t *UnixNanoTime) Equal(u AnyTime) bool { | ||||
| 	if t == nil && u == nil { | ||||
| 		return true | ||||
| 	} | ||||
| 	if t == nil || u == nil { | ||||
| 		return false | ||||
| 	} | ||||
| 	return t.Time().Equal(tt(u)) | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -3,6 +3,7 @@ package timeext | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"math" | ||||
| 	"sort" | ||||
| 	"time" | ||||
| ) | ||||
|  | ||||
| @@ -142,6 +143,42 @@ func Max(a time.Time, b time.Time) time.Time { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func Avg(v ...time.Time) time.Time { | ||||
| 	if len(v) == 0 { | ||||
| 		return time.Time{} | ||||
| 	} | ||||
|  | ||||
| 	t0 := v[0].UnixNano() | ||||
|  | ||||
| 	var dsum int64 | ||||
| 	for _, t := range v { | ||||
| 		dsum += t.UnixNano() - t0 | ||||
| 	} | ||||
|  | ||||
| 	tAvg := t0 + (dsum / int64(len(v))) | ||||
|  | ||||
| 	return time.Unix(0, tAvg) | ||||
| } | ||||
|  | ||||
| func Median(v ...time.Time) time.Time { | ||||
| 	if len(v) == 0 { | ||||
| 		return time.Time{} | ||||
| 	} | ||||
|  | ||||
| 	sorted := make([]time.Time, len(v)) | ||||
| 	copy(sorted, v) | ||||
| 	sort.Slice(sorted, func(i, j int) bool { | ||||
| 		return sorted[i].UnixNano() < sorted[j].UnixNano() | ||||
| 	}) | ||||
|  | ||||
| 	mid := len(sorted) / 2 | ||||
| 	if len(sorted)%2 == 0 { | ||||
| 		return Avg(sorted[mid-1], sorted[mid]) | ||||
| 	} else { | ||||
| 		return sorted[mid] | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func UnixFloatSeconds(v float64) time.Time { | ||||
| 	sec, dec := math.Modf(v) | ||||
| 	return time.Unix(int64(sec), int64(dec*(1e9))) | ||||
|   | ||||
| @@ -227,3 +227,192 @@ func TestDaysInMonth_FebruaryNonLeapYear(t *testing.T) { | ||||
| 		t.Errorf("Expected %d but got %d", expected, result) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestAvg_MultipleValues(t *testing.T) { | ||||
| 	t1 := time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC) | ||||
| 	t2 := time.Date(2022, 1, 3, 0, 0, 0, 0, time.UTC) | ||||
| 	t3 := time.Date(2022, 1, 5, 0, 0, 0, 0, time.UTC) | ||||
|  | ||||
| 	// Average should be January 3, 2022 (middle date) | ||||
| 	expected := time.Date(2022, 1, 3, 0, 0, 0, 0, time.UTC) | ||||
| 	result := Avg(t1, t2, t3) | ||||
|  | ||||
| 	if !result.Equal(expected) { | ||||
| 		t.Errorf("Expected %v but got %v", expected, result) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestAvg_ManyValues(t *testing.T) { | ||||
| 	t1 := time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC) | ||||
| 	t2 := time.Date(2022, 1, 2, 0, 0, 0, 0, time.UTC) | ||||
| 	t3 := time.Date(2022, 1, 3, 0, 0, 0, 0, time.UTC) | ||||
| 	t4 := time.Date(2022, 1, 4, 0, 0, 0, 0, time.UTC) | ||||
| 	t5 := time.Date(2022, 1, 5, 0, 0, 0, 0, time.UTC) | ||||
| 	t6 := time.Date(2022, 1, 6, 0, 0, 0, 0, time.UTC) | ||||
| 	t7 := time.Date(2022, 1, 7, 0, 0, 0, 0, time.UTC) | ||||
| 	t8 := time.Date(2022, 1, 8, 0, 0, 0, 0, time.UTC) | ||||
| 	t9 := time.Date(2022, 1, 9, 0, 0, 0, 0, time.UTC) | ||||
|  | ||||
| 	expected := time.Date(2022, 1, 5, 0, 0, 0, 0, time.UTC) | ||||
| 	result := Avg(t1, t2, t3, t4, t5, t6, t7, t8, t9) | ||||
|  | ||||
| 	if !result.Equal(expected) { | ||||
| 		t.Errorf("Expected %v but got %v", expected, result) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestAvg_TwoValues(t *testing.T) { | ||||
| 	t1 := time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC) | ||||
| 	t2 := time.Date(2022, 1, 3, 0, 0, 0, 0, time.UTC) | ||||
|  | ||||
| 	expected := time.Date(2022, 1, 2, 0, 0, 0, 0, time.UTC) | ||||
| 	result := Avg(t1, t2) | ||||
|  | ||||
| 	if !result.Equal(expected) { | ||||
| 		t.Errorf("Expected %v but got %v", expected, result) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestAvg_EmptySlice(t *testing.T) { | ||||
| 	result := Avg() | ||||
| 	expected := time.Time{} | ||||
|  | ||||
| 	if !result.Equal(expected) { | ||||
| 		t.Errorf("Expected zero time but got %v", result) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestMedian_OddNumberOfValues(t *testing.T) { | ||||
| 	t1 := time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC) | ||||
| 	t2 := time.Date(2022, 1, 3, 0, 0, 0, 0, time.UTC) | ||||
| 	t3 := time.Date(2022, 1, 5, 0, 0, 0, 0, time.UTC) | ||||
|  | ||||
| 	// Median should be the middle date | ||||
| 	expected := t2 | ||||
| 	result := Median(t1, t2, t3) | ||||
|  | ||||
| 	if !result.Equal(expected) { | ||||
| 		t.Errorf("Expected %v but got %v", expected, result) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestMedian_EvenNumberOfValues(t *testing.T) { | ||||
| 	t1 := time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC) | ||||
| 	t2 := time.Date(2022, 1, 2, 0, 0, 0, 0, time.UTC) | ||||
| 	t3 := time.Date(2022, 1, 3, 0, 0, 0, 0, time.UTC) | ||||
| 	t4 := time.Date(2022, 1, 4, 0, 0, 0, 0, time.UTC) | ||||
|  | ||||
| 	// Median for even number of values should be average of middle two | ||||
| 	expected := time.Date(2022, 1, 2, 12, 0, 0, 0, time.UTC) | ||||
| 	result := Median(t1, t2, t3, t4) | ||||
|  | ||||
| 	if !result.Equal(expected) { | ||||
| 		t.Errorf("Expected %v but got %v", expected, result) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestMedian_UnsortedValues(t *testing.T) { | ||||
| 	t1 := time.Date(2022, 1, 5, 0, 0, 0, 0, time.UTC) | ||||
| 	t2 := time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC) | ||||
| 	t3 := time.Date(2022, 1, 3, 0, 0, 0, 0, time.UTC) | ||||
|  | ||||
| 	// Median should correctly sort values first | ||||
| 	expected := t3 | ||||
| 	result := Median(t1, t2, t3) | ||||
|  | ||||
| 	if !result.Equal(expected) { | ||||
| 		t.Errorf("Expected %v but got %v", expected, result) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestMedian_EmptySlice(t *testing.T) { | ||||
| 	result := Median() | ||||
| 	expected := time.Time{} | ||||
|  | ||||
| 	if !result.Equal(expected) { | ||||
| 		t.Errorf("Expected zero time but got %v", result) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestTimeToDatePart(t *testing.T) { | ||||
| 	tz := TimezoneBerlin | ||||
| 	tm := time.Date(2022, 1, 1, 13, 14, 15, 0, tz) | ||||
| 	expected := time.Date(2022, 1, 1, 0, 0, 0, 0, tz) | ||||
| 	result := TimeToDatePart(tm, tz) | ||||
| 	if !result.Equal(expected) { | ||||
| 		t.Errorf("Expected %v but got %v", expected, result) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestTimeToWeekStart(t *testing.T) { | ||||
| 	tz := TimezoneBerlin | ||||
| 	// January 5, 2022 was a Wednesday | ||||
| 	tm := time.Date(2022, 1, 5, 13, 14, 15, 0, tz) | ||||
| 	// Should return Monday, January 3, 2022 | ||||
| 	expected := time.Date(2022, 1, 3, 0, 0, 0, 0, tz) | ||||
| 	result := TimeToWeekStart(tm, tz) | ||||
| 	if !result.Equal(expected) { | ||||
| 		t.Errorf("Expected %v but got %v", expected, result) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestTimeToWeekStart_WhenMonday(t *testing.T) { | ||||
| 	tz := TimezoneBerlin | ||||
| 	// January 3, 2022 was a Monday | ||||
| 	tm := time.Date(2022, 1, 3, 13, 14, 15, 0, tz) | ||||
| 	expected := time.Date(2022, 1, 3, 0, 0, 0, 0, tz) | ||||
| 	result := TimeToWeekStart(tm, tz) | ||||
| 	if !result.Equal(expected) { | ||||
| 		t.Errorf("Expected %v but got %v", expected, result) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestTimeToMonthStart(t *testing.T) { | ||||
| 	tz := TimezoneBerlin | ||||
| 	tm := time.Date(2022, 1, 15, 13, 14, 15, 0, tz) | ||||
| 	expected := time.Date(2022, 1, 1, 0, 0, 0, 0, tz) | ||||
| 	result := TimeToMonthStart(tm, tz) | ||||
| 	if !result.Equal(expected) { | ||||
| 		t.Errorf("Expected %v but got %v", expected, result) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestTimeToMonthEnd(t *testing.T) { | ||||
| 	tz := TimezoneBerlin | ||||
| 	tm := time.Date(2022, 1, 15, 13, 14, 15, 0, tz) | ||||
| 	expected := time.Date(2022, 2, 1, 0, 0, 0, 0, tz).Add(-1) | ||||
| 	result := TimeToMonthEnd(tm, tz) | ||||
| 	if !result.Equal(expected) { | ||||
| 		t.Errorf("Expected %v but got %v", expected, result) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestTimeToYearStart(t *testing.T) { | ||||
| 	tz := TimezoneBerlin | ||||
| 	tm := time.Date(2022, 5, 15, 13, 14, 15, 0, tz) | ||||
| 	expected := time.Date(2022, 1, 1, 0, 0, 0, 0, tz) | ||||
| 	result := TimeToYearStart(tm, tz) | ||||
| 	if !result.Equal(expected) { | ||||
| 		t.Errorf("Expected %v but got %v", expected, result) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestTimeToYearEnd(t *testing.T) { | ||||
| 	tz := TimezoneBerlin | ||||
| 	tm := time.Date(2022, 5, 15, 13, 14, 15, 0, tz) | ||||
| 	expected := time.Date(2023, 1, 1, 0, 0, 0, 0, tz).Add(-1) | ||||
| 	result := TimeToYearEnd(tm, tz) | ||||
| 	if !result.Equal(expected) { | ||||
| 		t.Errorf("Expected %v but got %v", expected, result) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestTimeToNextYearStart(t *testing.T) { | ||||
| 	tz := TimezoneBerlin | ||||
| 	tm := time.Date(2022, 5, 15, 13, 14, 15, 0, tz) | ||||
| 	expected := time.Date(2023, 1, 1, 0, 0, 0, 0, tz) | ||||
| 	result := TimeToNextYearStart(tm, tz) | ||||
| 	if !result.Equal(expected) { | ||||
| 		t.Errorf("Expected %v but got %v", expected, result) | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user