Comments (4)
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.
This might be useful: https://github.com/imathis/octopress/blob/master/plugins/date.rb#L19-30
from stamp.
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.
This was released with version 0.2.0. Thanks!
from stamp.
Related Issues (16)
- include Stamp not InstanceMethods HOT 1
- Support CPAN/Time::Format-style directives HOT 4
- Alias #stamp method HOT 4
- "pm" doesn't work on 1.8.7/REE
- Add support for Rails i18n date/time formats HOT 1
- Idea: Suppress leading space for, e.g., "3:00pm" ? HOT 5
- Wrong dates for November HOT 6
- Problem with timezones in Rails HOT 3
- Wrong Date Presented HOT 7
- Drop support for Ruby 1.8.7 HOT 4
- Strange output when using #stamp("29/01/2013") HOT 10
- Change "meridian" to "meridiem"
- Time Zone Support Broken HOT 8
- implement templates with Temple
- Disambiguator doesn't sit within the Stamp module, polluting global namespace HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stamp.