Date Constructor?

  1. 5 months ago

    Christian S

    Apr 5 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

    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?

  2. Michael E

    Apr 5 Europe (Deutschland, Heggen)

    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".

  3. Christian S

    Apr 5 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

    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.

  4. Alfred V

    Apr 5 Pre-Release Testers

    @ChristianSchmitz 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?

  5. Christian S

    Apr 5 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

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

  6. Alberto D

    Apr 6 Pre-Release Testers
    Edited 5 months ago

    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)
  7. Christian S

    Apr 6 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

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

  8. Alberto D

    Apr 6 Pre-Release Testers

    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.

  9. Alfred V

    Apr 6 Pre-Release Testers

    @Alberto D;Poo So my guess, even if I use the creator without the GMTOffset, the date is created with the system GMTOffset.

    Yup.

    @ChristianSchmitz But I'd like to set dates sometimes without an explicit time zone.

    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.

  10. Christian S

    Apr 6 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

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

  11. Alfred V

    Apr 6 Pre-Release Testers

    @ChristianSchmitz 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.

  12. Alberto D

    Apr 6 Pre-Release Testers

    When I do this in Xojo:

    Dim d As New date(2018)

    I get this:

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

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

    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.

or Sign Up to reply!