-
Notifications
You must be signed in to change notification settings - Fork 137
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
Custom Formats for DateTime support #212
Comments
Same here! Adding myself to the loop! |
Try this: property :created_at, exec_context: :decorator
def created_at; super.to_s; end |
Thanks for the input, @apotonick. I'm trying to change the format for Thanks for your time and effort in setting up this gem and maintaining it! |
@nlsrchtr Rendering or parsing? |
The idea was to have it both way. Currently I found a workaround, by changing the params before they hit the stack and changing: module ActiveSupport
class TimeWithZone
def as_json(options = nil)
if ActiveSupport::JSON::Encoding.use_standard_json_time_format
xmlschema
else
time.strftime("%s%L").to_i
end
end
def to_json(*args)
as_json.to_json(*args)
end
end
end It works, but feels way too hacky... |
I want to vomit! 🤢 Can I see your representer class? |
🤣 The requirement is, that it should be possible to switch between "UNIX epoch format" and ISO8601 on a request base (based on some header attribute). The call is also pretty plain and simple with: API::V1::Me::UnitBookingRepresenter.new(current_user.unit_bookings.new).from_json(permitted_params.to_json) The representer class looks like this require "roar/json/json_api"
module API
module V1
module Me
class UnitBookingRepresenter < Roar::Decorator
include Roar::JSON::JSONAPI.resource :unit_bookings
attributes do
property :unit_id
[...]
property :starts_at
property :ends_at
end
end
end
end
end Thanks for your time and effort! |
On a sidenote: You don't need |
Hm, this is a |
Hi,
It doesn't seem possible to represent timestamp properties in certain (or default) format.
Steps to reproduce
config/initializers/date_format.rb
It converts timestamp to proper format:
app/representers/song_representer.rb
Actual behavior
Anyway, it renders not expected output:
Please, help me understand if it's a bug or find a way to achieve expected result.
System configuration
Roar version: 1.1.0
The text was updated successfully, but these errors were encountered: