Giter Club home page Giter Club logo

Comments (4)

jeremyw avatar jeremyw commented on August 16, 2024

I think that would be an amazing feature! A couple people have asked me if stamp can do it.

But like you said, it's not something that strftime does. Right now, stamp just transforms natural (human) formats into strftime directives and doesn't add any of its own features. I don't think there's a good reason not to break new ground, it just hasn't happened yet!

Actually, a small example of a place I did this is in handling "am/pm" in Ruby 1.8.7 because it doesn't support the %P directive, but that was much more trivial than this proposal.

As far as implementing this, I'd start by adding specs to the Cucumber feature for every scenario you can think of that represents significant behavior. Off the top of my head, I'd write spec for 1st, 2nd, 3rd, 4th, 5th, 6th, 7th, 8th, 9th, 10th, 11th, 12th, 21st, 22nd, 23rd. Note the inconsistencies with 1s and 2s in the teen range... tricky. I found the scenario outlines in Cucumber made it really easy to implement stamp and refactor it later, and they provide a good set of usage examples.

Once you have specs you're happy with, you just need an infinite number of monkeys and infinite time to make the specs pass! Or, figure out a good strategy for spotting ordinal patterns and translating to an appropriate token based on the value.

If it simplifies things I think you can scope the feature to "day" values. I can't think of a good case for "12th month" or "2011th year"... maybe "22nd week of the year" could be useful, but that's so rarely used I'd just focus on making it work for day of month. So you might start with something like the OBVIOUS_DAYS range, but a regular expression to detect ORDINAL_DAYS.

I'm not a regexp ninja myself. I lean heavily on http://rubular.com/. After some quick testing, I think /(\d{1,2})(st|nd|rd|th)/ might work well. This captures 1 or 2 digits followed by "st", "nd", "rd", or "th".

I hope this helps and gives you some ideas. Do you have any local hackfests you can go to, if you need some help? I'm otherwise happy to give you feedback on a work in progress.

PS: An interesting next step of this might be to translate "On the Thirteenth of March" to e.g. "On the Fifth of November". But again, not a common use case.

from stamp.

jeremyw avatar jeremyw commented on August 16, 2024

This might be useful: https://github.com/imathis/octopress/blob/master/plugins/date.rb#L19-30

from stamp.

chrisledet avatar chrisledet commented on August 16, 2024

Thanks Jeremy. Definitely look into the suggestions. I think that snippet will be useful. I'll try this another shot in the next few days.

from stamp.

jeremyw avatar jeremyw commented on August 16, 2024

This was released with version 0.2.0. Thanks!

from stamp.

Related Issues (16)

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.