Coder Social home page Coder Social logo

Date parsing? about freddy HOT 11 CLOSED

bignerdranch avatar bignerdranch commented on August 11, 2024
Date parsing?

from freddy.

Comments (11)

zwaldowski avatar zwaldowski commented on August 11, 2024

A pull request would be welcome! I don't personally think it's out of scope, but we didn't want to be too opinionated about it yet.

Further parsing can be built as a composition out of the string family of methods, for instance:

let formatter = ...
self.dateOfBirth = try json.string("some", "key", "path", ifNotFound: true).flatMap(formatter.dateFromString)

That obviously leaves something to be desired (error handling, for one). I envisioned a ValueTransformer<In, Out> as a case-by-case alternative to everything needing to be JSONDecodable.

from freddy.

getaaron avatar getaaron commented on August 11, 2024

I can open a PR for consideration. Any thoughts on special date formats we'd like to support? At a minimum, I think it'd be nice to support two common Ruby date formats ("yyyy-MM-dd'T'HH:mm:ss.SSSZZZZ" and "YYYY-MM-DD HH:mm:ss ZZZ")

from freddy.

zwaldowski avatar zwaldowski commented on August 11, 2024

I personally think magical support for a specific format would be more confusing than opt-in support, but I won't say we wouldn't consider it.

from freddy.

justin avatar justin commented on August 11, 2024

All the dates in our REST APIs conform to ISO8601. I feel like that's somewhat standard, but i wouldn't lose sleep if i had to pass in a format string to adopt it.

from freddy.

jgallagher avatar jgallagher commented on August 11, 2024

All the dates in our REST APIs conform to ISO8601. I feel like that's somewhat standard, but i wouldn't lose sleep if i had to pass in a format string to adopt it.

I would be sooooooo happy if I had that experience. Unfortunately we see all kinds of date formats in practice, including some that can't be parsed by NSDateFormatter (e.g., search for "DateTime Wire Format" for .NET 4.5). Given that, I'm not sure even a format string is an ideal solution. :-/ This is where the desire for value transformers is coming from, FWIW.

from freddy.

ratkins avatar ratkins commented on August 11, 2024

We just came up with the need to turn http://example.com/foo.jpg into an NSURL-typed property on our model object, and would also like either this special-cased or some kind of value transformer as mentioned above.

from freddy.

jgallagher avatar jgallagher commented on August 11, 2024

For URLs, there isn't much transformation needed. Can you make NSURL conform to JSONDecodable in your project?

from freddy.

ratkins avatar ratkins commented on August 11, 2024

We can without too much trouble, sure. I have a side-question on doing that though: when turning NSURL's failable initialiser into one that throws we thought using Freddy.JSON.Error. ValueNotConvertible would be the appropriate error but I wasn't sure what to give for the value parameter?

from freddy.

jgallagher avatar jgallagher commented on August 11, 2024

That's up to you and how you're handling/reporting errors. I'd put in the string that failed to convert. You could also define your own error case that doesn't have an associated value.

from freddy.

alcarvalho avatar alcarvalho commented on August 11, 2024

@ratkins were you able to conform NSURL to JSONDecodable by using its failable initializer? I couldn't get it done myself.

from freddy.

zwaldowski avatar zwaldowski commented on August 11, 2024

Closing due to inactivity. Given the advent of Codable, Freddy is in maintenance mode and only considering bug fixes at this time.

from freddy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.