Convert old Date to Xojo.Core.Date

  1. ‹ Older
  2. 4 years ago

    Eli O

    is not verified 16 Jun 2016 Europe (Berlin, Germany)

    Classic dates are GMT dates I assume. So you would need to apply the offset:

    Dim d As New Xojo.Core.Date(aClassicFrameworkDate.TotalSeconds - 2082844800 - Xojo.Core.TimeZone.Current.SecondsFromGMT, Xojo.Core.TimeZone.Current)

    And some time zones have daylight saving time – I don't know how these influence TimeZone and SecondsFromGMT.

  3. Michel B

    17 Jun 2016 Pre-Release Testers, Xojo Pro

    Actually Classic date is using the current Locale.

      dim d as new date
      system.debuglog d.SQLDateTime
      Dim dada as new Xojo.core.date(d.year, d.month, d.day, d.hour, d.Minute, d.Second, 0, Xojo.Core.TimeZone.Current)
      system.debuglog dada.totext
  4. Bob K

    17 Jun 2016 Pre-Release Testers, Xojo Pro Kansas City

    I had a bug report from (other peoples) code that used the above snippet and found that the above snippet consistently brought back the wrong date. No big deal to move it to using the global Date object. This is a warning for others that might use it verbatim as the person who wrote this code did.

  5. Michel B

    17 Jun 2016 Pre-Release Testers, Xojo Pro

    @Bob K I had a bug report from (other peoples) code that used the above snippet and found that the above snippet consistently brought back the wrong date. No big deal to move it to using the global Date object. This is a warning for others that might use it verbatim as the person who wrote this code did.

    Which snippet ? The totalsecond one, or the constructor with year, month, day, hour, etc ?

    Whichever one it seems pretty easy to verify after constructing the Xojo.Core.Date if it is in sync with Classic. Could it rather not be an issue with the conversion between totalsecond and secondsFrom1970 ?

  6. Bob K

    17 Jun 2016 Pre-Release Testers, Xojo Pro Kansas City

    The first snippet. And yes, it's a conversion issue between total second's and secondsFrom1970.

    The OPC project I was working on I could tell that the programmer took the code, verbatim, from this post and used it without checking its authenticity. The dangers of using code you find online.

  7. Brock N

    17 Jun 2016 Pre-Release Testers, Xojo Pro

    What's the best way to go in reverse? I need to go from a Xojo.Core.Date to the classic Date.

  8. Michel B

    17 Jun 2016 Pre-Release Testers, Xojo Pro
    Edited 4 years ago

    I tend to use exactly the same way I posted : use the constructor with explicit values. But the root property is probably OK too.

  9. Norman P

    17 Jun 2016 Xojo Inc, Pre-Release Testers, Xojo Pro Seeking work. npalardy@great-w...

    the classic date constructor with appropriate params passed seems simple enough

  10. Peter F

    21 Jun 2016 Pre-Release Testers, Xojo Pro New England

    @Bob K The OPC project I was working on I could tell that the programmer took the code, verbatim, from this post and used it without checking its authenticity. The dangers of using code you find online.

    Guilty :)

    Tested, but, obviously not extensively enough.

  11. Bob K

    21 Jun 2016 Pre-Release Testers, Xojo Pro Kansas City

    @Peter F Guilty :)

    Tested, but, obviously not extensively enough.

    No worries. Easy to miss because it does bring back a date that looks good at first blush. Unfortunately, a client was the one that spotted it. :(

  12. 2 years ago

    Djamel A

    25 Jul 2018 Oran (Algeria)

    Hello,
    Using TimeControl and DateControl (EinHugur Plugin), i try to get time and Date valueChanged
    These values changes only inside valueChanged Event (Date and Time ctrl), i would like to get the values changed every where in the project.

  13. Björn E

    25 Jul 2018 Pre-Release Testers, Xojo Pro Iceland

    I am not sure what you are asking you get notify in the event when the value changes and you there notify the rest of your application and variables of the change.

    If you for any reason want to read the value at random time then you just read the controls DateValue property.

    Basically same as any other control works

  14. Ulrich B

    25 Jul 2018 Pre-Release Testers, Xojo Pro Europe (Germany, Berlin) · xo...

    @Djamel A;AMRANE These values changes only inside valueChanged Event (Date and Time ctrl), i would like to get the values changed every where in the project.

    You should read about AddHandler. It allows you to reroute an event to another place.

  15. Djamel A

    25 Jul 2018 Oran (Algeria)

    @Björn Eiacute;ksson I am not sure what you are asking you get notify in the event when the value changes and you there notify the rest of your application and variables of the change.

    If you for any reason want to read the value at random time then you just read the controls DateValue property.

    Basically same as any other control works

    Unfortunately i can not show any example code TimeCtrl and DateCtrl (plugin) are not exported with the project.
    I give an example :
    I wrote Method to draw analogical clock, i want to move the needles shows.
    when i modify "hour or minutes" the needles shows must move imidiately ... , it means that the time inside my draw method changes when increasing or decreasing the hours or minutes in the Time Picker (TimeCtrl).

  16. Björn E

    26 Jul 2018 Pre-Release Testers, Xojo Pro Iceland

    It is just like any other Xojo control, your get Value changed event, you Set your stored variable or property, you call invalidate on your "needles" drawing control and it draws what you have stored in your property. => Happens immediately

  17. Djamel A

    26 Jul 2018 Oran (Algeria)

    @Björn Eiacute;ksson It is just like any other Xojo control, your get Value changed event, you Set your stored variable or property, you call invalidate on your "needles" drawing control and it draws what you have stored in your property. => Happens immediately

    Understood, it happens. The methods called for drawing are also Invalidate.
    Problem that the draw is not refreshed, overlapping , it means that the program keep the elapsed time in memory ...
    The drawing is moving properly no overlapping when time is introduced by TextField "hour", Textfield "minutes", etc ...

  18. Björn E

    26 Jul 2018 Pre-Release Testers, Xojo Pro Iceland

    Ah I think I know what you mean

    There is delay in the date and time control entry......since else you could not enter some values. It needs to delay while you are entering to give you time to enter valid number before applying validations. So you have maybe half a second delay.

    Before that delay was put there the user experience was sometimes horrible. Like if min date was 1.1.2001, and you start to enter 2001, then you type 2, and get validation and the year 2 would be to low. Input delay handles such so you can enter 2001 before validation happens. (Pretty standard practice for controls like this one)

  19. Djamel A

    27 Jul 2018 Oran (Algeria)

    @Björn Eiacute;ksson Ah I think I know what you mean

    There is delay in the date and time control entry......since else you could not enter some values. It needs to delay while you are entering to give you time to enter valid number before applying validations. So you have maybe half a second delay.

    Before that delay was put there the user experience was sometimes horrible. Like if min date was 1.1.2001, and you start to enter 2001, then you type 2, and get validation and the year 2 would be to low. Input delay handles such so you can enter 2001 before validation happens. (Pretty standard practice for controls like this one)

    Unfortunately i have not found solution, The Date Time Picker((EinHugur Plugin) become uncontrollable, focus on the hour or minute does not respond, only the second change (increase or decrease) slowly ...
    Entering the time value by textfield run properly but ... !

  20. 6 weeks ago

    Josh H

    Jan 10 Pre-Release Testers, Xojo Pro

    Public Function SecondsSince1904KSW(Extends d As DateTime) as Double
    Return d.SecondsFrom1970+kSecondsBetween1904And1970+timeZone.Current.SecondsFromGMT
    End Function

    Public Function NewDateTimeFromLegacyDateTotalSeconds(d As Double) as DateTime
    Return New DateTime(d-kSecondsBetween1904And1970-TimeZone.Current.SecondsFromGMT,TimeZone.Current)
    End Function

    Public Const kSecondsBetween1904And1970 as Number = 2082844800

    Sub Open() Handles Open
    Dim d As New Date
    Dim dNew As New DateTime(d)

    Dim dTS, dTS2 As Double
    dTS = d.TotalSeconds
    dTS2 = dNew.SecondsSince1904KSW

    Dim dTrial As DateTime = NewDateTimeFromLegacyDateTotalSeconds(dTS2)
    break
    End Sub

  21. Djamel A

    Jan 11 Oran (Algeria)

    Hi Josh,
    i am still using 2015r1, DateTime() works only since 2019r2.
    thank you

or Sign Up to reply!