Using chronic dates phrases

2 views
Skip to first unread message

Karl

unread,
Dec 2, 2009, 3:16:12 PM12/2/09
to pickle
I would like to set date values on a model via pickle using relative
terms like "yesterday", "today", or "two days ago".

For example:

Given a user exists with username: "karl", signup_date: "yesterday"

I tried using transforms in combination with the Chronic gem(http://
chronic.rubyforge.org/), but it does not look like the transform gets
picked up. Is this the right way to go?

thx.

-karl

Ian White

unread,
Dec 2, 2009, 6:19:16 PM12/2/09
to pickle-...@googlegroups.com
Sounds like a good idea. Could you post your transform code, and a
scenario, so that I can take a look?
> --
>
> You received this message because you are subscribed to the Google
> Groups "pickle" group.
> To post to this group, send email to pickle-...@googlegroups.com.
> To unsubscribe from this group, send email to pickle-cucumb...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/pickle-cucumber?hl=en
> .
>
>

Karl Baum

unread,
Dec 2, 2009, 6:37:58 PM12/2/09
to pickle-...@googlegroups.com
Sure.. I tried something very basic to begin with just to see if it was
possible.

Transform /1 day ago/ do |step_arg|
Date.yesterday
End

Obviously we would make that more generic but I just wanted to see if the
transform could be used.

And then the step.

Given 20 promo_messages exist with date: "1 day ago"

Thanks!

-karl

tomtt

unread,
Dec 15, 2009, 7:32:48 AM12/15/09
to pickle
Hi Ian & co,

I have also been trying to allow pickle to understand time formats.

The best way to do it - methinks - is to hook into the cucumber
transforms. So I have the following transform:

Transform /^(\d+) (second|minute|hour|day|week|fortnight|year)s? (from
[_ ]now|ago)$/ do |number, unit, time_arrow|
number.to_i.send(unit).send(time_arrow.tr(' ', '_'))
end

And then all we need is for pickle to apply the transforms to it's
matched values...

I got it to work by hacking into pickle's Parser::parse_field method.
Since I considered this just a spike, I have not written any specs for
it yet. The ugliest part of the code is getting a hold of the cucumber
language set which is where the transforms live. Before submitting a
real patch, I will write a cucumber patch that will provide a better
way of getting hold of this. So please ignore the resulting ugliness,
it will be engineered away.

I was hoping you could put an eyeball on the code and if you can think
of any issues with this.

http://github.com/tomtt/pickle/tree/apply_transforms

Running garlic there were no failing specs, but they did not pass due
to lack of coverage.

Cheers, Tom.

-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Tom ten Thij
Unboxed Consulting, http://unboxedconsulting.com
T: +44 20 3137 2943 F: +44 20 7183 4251
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~

Ian White

unread,
Dec 15, 2009, 7:40:48 AM12/15/09
to pickle-...@googlegroups.com
Hi Tom,

Thanks for your work on this. I'll check it out soon.

Allowing the 'innids' of a field string to be parsed for partials is
an excellent idea actually, and can be used for loads of applications
I reckon.

Cheers,
Ian
Reply all
Reply to author
Forward
0 new messages