[MacRuby-devel] MacRuby 0.9 - NSDate initWithTimeInterval:sinceDate: problem

Jonathan Waddilove jonathan at waddilove.net
Mon Feb 14 01:08:13 PST 2011


Thank you Alan,

I was obviously having a really bad day for mistyping and word blindness...

best wishes, Jonathan


regards,  Jonathan

Jonathan T Waddilove
email: jonathan at waddilove.net 
web: jonathan.waddilove.net

On 13 Feb 2011, at 19:52, Alan Skipp wrote:

> I think you've just managed to get your variable names mixed up. You've used 'cocoaFinishTime' where you should have used 'cocoaTime'
> 
> last line should be:
> puts "Cocoa Later time: #{cocoaFinishTime}, interval: #{cocoaFinishTime.timeIntervalSinceDate(cocoaTime)} seconds"
> 
> al
> 
> 
> On 13 Feb 2011, at 16:42, Jonathan Waddilove wrote:
> 
>> Hi, I have been trying to use the NSDate initWithTimeInterval:sinceDate: method to measure elapsed times.
>> 
>> I know there has been some discussion about the mapping from Cocoa NSDate to Ruby Time and back but I'm not sure if this is supposed to be working now?
>> 
>> Here's a snip of code that calculates the interval using Ruby Time and then NSDate
>> 
>> #!/usr/local/bin/macruby
>> puts "Ruby Version: #{RUBY_VERSION}, MacRuby Version: #{MACRUBY_VERSION}"
>> 
>> puts "\n\nRuby vesion - works as expected"
>> point_in_time = Time.now
>> puts "Ruby start time #{point_in_time}"
>> sleep(1)
>> later_time = Time.now
>> puts "Later time: #{later_time}, interval: #{later_time - point_in_time} seconds"
>> 
>> puts "\n\nFailing Cocoa version"
>> cocoaTime = NSDate.date
>> puts "Coca start time: #{cocoaTime}"
>> sleep(1)
>> cocoaFinishTime = NSDate.date
>> puts "Cocoa Later time: #{cocoaFinishTime}, interval: #{cocoaFinishTime.timeIntervalSinceDate( cocoaFinishTime)} seconds"
>> 
>> 
>> And here's the output, note the NSDate sees zero intervale...
>> Ruby Version: 1.9.2, MacRuby Version: 0.8
>> 
>> 
>> Ruby vesion - works as expected
>> Ruby start time 2011-02-13 16:33:23 +0000
>> Later time: 2011-02-13 16:33:24 +0000, interval: 1.000694 seconds
>> 
>> 
>> Failing Cocoa version
>> Coca start time: 2011-02-13 16:33:24 +0000
>> Cocoa Later time: 2011-02-13 16:33:25 +0000, interval: 0.0 seconds
>> 
>> User error? or do I need to file a ticket?
>> 
>> Best wishes and thanks, Jonathan
>> 
>> _______________________________________________
>> MacRuby-devel mailing list
>> MacRuby-devel at lists.macosforge.org
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
> 
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel



More information about the MacRuby-devel mailing list