Nik
2008-Jul-29 19:06 UTC
Creating a custom function that can be called from an instance variable.
Hello all, I have a whole bunch of time stamps which I need to display in fractional hours or fractional days as the case may be. Is there any chance I could do something like this: <<controller>> def HourDisp ... end @time = 12:30:00 -------------------------------------- <<view>> <%= @time.HourDisp %> --------------------------------------- Shows: 12.5 Thank You very much@ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nik
2008-Aug-01 13:22 UTC
Re: Creating a custom function that can be called from an instance variable.
So:
#t in hh:mm:ss format
def HourDisp(t)
#t gets split in three parts hh,mm, and ss
new_t = t.split('':'')
h=new_t[0] + new_t[1]/60 + new_t[2]/3600
return h
end
<<view>>
<%= HourDisp(12:30:00) %>
#12.5
Thank You So Much Philip!
On Jul 29, 9:24 pm, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org>
wrote:> On Jul 29, 2008, at 12:06 PM,Nikwrote:
>
>
>
>
>
> > Hello all,
>
> > I have a whole bunch of time stamps which I need to display in
> > fractional hours or fractional days as the case may be.
>
> > Is there any chance I could do something like this:
> > <<controller>>
> > def HourDisp
> > ...
> > end
> > @time = 12:30:00
> > --------------------------------------
> > <<view>>
> > <%= @time.HourDisp %>
> > ---------------------------------------
> > Shows:
> > 12.5
>
> Nik-
>
> Create a helper method named say "time_as_fraction" and pass your
time
> into it. Make that method do whatever munging you need it to do.
>
> -philip
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Nik
2008-Aug-01 13:24 UTC
Re: Creating a custom function that can be called from an instance variable.
I tried it and I got it to work, Philip! Thank You so much for your time. It''s probably not my place to say that this stuff is probably elementary. This is why: Thank you so much for your time!! Cheers! On Aug 1, 3:22 pm, Nik <NiKS...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> So: > #t in hh:mm:ss format > def HourDisp(t) > #t gets split in three parts hh,mm, and ss > new_t = t.split('':'') > h=new_t[0] + new_t[1]/60 + new_t[2]/3600 > return h > end > > <<view>> > <%= HourDisp(12:30:00) %> > #12.5 > > Thank You So Much Philip! > > On Jul 29, 9:24 pm, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote: > > > On Jul 29, 2008, at 12:06 PM,Nikwrote: > > > > Hello all, > > > > I have a whole bunch of time stamps which I need to display in > > > fractional hours or fractional days as the case may be. > > > > Is there any chance I could do something like this: > > > <<controller>> > > > def HourDisp > > > ... > > > end > > > @time = 12:30:00 > > > -------------------------------------- > > > <<view>> > > > <%= @time.HourDisp %> > > > --------------------------------------- > > > Shows: > > > 12.5 > > >Nik- > > > Create a helper method named say "time_as_fraction" and pass your time > > into it. Make that method do whatever munging you need it to do. > > > -philip--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---