Is it loaded by default Date Class?

Should the ‘Date’ class be loaded by default when starting SketchUp?
If I type in the console puts it works for me but not for other users.
Is it possible that some of the plugins I have, have loaded the class with require 'date' and that’s why it works for me but not for other users?
Could it depend on the version of SketchUp being used or if it is a Mac or Windows environment?

No, only files that depend upon it should load it.

Because it was not loaded on their machine.

Date, DateTime and Date::Error are not core Ruby classes. They are library classes that must be loaded.
Class: Date (Ruby 2.7.2) (

Yes, most likely this is the case.


Thanks @DanRathbun one of my plugins is not working in a few user’s machines and I believe that this is the reason why…

Anyone working with a ‘public’ plugin/extension should test it with all other extensions disabled. I know it’s a PITA, but doing so will show problems like this.

As of Ruby 3.0, the following comment was added to DateTime:

DateTime class is considered deprecated. Use Time class.

As of today, It is still part of Ruby 3.3, which will be released in December.

Re a string equivalent of, use '%Y-%m-%dT%H:%M:%S%z'

1 Like

interesting… I didn’t know that
so in the case:

puts (DateTime.parse("2023-10-20T19:00:00")-DateTime.parse("2023-10-19T19:00:00")).to_i

will be this the equivalence?

puts (Date.parse("2023-10-20T23:00:00")-Date.parse("2023-10-19T10:00:00")).to_i

or will be this one? (because I would have to transform it from seconds to days)

puts (Time.parse("2023-10-20T19:00:00")-Time.parse("2023-10-19T19:00:00")).to_i

You can easily test for equivalence of expressions in the Ruby Console.

I know. The results are different. One in seconds and the other in days. But…
Date.parse is deprecated too?


For the benefit of Dan, myself, and whomever else might reply, what you are trying to calculate?

It appears you’re trying to calculate elapsed time or a time interval. What does the interval represent? Is it stored outside of your code (in a model, component, etc)?

As you stated, Time is essentially a float second value. So, 24 * 60 * 60 is the number of seconds in a normal day? BTW, Time.parse doesn’t exist…

Also, for versions of Ruby before 3.2, will not accept a string.

So, if you’re storing the value as text outside of Ruby, you may need to require date.

Or, converting a string to a numeric/time value without using ‘date’ is difficult with Ruby versions currently used in SketchUp.

I am calculating the period of time between two dates.
The value comes from an xml file that I stored as an attribute within a dictionary inside the SketchUp model and is imported as text from xml file with format %Y-%m-%dT%H:%M:%S%z.
Anyway the place were appeared I have already replaced it. I have also put at the beginning require ‘date’ and everything works. Thanks for your help

Glad you got things worked out.

Given that your forum ‘profile’ mentioned BIM, I thought that likely.

SketchUp doesn’t make working with XML very easy. I guess that’s another discussion…

1 Like