# New time object with custom value

**URL:** <https://www.ruby-forum.com/t/new-time-object-with-custom-value/142706>\
**Category:** Rails\
**Created:** [July 10, 2008, 3:37pm UTC](https://www.ruby-forum.com/t/new-time-object-with-custom-value/142706 "2008-07-10T15:37:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sadeesh\_kumar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@sadeesh\_kumar](https://www.ruby-forum.com/u/sadeesh_kumar)\
**Post date:** [July 10, 2008, 3:37pm UTC](https://www.ruby-forum.com/t/new-time-object-with-custom-value/142706/1 "2008-07-10T15:37:22Z")

</div>

hi,  
I need to construct anew time object with hour-\>7,min-55,sec-33.  
Then how could i do it?. As i search for it, I found no constructor to  
make time object like this. Anybody?

Thanks,  
-Sadeesh kumar.

---

<div class="post-metadata">

**Author:** ![sadeesh\_kumar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@sadeesh\_kumar](https://www.ruby-forum.com/u/sadeesh_kumar)\
**Post date:** [July 10, 2008, 5:06pm UTC](https://www.ruby-forum.com/t/new-time-object-with-custom-value/142706/2 "2008-07-10T17:06:22Z")

</div>

Hi Sadeesh,

sadeesh kumar wrote:

> I need to construct anew time object  
> with hour-\>7,min-55,sec-33. Then how  
> could i do it?.

Take a look at the  
ActiveSupport::CoreExtensions::DateTime::Calculations#change method.  
There’s no Time.new(args) method, but I think that’ll get you what  
you’re  
looking for.

HTH,  
Bill

---

<div class="post-metadata">

**Author:** ![sadeesh\_kumar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@sadeesh\_kumar](https://www.ruby-forum.com/u/sadeesh_kumar)\
**Post date:** [July 10, 2008, 10:14pm UTC](https://www.ruby-forum.com/t/new-time-object-with-custom-value/142706/3 "2008-07-10T22:14:44Z")

</div>

On Thu, Jul 10, 2008 at 11:04 AM, Bill W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ActiveSupport::CoreExtensions::DateTime::Calculations#change method.  
> There’s no Time.new(args) method, but I think that’ll get you what you’re  
> looking for.

Also, I’m not sure what Sadeesh meant by a time object with hour-\>7,  
min-55,  
sec-33.

The ruby Time class is really a point in time, so it represents, say  
4:06  
pm on July 10, 2008, rather than 16 hours and 6 minutes.

Rails provides an ActiveSupport::Duration class which does represent  
time  
intervals, they are created using methods on integers so you can do:

7.hours + 66.minutes + 33.seconds

And you can add or subtract a duration to/from a time so;

Time.now + 7.hours + 66.minuts + 33.seconds

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![sadeesh\_kumar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@sadeesh\_kumar](https://www.ruby-forum.com/u/sadeesh_kumar)\
**Post date:** [July 11, 2008, 4:54am UTC](https://www.ruby-forum.com/t/new-time-object-with-custom-value/142706/4 "2008-07-11T04:54:34Z")

</div>

Hi Bill W.,  
Thanks for your reply. But i am still struggling to use the  
ActiveSupport::CoreExtensions::DateTime::Calculations#change. Can you  
give me an example?

---

<div class="post-metadata">

**Author:** ![sadeesh\_kumar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@sadeesh\_kumar](https://www.ruby-forum.com/u/sadeesh_kumar)\
**Post date:** [July 11, 2008, 5:09am UTC](https://www.ruby-forum.com/t/new-time-object-with-custom-value/142706/5 "2008-07-11T05:09:46Z")

</div>

Bill,  
require ‘activesupport’  
print ActiveSupport::CoreExtensions::Time::Calculations::change(13)  
print ActiveSupport::CoreExtensions::Time::Calculations.change(13)

Well my problem is, I don’t know how to use change method.

Thanks,  
-Sadeesh kumar.

---

<div class="post-metadata">

**Author:** ![sadeesh\_kumar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@sadeesh\_kumar](https://www.ruby-forum.com/u/sadeesh_kumar)\
**Post date:** [July 11, 2008, 5:29am UTC](https://www.ruby-forum.com/t/new-time-object-with-custom-value/142706/6 "2008-07-11T05:29:06Z")

</div>

Hi Sadeesh,  
sadeesh kumar wrote:

> Bill,  
> require ‘activesupport’  
> print ActiveSupport::CoreExtensions::Time::Calculations::change(13)  
> print ActiveSupport::CoreExtensions::Time::Calculations.change(13)
> 
> Well my problem is, I don’t know how to use change method.

Wow. Sorry about that. Check the documentation for the change method  
(bottom left frame) in ActiveSupport::CoreExtensions::Time::Calculations  
at  
[api.rubyonrails.org](http://api.rubyonrails.org). If it’s not obvious how to use it at that point,  
try  
it out in irb. When you have some concrete ‘tried this, got that, don’t  
understand why’ type results, come back.

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![sadeesh\_kumar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@sadeesh\_kumar](https://www.ruby-forum.com/u/sadeesh_kumar)\
**Post date:** [July 11, 2008, 5:01am UTC](https://www.ruby-forum.com/t/new-time-object-with-custom-value/142706/7 "2008-07-11T05:01:00Z")

</div>

Hi Sadeesh,

sadeesh kumar wrote:

> Thanks for your reply. But i am still struggling to use the  
> ActiveSupport::CoreExtensions::DateTime::Calculations#change. Can you  
> give me an example?

What have you tried? What were the results and how did they confuse  
you?

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![sadeesh\_kumar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@sadeesh\_kumar](https://www.ruby-forum.com/u/sadeesh_kumar)\
**Post date:** [July 11, 2008, 10:55am UTC](https://www.ruby-forum.com/t/new-time-object-with-custom-value/142706/8 "2008-07-11T10:55:05Z")

</div>

Hi Rick DeNatale, Thanks for your reply. Any example code would be  
appreciated.

Thanks,  
-Sadeesh.

> > Also, I’m not sure what Sadeesh meant by a time object with hour-\>7, min-55,  
> > sec-33.
