[MacRuby-devel] MacRuby 0.9 - NSDate initWithTimeInterval:sinceDate: problem
Jonathan Waddilove
jonathan at waddilove.net
Sun Feb 13 08:42:16 PST 2011
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
More information about the MacRuby-devel
mailing list