Use JSON date serializer

Effective API changes:

  - nil serializes to null, not empty string
  - dates serialize to IETF RFC 3339 with millisecond precision, not
    second precision surrounded by spaces
This commit is contained in:
Andrew Kvalheim 2022-09-28 09:34:01 -07:00
parent b60257ef59
commit 397341a324
4 changed files with 8 additions and 15 deletions

View file

@ -3,12 +3,8 @@
class EventScheduleSerializer < ActiveModel::Serializer
include ActionView::Helpers::TextHelper
attributes :date, :room
def date
t = object.start_time
t.blank? ? '' : %( #{I18n.l t, format: :short}#{t.formatted_offset(false)} )
end
attribute :start_time, key: :date
attributes :room
def room
object.room.guid

View file

@ -3,12 +3,9 @@
class EventSerializer < ActiveModel::Serializer
include ActionView::Helpers::TextHelper
attributes :guid, :title, :length, :scheduled_date, :language, :abstract, :speaker_ids, :type, :room, :track
def scheduled_date
t = object.time
t.blank? ? '' : %( #{I18n.l t, format: :short}#{t.formatted_offset(false)} )
end
attributes :guid, :title, :length
attribute :time, key: :scheduled_date
attributes :language, :abstract, :speaker_ids, :type, :room, :track
def speaker_ids
speakers = object.event_users.select { |i| i.event_role == 'speaker' }