Ruby On Rails : local_time gem : I dont want it to wrap date with <time> tag

806 views Asked by At

I have been using local_time to convert servertime to client local time. However now I am using datatables and to sort date/time columns. I have to use date-moment.js plugin of Datatables which uses moment.js to handle date conversions.

My problem is: the local_time's view helper is wrapping the date with < time > tag like this

<time data-format="%B %e, %Y %l:%M%P"
      data-local="time"
      datetime="2013-11-27T23:43:22Z"
      title="November 27, 2013 6:43pm EDT"
      data-localized="true">November 27, 2013 6:43pm</time>

The wrapping thing is creating problem for moment.js to get the actual date-time as it expects. I need it to convert the date-time but not wrap with <time> tag. Is it possible. If yes How?

1

There are 1 answers

0
Shiva On BEST ANSWER

currently created a helper method to extract the core date from the string returned by the gem's local_date method
in views/

<%= extract_date(local_date(workflow.created_at, CommonConstants::DATE_FORMAT_LONG)) %>

  # Parse the string generated by local_time gem
  # Expectation :
  #   "<time data-format=\"%B %e, %Y\" data-local=\"time\" datetime=\"2015-10-28T11:19:54Z\">October 28, 2015</time>"
  def extract_date(date_string)
    date_string.split('>').pop.split('</')[0] rescue ''
  end