# TOML.parsefile error on reading date formatted variable

**URL:** <https://discourse.julialang.org/t/toml-parsefile-error-on-reading-date-formatted-variable/59681>\
**Category:** New to Julia\
**Created:** [April 20, 2021, 5:24pm UTC](https://discourse.julialang.org/t/toml-parsefile-error-on-reading-date-formatted-variable/59681 "2021-04-20T17:24:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mocalvao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mocalvao/32/19318_2.png) [@mocalvao](https://discourse.julialang.org/u/mocalvao)\
**Post date:** [April 20, 2021, 5:24pm UTC](https://discourse.julialang.org/t/toml-parsefile-error-on-reading-date-formatted-variable/59681/1 "2021-04-20T17:24:56Z")

</div>

I have the test.toml file, containing the single line:

```julia
period = 2021-04-20 # should be formatted as YYYY-MM-DD

```

When I try to parse it via:

```julia
julia> using TOML
julia> TOML.parsefile("test.toml")

```

the following error arises:

```julia
ERROR: TOML Parser error:
/home/orca/Dropbox/work/study/computing/Julia/sandbox/test.toml:1:21 error: expected newline after key value pair
  period = 2021-04-20 # should be of type Date 
                      ^                         
Stacktrace:
 [1] parse
   @ ./toml_parser.jl:441 [inlined]
 [2] parsefile(f::String)
   @ TOML /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/TOML/src/TOML.jl:43
 [3] top-level scope
   @ REPL[2]:1

```

If I delete the comment: `# should be formatted as YYYY-MM-DD` in the original test.toml file, it is correctly parsed:

```julia
julia> TOML.parsefile("test.toml")
Dict{String, Any} with 1 entry:
  "period" => Date("2021-04-20")

```

How can I use an end of line comment in the .toml file for a field formatted like period? In principle, I would like to keep the comment, in the same line, to help the user input correctly the value for the variable `period`. Of course, there are two ways around this, which I’d rather not use:  
(1) move the comment to a line by itself, right before the line declaring `period`,  
(2) not using any comment at all.

Cheers

---

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [February 25, 2023, 7:40pm UTC](https://discourse.julialang.org/t/toml-parsefile-error-on-reading-date-formatted-variable/59681/2 "2023-02-25T19:40:20Z")

</div>

> [@mocalvao](#):
>
> In principle, I would like to keep the comment, in the same line, to help the user input correctly the value for the variable `period`.

Beside option (1) you can incorporate the format in the section header, here my code snippet:

```julia
import TOML
const PERIOD_LABEL = "Period, YYYY-MM-DD"
input_toml_file = "/media/stefan/DATA/data/temp/period.toml"

period_in = Dict(PERIOD_LABEL => Dict("period" => "2021-04-20"))

open(input_toml_file, "w") do io
    println(io, "# --- A nice Title ----------------------------------------------")
    println(io, "# --- Some instructions ... 📅")
    TOML.print(io, period_in)
end

# --- read back:
@show period_out = TOML.tryparsefile(input_toml_file)
@show period_out[PERIOD_LABEL]
@show period_out[PERIOD_LABEL]["period"]

```

P.S.:  
I found the function `TOML.parsefile()` a little bit unreliable, therefore I prefer `TOML.tryparsefile()`
