# Time class instance

**URL:** <https://www.ruby-forum.com/t/time-class-instance/166415>\
**Category:** IronRuby\
**Created:** [April 24, 2009, 10:56pm UTC](https://www.ruby-forum.com/t/time-class-instance/166415 "2009-04-24T22:56:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jirapong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/90ced4/32.png) [@jirapong](https://www.ruby-forum.com/u/jirapong)\
**Post date:** [April 24, 2009, 10:56pm UTC](https://www.ruby-forum.com/t/time-class-instance/166415/1 "2009-04-24T22:56:29Z")

</div>

Hi  
Time class instance in IronRuby act as static. Given following code:

t = Time.new  
t.utc  
t.utc? # should be true behave

t.localtime  
t.utc? # should be false

“t” should convert itself into UTC type after method “utc” being  
called. There are three methods must modifying the receiver; utc,  
gmtime, and localtime

It also effect to Time.rfc2882 formating as you can run MRI vs  
IronRuby at - [http://gist.github.com/101229](http://gist.github.com/101229)

I have propose my fix at -  
[http://github.com/Jirapong/ironruby/commit/937a8c4aea048dd20ddea8aa6e27b0055bf6907d](http://github.com/Jirapong/ironruby/commit/937a8c4aea048dd20ddea8aa6e27b0055bf6907d)

File changes:  
â€¢ Merlin/External.LCA\_RESTRICTED/Languages/IronRuby/mspec/ironruby-  
tags/library/time/rfc2822\_tags.txt  
â€¢ Merlin/External.LCA\_RESTRICTED/Languages/IronRuby/mspec/rubyspec/  
core/time/utc\_spec.rb  
â€¢ Merlin/Main/Languages/Ruby/Libraries.LCA\_RESTRICTED/Builtins/  
FileOps.cs  
â€¢ Merlin/Main/Languages/Ruby/Libraries.LCA\_RESTRICTED/Builtins/  
TimeOps.cs  
â€¢ Merlin/Main/Languages/Ruby/Libraries.LCA\_RESTRICTED/  
Initializers.Generated.cs  
â€¢ Merlin/Main/Languages/Ruby/Libraries.LCA\_RESTRICTED/Zlib/zlib.cs  
â€¢ Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyDateTime.cs  
â€¢ Merlin/Main/Languages/Ruby/Ruby/Ruby.csproj

Note: Shri, this push should fix  
23) Failure:  
test\_request\_unmodifed(TestGemRemoteFetcher)  
[test\_gem\_remote\_fetcher.rb:604]:  
Expected “Mon, 13 Apr 2009 13:22:16 -0700”, not “Mon, 13 Apr 2009  
20:22:16 -0000”

Thank you,  
-Jirapong

---

<div class="post-metadata">

**Author:** ![jirapong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/90ced4/32.png) [@jirapong](https://www.ruby-forum.com/u/jirapong)\
**Post date:** [May 4, 2009, 3:44am UTC](https://www.ruby-forum.com/t/time-class-instance/166415/2 "2009-05-04T03:44:39Z")

</div>

Doesn’t look like anyone has reviewed this yet. To make sure it doesn’t  
get lost, can you also make a bug on codeplex for this?

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
removed\_email\_address@domain.invalid  
Sent: Friday, April 24, 2009 1:56 PM  
To: removed\_email\_address@domain.invalid  
Subject: [Ironruby-core] Time class instance

Hi  
Time class instance in IronRuby act as static. Given following  
code:

t = Time.new  
t.utc  
t.utc? # should be true behave

t.localtime  
t.utc? # should be false

“t” should convert itself into UTC type after method “utc” being called.  
There are three methods must modifying the receiver; utc, gmtime, and  
localtime

It also effect to Time.rfc2882 formating as you can run MRI vs IronRuby  
at - [101229’s gists · GitHub](http://gist.github.com/101229)

I have propose my fix at -  
[http://github.com/Jirapong/ironruby/commit/937a8c4aea048dd20ddea8aa6e27b0055bf6907d](http://github.com/Jirapong/ironruby/commit/937a8c4aea048dd20ddea8aa6e27b0055bf6907d)

File changes:  
\*  
Merlin/External.LCA\_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/library/time/rfc2822\_tags.txt  
\*  
Merlin/External.LCA\_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/time/utc\_spec.rb  
\*  
Merlin/Main/Languages/Ruby/Libraries.LCA\_RESTRICTED/Builtins/FileOps.cs  
\*  
Merlin/Main/Languages/Ruby/Libraries.LCA\_RESTRICTED/Builtins/TimeOps.cs  
\*  
Merlin/Main/Languages/Ruby/Libraries.LCA\_RESTRICTED/Initializers.Generated.cs  
\*  
Merlin/Main/Languages/Ruby/Libraries.LCA\_RESTRICTED/Zlib/zlib.cs  
\* Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyDateTime.cs  
\* Merlin/Main/Languages/Ruby/Ruby/Ruby.csproj

Note: Shri, this push should fix  
23) Failure:

test\_request\_unmodifed(TestGemRemoteFetcher)  
[test\_gem\_remote\_fetcher.rb:604]:

Expected “Mon, 13 Apr 2009 13:22:16 -0700”, not “Mon, 13 Apr 2009  
20:22:16 -0000”

Thank you,  
-Jirapong

---

<div class="post-metadata">

**Author:** ![jirapong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/90ced4/32.png) [@jirapong](https://www.ruby-forum.com/u/jirapong)\
**Post date:** [May 4, 2009, 4:12am UTC](https://www.ruby-forum.com/t/time-class-instance/166415/3 "2009-05-04T04:12:58Z")

</div>

Hi,  
It would be nice to have anyone to review my code :-). bug file in  
at [http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=1021](http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=1021)

Thanks,  
-Jirapong

---

<div class="post-metadata">

**Author:** ![jirapong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/90ced4/32.png) [@jirapong](https://www.ruby-forum.com/u/jirapong)\
**Post date:** [May 4, 2009, 9:17am UTC](https://www.ruby-forum.com/t/time-class-instance/166415/4 "2009-05-04T09:17:23Z")

</div>

The approach looks good. I have some comments though…

You should do a search for “DateTime” in the code base to find all the  
places that might need updating. For example, Yaml.DateTimeOps needs to  
be changed (is there no spec for it?), and Converter.IsIntegral might  
need to be.

RubyDateTime should be a good .NET citizen. You should override Equals  
(and HashCode) - I suspect comparison might be broken without that since  
DateTime was a valuetype whereas RubyDateTime is not. Also ToString. You  
should define implicit operator converting from and to DateTime so that  
Ruby code can pass a Ruby Time object to a CLR method that expects  
DateTime. Would be nice to add constructors to RubyDateTime to match the  
contructors of DateTime so that you can directly create instances of  
RubyDateTime using “new RubyDateTime(args)” instead of using nested  
expressions like “new RubyDateTime(new DateTime(args))” which is harder  
to read. You should mark it as Serializable. Take a look at DateTime on  
[msdn.com](http://msdn.com) and see if there are any other interfaces or attributes you can  
propagate from DateTime to RubyDateTime.

The comment for RubyDateTime confused me a bit. Instead of “RubyDateTime  
to encapsulates DateTime type which support instance’s variable”, should  
it not be “Encapsulates DateTime and supports mutating of instances  
(whereas DateTime is immutable)”

Creating bugs for code reviews is extra process for you. We can try to  
avoid it until there are too many code reviews. So do send a reminder if  
no one replies to your changes within 48 hours.

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
removed\_email\_address@domain.invalid  
Sent: Sunday, May 03, 2009 7:12 PM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Ironruby-core] Time class instance

Hi,  
It would be nice to have anyone to review my code :-). bug  
file in at  
[http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=1021](http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=1021)

Thanks,  
-Jirapong

On May 4, 2009, at 8:43 AM, Jimmy S. wrote:

Doesn’t look like anyone has reviewed this yet. To make sure it doesn’t  
get lost, can you also make a bug on codeplex for this?

From:  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Friday, April 24, 2009 1:56 PM  
To: removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: [Ironruby-core] Time class instance

Hi  
Time class instance in IronRuby act as static. Given following  
code:

t = Time.new  
t.utc  
t.utc? # should be true behave

t.localtime  
t.utc? # should be false

“t” should convert itself into UTC type after method “utc” being called.  
There are three methods must modifying the receiver; utc, gmtime, and  
localtime

It also effect to Time.rfc2882 formating as you can run MRI vs IronRuby  
at - [101229’s gists · GitHub](http://gist.github.com/101229)

I have propose my fix at -  
[http://github.com/Jirapong/ironruby/commit/937a8c4aea048dd20ddea8aa6e27b0055bf6907d](http://github.com/Jirapong/ironruby/commit/937a8c4aea048dd20ddea8aa6e27b0055bf6907d)

File changes:  
\*  
Merlin/External.LCA\_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/library/time/rfc2822\_tags.txt  
\*  
Merlin/External.LCA\_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/time/utc\_spec.rb  
\*  
Merlin/Main/Languages/Ruby/Libraries.LCA\_RESTRICTED/Builtins/FileOps.cs  
\*  
Merlin/Main/Languages/Ruby/Libraries.LCA\_RESTRICTED/Builtins/TimeOps.cs  
\*  
Merlin/Main/Languages/Ruby/Libraries.LCA\_RESTRICTED/Initializers.Generated.cs  
\*  
Merlin/Main/Languages/Ruby/Libraries.LCA\_RESTRICTED/Zlib/zlib.cs  
\* Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyDateTime.cs  
\* Merlin/Main/Languages/Ruby/Ruby/Ruby.csproj

Note: Shri, this push should fix  
23) Failure:

test\_request\_unmodifed(TestGemRemoteFetcher)  
[test\_gem\_remote\_fetcher.rb:604]:

Expected “Mon, 13 Apr 2009 13:22:16 -0700”, not “Mon, 13 Apr 2009  
20:22:16 -0000”

Thank you,  
-Jirapong

---

<div class="post-metadata">

**Author:** ![jirapong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/90ced4/32.png) [@jirapong](https://www.ruby-forum.com/u/jirapong)\
**Post date:** [May 4, 2009, 7:28pm UTC](https://www.ruby-forum.com/t/time-class-instance/166415/5 "2009-05-04T19:28:06Z")

</div>

Hello Shri,  
Thank you very much for code review. It is make sense about  
constructors and ToString methods. I will work on it.

p.s. please delete bug #1021 for me.

Thank you,  
-Jirapong

---

<div class="post-metadata">

**Author:** ![jirapong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/90ced4/32.png) [@jirapong](https://www.ruby-forum.com/u/jirapong)\
**Post date:** [May 4, 2009, 9:26am UTC](https://www.ruby-forum.com/t/time-class-instance/166415/6 "2009-05-04T09:26:09Z")

</div>

Why did you need to disable two examples in rfc2822\_spec.rb? We should  
not be disabling tests that worked before without a very good reason.

You added a test for Time.utc. That should actually be in the second  
describe block in the same file for Time#utc. The (grammatically  
correct) name of the examples should be “modifies the receiver”

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Shri B.  
Sent: Monday, May 04, 2009 12:15 AM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Ironruby-core] Time class instance

The approach looks good. I have some comments though…

You should do a search for “DateTime” in the code base to find all the  
places that might need updating. For example, Yaml.DateTimeOps needs to  
be changed (is there no spec for it?), and Converter.IsIntegral might  
need to be.

RubyDateTime should be a good .NET citizen. You should override Equals  
(and HashCode) - I suspect comparison might be broken without that since  
DateTime was a valuetype whereas RubyDateTime is not. Also ToString. You  
should define implicit operator converting from and to DateTime so that  
Ruby code can pass a Ruby Time object to a CLR method that expects  
DateTime. Would be nice to add constructors to RubyDateTime to match the  
contructors of DateTime so that you can directly create instances of  
RubyDateTime using “new RubyDateTime(args)” instead of using nested  
expressions like “new RubyDateTime(new DateTime(args))” which is harder  
to read. You should mark it as Serializable. Take a look at DateTime on  
[msdn.com](http://msdn.com) and see if there are any other interfaces or attributes you can  
propagate from DateTime to RubyDateTime.

The comment for RubyDateTime confused me a bit. Instead of “RubyDateTime  
to encapsulates DateTime type which support instance’s variable”, should  
it not be “Encapsulates DateTime and supports mutating of instances  
(whereas DateTime is immutable)”

Creating bugs for code reviews is extra process for you. We can try to  
avoid it until there are too many code reviews. So do send a reminder if  
no one replies to your changes within 48 hours.

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
removed\_email\_address@domain.invalid  
Sent: Sunday, May 03, 2009 7:12 PM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Ironruby-core] Time class instance

Hi,  
It would be nice to have anyone to review my code :-). bug  
file in at  
[http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=1021](http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=1021)

Thanks,  
-Jirapong

On May 4, 2009, at 8:43 AM, Jimmy S. wrote:

Doesn’t look like anyone has reviewed this yet. To make sure it doesn’t  
get lost, can you also make a bug on codeplex for this?

From:  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Friday, April 24, 2009 1:56 PM  
To: removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: [Ironruby-core] Time class instance

Hi  
Time class instance in IronRuby act as static. Given following  
code:

t = Time.new  
t.utc  
t.utc? # should be true behave

t.localtime  
t.utc? # should be false

“t” should convert itself into UTC type after method “utc” being called.  
There are three methods must modifying the receiver; utc, gmtime, and  
localtime

It also effect to Time.rfc2882 formating as you can run MRI vs IronRuby  
at - [101229’s gists · GitHub](http://gist.github.com/101229)

I have propose my fix at -  
[http://github.com/Jirapong/ironruby/commit/937a8c4aea048dd20ddea8aa6e27b0055bf6907d](http://github.com/Jirapong/ironruby/commit/937a8c4aea048dd20ddea8aa6e27b0055bf6907d)

File changes:  
\*  
Merlin/External.LCA\_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/library/time/rfc2822\_tags.txt  
\*  
Merlin/External.LCA\_RESTRICTED/Languages/IronRuby/mspec/rubyspec/core/time/utc\_spec.rb  
\*  
Merlin/Main/Languages/Ruby/Libraries.LCA\_RESTRICTED/Builtins/FileOps.cs  
\*  
Merlin/Main/Languages/Ruby/Libraries.LCA\_RESTRICTED/Builtins/TimeOps.cs  
\*  
Merlin/Main/Languages/Ruby/Libraries.LCA\_RESTRICTED/Initializers.Generated.cs  
\*  
Merlin/Main/Languages/Ruby/Libraries.LCA\_RESTRICTED/Zlib/zlib.cs  
\* Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyDateTime.cs  
\* Merlin/Main/Languages/Ruby/Ruby/Ruby.csproj

Note: Shri, this push should fix  
23) Failure:

test\_request\_unmodifed(TestGemRemoteFetcher)  
[test\_gem\_remote\_fetcher.rb:604]:

Expected “Mon, 13 Apr 2009 13:22:16 -0700”, not “Mon, 13 Apr 2009  
20:22:16 -0000”

Thank you,  
-Jirapong

---

<div class="post-metadata">

**Author:** ![jirapong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/90ced4/32.png) [@jirapong](https://www.ruby-forum.com/u/jirapong)\
**Post date:** [May 4, 2009, 9:03pm UTC](https://www.ruby-forum.com/t/time-class-instance/166415/7 "2009-05-04T21:03:48Z")

</div>

Hello Shri,  
Because the spec passed by accident, I was checked result by this  
code snippet

require ‘time’

t1 = (Time.utc(1976, 8, 26, 14, 30) + 4 \* 3600)  
t2 = Time.rfc2822(“26 Aug 76 14:30 EDT”)

puts “#{t1} == #{t2}? #{t1==t2}”

MRI:  
Thu Aug 26 18:30:00 UTC 1976 == Fri Aug 27 01:30:00 +0700 1976 true

IrunRuby:  
Thu Aug 26 18:30:00 Z 1976 == Thu Aug 26 18:30:00 Z 1976? true

According to rfc2822 section - 3.3. Date and Time Specification  
([http://www.ietf.org/rfc/rfc2822.txt](http://www.ietf.org/rfc/rfc2822.txt)  
) Timezone of rfc2822 should display in (( “+” / “-” ) 4DIGIT format.

Thank you,  
-Jirapong

On May 4, 2009, at 2:25 PM, Shri B. wrote:

> Why did you need to disable two examples in rfc2822\_spec.rb? We  
> should not be disabling tests that worked before without a very good  
> reason.
> 
> You added a test for Time.utc. That should actually be in the second  
> describe block in the same file for Time#utc. The (grammatically  
> correct) name of the examples should be â€œmodifies the receiverâ€  
> [Thanks for correction :-)]
