Skip to content

cannot set datetime object

Forums Forums SIMPOL Programming cannot set datetime object

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #48
    Jim Locker
    Member

    This code does not work: datetime runtime date dt integer year,month, day, hour, minute, second time autotime, curtime autotime =@ app.fg.sg.AutoTime dt =@ date.new() dt.setnow() curtime =@ time.new() curtime.setnow() if autotime <= curtime dt = dt + 1 end if runtime =@ datetime.new() year = dt.year() month = dt.month() day = dt.dayinmonth() hour = autotime.hours() minute = autotime.minutes() second = autotime.seconds() runtime.set(year=year,month=month,dayinmonth=day,hours=hour,minutes=minute,seconds=second) The runtime object is initialized by the runtime.new() method, but I cannot set it. Nothing changes; the value of the object remains unspecified and when I look at it using the object viewer, the assigned value is zero. the autotime object is presently set to midnight so hour minute and second all are set to zero, but not setting hour minute second doesn't change the outcome; I just can't set the runtime object. The code is intended to be used to invoke a function at a particular wall clock time, using a !wait for the necessary time based upon the time the program started running. If there is a better way to do this in simpol, I haven't found it. Why can't I set this object?

    #1684
    Michael
    Keymaster

    On 14/04/2010 22:42, jim wrote:
    > This code does not work:
    >
    >
    > datetime runtime
    > date dt
    > integer year,month, day, hour, minute, second
    > time autotime, curtime
    > autotime =@ app.fg.sg.AutoTime
    > dt =@ date.new()
    > dt.setnow()
    > curtime =@ time.new()
    > curtime.setnow()
    > if autotime <= curtime
    > dt = dt + 1
    > end if
    > runtime =@ datetime.new()
    > year = dt.year()
    > month = dt.month()
    > day = dt.dayinmonth()
    > hour = autotime.hours()
    > minute = autotime.minutes()
    > second = autotime.seconds()
    >
    > runtime.set(year=year,month=month,dayinmonth=day,hours=hour,minutes=minute,seconds=second)
    >
    > The runtime object is initialized by the runtime.new() method, but I
    > cannot set it. Nothing changes; the value of the object remains
    > unspecified and when I look at it using the object viewer, the
    > assigned value is zero.
    >
    > the autotime object is presently set to midnight so hour minute and
    > second all are set to zero, but not setting hour minute second
    > doesn't change the outcome; I just can't set the runtime object.
    >
    > The code is intended to be used to invoke a function at a particular
    > wall clock time, using a !wait for the necessary time based upon the
    > time the program started running. If there is a better way to do
    > this in simpol, I haven't found it.
    >
    > Why can't I set this object?

    I have logged a bug on this one. There is an easy workaround. The
    problem appears to be that the set() method on the datetime object is
    failing to set the datetime if the object has the value .nul. The
    workaround is quite simple. Just initialize the datetime with 0, like this:

    runtime =@ datetime.new(0)

    After that, everything works as it should. This problem is specific to
    the datetime object, the date and time objects do not display this behavior.

    Ciao, Neil

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.