4

Date syntax in OS API

Hello, i would like to know how input begin and end date to get the number day of a time period ? I got the month and day as integer values (day -1, month -1) but have problem when convert them to date format in OS for date calculation

ngkhanh's avatar
2.2k
ngkhanh
asked 2016-02-07 12:52:17 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

3

Take a look at the Time section on this page of the SDK documentation. For dates and time, OpenStudio has the following:

Now let's say that you want to create a date. The "tricky" part is that for the month it requires an OpenStudio::MonthOfYear:

day = 1
month = 1
year = 2010
date = OpenStudio::Date.new(OpenStudio::MonthOfYear.new(month), day, year)
Julien Marrec's avatar
29.7k
Julien Marrec
answered 2016-02-08 01:36:23 -0500
edit flag offensive 0 remove flag delete link

Comments

@Julien Marrec Thank a lot. After those definition, may i use date1 - date 2 to get the day number between 2 date ? Have any special syntax should be consider ?

ngkhanh's avatar ngkhanh (2016-02-08 05:11:37 -0500) edit

Yes. it seems to return an OpenStudio::Time (t = date1-date2), on which can call for example t.totalDays to get a float (decimal number) of the number of days.

To know this kind of stuff I usually just open a command prompt or terminal, launch ruby and require openstudio, and then I can explore and try things like this.

Julien Marrec's avatar Julien Marrec (2016-02-08 06:03:52 -0500) edit

May i do it in ruby console of sketchup ? ruby IDE installation with Openstudio is too complicated.

ngkhanh's avatar ngkhanh (2016-02-08 10:58:28 -0500) edit

You should be able too yes. But there's nothing complicated to install ruby to work with openstudio though. See the beginning of this page, section Optional - Install ruby

Julien Marrec's avatar Julien Marrec (2016-02-08 14:23:51 -0500) edit

i did it but i did not see the advantages of ruby installation when compare with notepad++ and Apply Measure Now. The main advantage is test console but i don't know much about this. Most of time the measure test is collapsed - Please give some suggest if you got a good installtiopn ruby.

ngkhanh's avatar ngkhanh (2016-02-08 14:47:17 -0500) edit
add a comment see more comments