From 4797489685bc18d17b0eede6ef0d0c99755e2963 Mon Sep 17 00:00:00 2001 From: Nicolaj Nielsen Date: Sun, 17 Sep 2023 09:28:43 +0200 Subject: [PATCH] Support datetime format with dot separator --- nfp.go | 7 +++++++ nfp_test.go | 3 +++ 2 files changed, 10 insertions(+) diff --git a/nfp.go b/nfp.go index ba3b020..8d83e7f 100644 --- a/nfp.go +++ b/nfp.go @@ -400,6 +400,13 @@ func (ps *Parser) getTokens() Tokens { ps.Offset++ continue } + if ps.Token.TType == TokenTypeDateTimes && !strings.ContainsAny(NumCodeChars, ps.nextChar()) { + ps.Tokens.add(ps.Token.TValue, ps.Token.TType, ps.Token.Parts) + ps.Tokens.add(ps.currentChar(), TokenTypeLiteral, ps.Token.Parts) + ps.Token = Token{} + ps.Offset++ + continue + } if !ps.InString { if ps.Token.TType != "" && strings.ContainsAny(NumCodeChars, ps.nextChar()) { ps.Tokens.add(ps.Token.TValue, ps.Token.TType, ps.Token.Parts) diff --git a/nfp_test.go b/nfp_test.go index 2cbe017..1460e07 100644 --- a/nfp_test.go +++ b/nfp_test.go @@ -223,6 +223,9 @@ var testStrings [][]string = [][]string{ {`DD/MM/YY;@`, "[{Positive [{DD DateTimes []} {/ Literal []} {MM DateTimes []} {/ Literal []} {YY DateTimes []}]} {Text [{@ TextPlaceHolder []}]}]"}, {`DD/MM/YYYY`, "[{Positive [{DD DateTimes []} {/ Literal []} {MM DateTimes []} {/ Literal []} {YYYY DateTimes []}]}]"}, {`DD/MM/YYYY;@`, "[{Positive [{DD DateTimes []} {/ Literal []} {MM DateTimes []} {/ Literal []} {YYYY DateTimes []}]} {Text [{@ TextPlaceHolder []}]}]"}, + {`DD.MM.YY;@`, "[{Positive [{DD DateTimes []} {. Literal []} {MM DateTimes []} {. Literal []} {YY DateTimes []}]} {Text [{@ TextPlaceHolder []}]}]"}, + {`DD.MM.YYYY`, "[{Positive [{DD DateTimes []} {. Literal []} {MM DateTimes []} {. Literal []} {YYYY DateTimes []}]}]"}, + {`DD.MM.YYYY;@`, "[{Positive [{DD DateTimes []} {. Literal []} {MM DateTimes []} {. Literal []} {YYYY DateTimes []}]} {Text [{@ TextPlaceHolder []}]}]"}, {`DDD`, "[{Positive [{DDD DateTimes []}]}]"}, {`DDDD`, "[{Positive [{DDDD DateTimes []}]}]"}, {`DDDD", "MMMM\ DD", "YYYY`, "[{Positive [{DDDD DateTimes []} {, Literal []} {MMMM DateTimes []} { Literal []} {DD DateTimes []} {, Literal []} {YYYY DateTimes []}]}]"},