The existing DateFormat structure is perfectly happy to represent additional subsecond characters beyond the millisecond.
julia> d=dateformat"yyyy-mm-ddTHH:MM:SS.sssssssss"
dateformat"yyyy-mm-ddTHH:MM:SS.sssssssss"
julia> d.tokens
(DatePart(yyyy), Delim(-), DatePart(mm), Delim(-), DatePart(dd), Delim(T), DatePart(HH), Delim(:), DatePart(MM), Delim(:), DatePart(SS), Delim(.), DatePart(sssssssss))
And even still works (with a DateTime compatible string)
julia> DateTime("2020-05-03T12:59:58.123",dateformat"yyyy-mm-ddTHH:MM:SS.sssssssss")
2020-05-03T12:59:58.123
An error isn’t thrown until you actually go to use this format on a string with more than 3 digits after the decimal point. An error is thrown here.
julia> DateTime("2020-05-03T12:59:58.1234",dateformat"yyyy-mm-ddTHH:MM:SS.sssssssss")
ERROR: InexactError: convert(Dates.Decimal3, 1234)
Stacktrace:
[1] tryparsenext
@ C:\Users\jcluts\scoop\apps\julia\current\share\julia\stdlib\v1.7\Dates\src\io.jl:153 [inlined]
[2] tryparsenext
@ C:\Users\jcluts\scoop\apps\julia\current\share\julia\stdlib\v1.7\Dates\src\io.jl:41 [inlined]
[3] macro expansion
@ C:\Users\jcluts\scoop\apps\julia\current\share\julia\stdlib\v1.7\Dates\src\parse.jl:64 [inlined]
[4] tryparsenext_core(str::String, pos::Int64, len::Int64, df::DateFormat{Symbol("yyyy-mm-ddTHH:MM:SS.ssss"), Tuple{Dates.DatePart{'y'}, Dates.Delim{Char, 1}, Dates.DatePart{'m'}, Dates.Delim{Char, 1}, Dates.DatePart{'d'}, Dates.Delim{Char, 1}, Dates.DatePart{'H'}, Dates.Delim{Char, 1}, Dates.DatePart{'M'}, Dates.Delim{Char, 1}, Dates.DatePart{'S'}, Dates.Delim{Char, 1}, Dates.DatePart{'s'}}}, raise::Bool)
@ Dates C:\Users\jcluts\scoop\apps\julia\current\share\julia\stdlib\v1.7\Dates\src\parse.jl:38
[5] macro expansion
@ C:\Users\jcluts\scoop\apps\julia\current\share\julia\stdlib\v1.7\Dates\src\parse.jl:150 [inlined]
[6] tryparsenext_internal
@ C:\Users\jcluts\scoop\apps\julia\current\share\julia\stdlib\v1.7\Dates\src\parse.jl:125 [inlined]
[7] parse(::Type{DateTime}, str::String, df::DateFormat{Symbol("yyyy-mm-ddTHH:MM:SS.ssss"), Tuple{Dates.DatePart{'y'}, Dates.Delim{Char, 1}, Dates.DatePart{'m'}, Dates.Delim{Char, 1}, Dates.DatePart{'d'}, Dates.Delim{Char, 1}, Dates.DatePart{'H'}, Dates.Delim{Char, 1}, Dates.DatePart{'M'}, Dates.Delim{Char, 1}, Dates.DatePart{'S'}, Dates.Delim{Char, 1}, Dates.DatePart{'s'}}})
@ Dates C:\Users\jcluts\scoop\apps\julia\current\share\julia\stdlib\v1.7\Dates\src\parse.jl:282
[8] DateTime(dt::String, df::DateFormat{Symbol("yyyy-mm-ddTHH:MM:SS.ssss"), Tuple{Dates.DatePart{'y'}, Dates.Delim{Char, 1}, Dates.DatePart{'m'}, Dates.Delim{Char, 1}, Dates.DatePart{'d'}, Dates.Delim{Char, 1}, Dates.DatePart{'H'}, Dates.Delim{Char, 1}, Dates.DatePart{'M'}, Dates.Delim{Char, 1}, Dates.DatePart{'S'}, Dates.Delim{Char, 1}, Dates.DatePart{'s'}}})
@ Dates C:\Users\jcluts\scoop\apps\julia\current\share\julia\stdlib\v1.7\Dates\src\io.jl:576
[9] top-level scope
@ REPL[23]:1
It may be possible to not need a new “nanodateformat” structure and only modify some of the parsing functions and use a lot of the Dates existing machinery.