Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion failure when a text field start with a date or datetime #410

Open
fernandomm opened this issue Oct 28, 2021 · 0 comments
Open

Comments

@fernandomm
Copy link

When LHS is used to access a text attribute that starts with a date or datetime, it converts the initial date ignoring everything else.

Sample json:

[
  {
    "id": 1,
    "text": "2021-10-28 Sample message."
  }
]

Accessing text attribute returns a date and not an string:

[1] > ticket = Ticket.where(id: 1)
=> Ticket 47342870532040
{:id=>1, :text=>"2021-10-28 Sample message."}
[2] > ticket.first.text
=> Thu, 28 Oct 2021

The issue seems to be caused by the regex in:

/(?<date>\d{4}-\d{2}-\d{2})?(?<time>T\d{2}:\d{2}(:\d{2}(\.\d*.\d{2}:\d{2})*)?)?/

Limiting it with \A and \z seems to fix the problem without any side effects:

def date_time_regex
  /\A(?<date>\d{4}-\d{2}-\d{2})?(?<time>T\d{2}:\d{2}(:\d{2}(\.\d*.\d{2}:\d{2})*)?)?\z/
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant