Date Constructor?

Has someone got the date constructor to load?

this one fails:

Constructor(Year as Integer, Month as Integer, Day as Integer, hour as Integer, minute as Integer, second as Integer)

this one works:
Constructor(Year as Integer, Month as Integer, Day as Integer, Hour as Integer, Minute as Integer, Second as Integer, GMTOffset as Double)

But I’d like to have both working. Any idea?

Do you mean dim ls_heute as new date(2012,11,13,10,11,12) ?

I’ve tried it with debugger and get the date and time value. I.e. the SQLDateTime contains “2012-11-13 10:11:12”.

I am sorry for my incomplete posting.
This is a question for C++ developers writing plugins.
My code looks like this:

typedef void (*Func)(REALobject o, RBInteger y, RBInteger m, RBInteger d, RBInteger h, RBInteger i, RBInteger s); Func f2 = (Func) REALLoadObjectMethod(o, "Constructor(Year as Integer, Month as Integer, Day as Integer, hour as Integer, minute as Integer, second as Integer)");

this fails.

And this works:

typedef void (*Func)(REALobject o, RBInteger y, RBInteger m, RBInteger d, RBInteger h, RBInteger i, RBInteger s, double g); Func f1 = (Func) REALLoadObjectMethod(o, "Constructor(Year as Integer, Month as Integer, Day as Integer, Hour as Integer, Minute as Integer, Second as Integer, GMTOffset as Double)");

But I’d like to set dates sometimes without an explicit time zone.

Not sure what you want, but the full signature that works is sufficient. Just use the value 0.0 for the GMTOffset?

Wouldn’t it?

No, 0.0 for GMT would put it on GMT time zone.

But without putting the GMTOffset how can you create a valid date?

In Xojo if you don’t put the GMTOffset the date is created with the system GMTOffset:

Dim d As New date(2019, 4, 6, 7, 49, 53) Dim d2 As Double d2 = d.GMTOffset
So my guess, even if I use the creator without the GMTOffset, the date is created with the system GMTOffset. If no GMTOffset is explicitly set then you need to use the system one to use is as the implicit GMTOffset, no?

Edit: maybe the Date.Constructor is really:

Date.Constructor(Year as Integer, Month as Integer = 1, Day as Integer = 1, hour as Integer = 0, minute as Integer = 0, second as Integer = 0, GMTOffset as double = systemoffset)

As said in plugin api we can’t load the constructor without GMT offset.

What I’m trying to say is that even Xojo use the GMT offset (system) even if I don’t supply one, so I don’t know why you trying to use a constructor without GMT offset when it is needed to create a valid date. At least that’s how I look at it.

Sorry I don’t understand your problem.

Yup.

You could use the simple constructor like

    REALobject result = REALnewInstance("Date");
    double origGMTOffset = 0;
    REALGetPropValueDouble(result, "gmtOffset", &origGMTOffset);
    
    REALSetPropValueDouble(result, "gmtOffset", 0.0);
    REALSetPropValueDouble(result, "totalSeconds",'whatever value you want to use');
    REALSetPropValueDouble(result, "gmtOffset", origGMTOffset); 
}

gmtOffset is always part of the date.

My question remains why REALLoadObjectMethod does not load the constructor function pointer?

Try these signatures (your remark is academic in nature)

Constructor(Year as Integer, Month as Integer = 1, Day as Integer = 1, hour as Integer = 0, minute as Integer = 0, second as Integer = 0, GMTOffset as double)


Constructor(Year as Integer, Month as Integer = 1, Day as Integer = 1, hour as Integer = 0, minute as Integer = 0, second as Integer = 0)

Most likely, the second one won’t work either, so the first one might likely be defined by setting the default value of the GMTOffset:

Constructor(Year as Integer, Month as Integer = 1, Day as Integer = 1, hour as Integer = 0, minute as Integer = 0, second as Integer = 0, GMTOffset as double = 0.0)

Indicating that Xojo, under the hood, has the “Constructor”, the copy constructor and the long form of the constructor, not the one you want.

When I do this in Xojo:

Dim d As New date(2018)

I get this:

Date(2018, 1, 1, 0, 0, 0, -5.0)

Maybe because that constructor is not valid and is missing the GMTOffset?

Sorry, this is the last time I post here, I have only ideas and not experience and may end offending someone. It is just clear to me why without the GMTOffset doesn’t work and with it, it works.