hello : help
work sql
type
Date* = ref object of RootObj
Data* : DateTime
Null* : bool
Temps* = ref object of RootObj
Data* : DateTime
Null* : bool
proc sql*(a: Date): string =
if a.Data.format("yyyy-MM-dd") == "0001-01-01" and a.Null == true : return "null"
else : return fmt""" "{a.Data.format("yyyy-MM-dd")}" """
proc sql*(a: Temps): string =
if a.Data.format("HH:mm:ss") == "00:00:00" and a.Null == true : return "null"
else :
return fmt""" "{a.Data.format("HH:mm:ss")}" """
a.Data =parse("20:10:05","HH:mm:ss")
: return fmt""" "{a.Data.format("HH:mm:ss")}" """
/home/soleil/.choosenim/toolchains/nim-1.0.6/lib/pure/strformat.nim(562, 18) &
/home/soleil/NIMGUI/GUISQL/var.nim(105, 15) Error: could not parse `a.Data.format("HH`.
/home/soleil/.choosenim/toolchains/nim-1.0.6/lib/core/macros.nim(557, 15) Error: closing " expected
is good DATE
: return fmt""" "{a.Data.format("yyyy-MM-dd")}" """ = "2020-03-18"
other
sql*(a: Temps): string =
if a.Data.format("HH:mm:ss") == "00:00:00" and a.Null == true : return "null"
else :
var h : string = a.Data.format("HH:mm:ss")
return fmt""" "{h}" """
this a.Data =parse("20:10:05","HH:mm:ss")
can you explain to me why please
I think the problem is that the strformat's fmt macro is not good enough to realize that date format is not part of it's format. So it gets confused. That is why you get the error:
: could not parse `a.Data.format("HH`.
I recommend doing what you already done:
""" "{h}" """
Format your date into a string variable, include the string in your final format.