Re: [Rails] Re: Retrieve duration (in string format) from database and convert to Ruby syntax for calculation

2013-09-21 Thread Norm Scherer
But not all months are 2592000 seconds long.some are shorter and some are longer If you have a Date of 1 Jan and add 1.month to it you will get 1 Feb which is 31 days later. If you have 1 Feb and you add 1.month you will get 1 Mar which is 28 or 29 days later. You could just store

[Rails] Re: Retrieve duration (in string format) from database and convert to Ruby syntax for calculation

2013-09-20 Thread Raj Kumar
btw you can do it using eval like eval(1.month) On Friday, 20 September 2013 03:30:16 UTC-4, Fai Wong wrote: If I store 1.month as a string in the database, how do I convert 1.month into 1.month? This way I can use the 1.month value stored in database to perform the following calculation.

[Rails] Re: Retrieve duration (in string format) from database and convert to Ruby syntax for calculation

2013-09-20 Thread Raj Kumar
I don't think this is good idea. 1.month.to_i will return in seconds as 2592000. you can store this and while fetching you can use it as it is Time.now + 2592000 On Friday, 20 September 2013 03:30:16 UTC-4, Fai Wong wrote: If I store 1.month as a string in the database, how do I convert

[Rails] Re: Retrieve duration (in string format) from database and convert to Ruby syntax for calculation

2013-09-20 Thread Eric Hayes
Take a look at this gem: https://github.com/peleteiro/ruby-duration —it will convert an arbitrary duration (like 1 month, 2 weeks, etc.) into seconds which can be stored in the DB. It is very similar to what Raj is recommending, just a little more formal. Either way you can avoid eval'ing code,