Skip to content

Encode Time objects as ISO8601 for compatibility with JS's Date.parse() #721

Closed
@paddor

Description

@paddor

I've read about the recent performance gains in this gem. Congratulations!

It's nothing urgent but eventually I'd love to switch from Oj to this gem. Currently I can't do that because Time objects are not encoded as ISO8601, which is what Javascript's Date.parse() expects.

Specifically, I've been using these Oj options:

        OJ_OPTIONS = {
          mode:             :custom,
          symbol_keys:      true,
          time_format:      :xmlschema, # ISO 8601, compatible with JavaScript's Date.parse()
          allow_gc:         false,
          second_precision: 3,
          cache_keys:       true,
          cache_str:        35

          # NOTE: MUST NOT use use_to_json. Because some gem requires 'json' (and also the specs), Time#to_json gets defined
          #       and will be used by Oj. It's not ISO8601.
          # use_to_json:      true,
        }

Would it be possible to add options time_format: :xmlschema and second_precision: N to JSON.generate?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions