Ruby date


#1

I searched a lot but confused .

how can i check if a string is date or not in ruby filter ?


(Magnus Bäck) #2

Your question would be easier to answer with more context. Why do you need to check in a ruby filter if a string contains a date?


#3

because i am splitting a string like this
f1=2015-08-09@f2=45@f3=alice

and then converting thier values accordingly do their data types .

like
"f1":2015-08-09, //date
"f2":45, //integer
"f3":"alice" //text


(Magnus Bäck) #4

And you can't use the date filter because you don't know all possible names of the date fields?

I'd try to parse the date and catch any parse exception so that I can fall back to e.g. a string. Are you going to perform date arithmetic on the parsed date, or why do you need a Date object?


#5

I need date object because I would perform range query on date .
And yes i don't know the date field name because i am extracting it from a string which can contain anything .

can you please suggest how to catch exception in ruby ,so that if its not a date it will give me the string as it is ?


(Magnus Bäck) #6

I need date object because I would perform range query on date .

What, inside the Ruby filter?

can you please suggest how to catch exception in ruby ,so that if its not a date it will give me the string as it is ?

I'm not fluent in Ruby myself but I'm sure there are many Ruby tutorials and other online documents that explain the syntax and semantics of Ruby's exception handling.


#7

Its ok magnus ! Thanks anyway


(system) #8