birl icon indicating copy to clipboard operation
birl copied to clipboard

Issue parsing sqlite timestamps

Open ross-byrne opened this issue 11 months ago • 1 comments

Hello! I was testing out the package (version 1.8.0) when I noticed there is an issue parsing timestamps that are created in sqlite3.

See the following code snippet for details

  let time1 = "2025-01-16 13:20:19" // default format for sqlite timestamps `current_timestamp`
  let time2 = "2025-01-16T13:20:19.502Z" // correctly formatted iso6801 string

  let assert Ok(v1) = birl.parse(time1)
  io.debug(birl.to_iso8601(v1))
  // "2025-01-01T00:00:00.000-01:06"

  let assert Ok(v2) = birl.parse(time2)
  io.debug(birl.to_iso8601(v2))
  // "2025-01-16T13:20:19.502Z"

As you can see, parsing a timestamp in "2025-01-16 13:20:19" format results in an Ok result but the date and time are wrong. I would expect this parse to fail and return an error result.

ross-byrne avatar Jan 16 '25 16:01 ross-byrne

Also facing similar issue. (Possible duplicate of #38)

I looked at codebase, and saw that it's trying to parse string and individually deriving the components of time. How about providing a wrapper around strptime for parsing, and maybe similar strftime for formatting. It has been around for quite sometime, and is prevalent in other ecosystem as well.

Ref:

I can probably try a PoC PR on this, but wanted to know your thoughts on it @massivefermion ?

Quick googling around did highlight the fact that the C implementation of these utility depends on machine

HandOfGod94 avatar Jan 17 '25 21:01 HandOfGod94