Android Question AnotherDatePicker - dates before 1970

Discussion in 'Android Questions' started by LucaMs, Apr 18, 2018.

  1. LucaMs

    LucaMs Expert Licensed User

    It seems to me that AnotherDatePicker allows you to select a date before 1970 but in this case the DateChanged event does not fire.

    Am I wrong?
     
    Erel likes this.
  2. LucaMs

    LucaMs Expert Licensed User

    No, it is really so.

    Now I don't know if I have to try to modify the original code (AnotherDatePicker) or not.
     
  3. LucaMs

    LucaMs Expert Licensed User

    Code:
    Private Sub DateField_TextChanged (Old As String, New As String)
        
    Dim ticks As Long = GetCurrentDateFromTextField (New)
        
    If ticks > 0 Then
    but for a date: 02/21/1968 ticks are -58755600000, so the event does not fire.
     
  4. LucaMs

    LucaMs Expert Licensed User

    It seems enough to change that line:
    to
    Code:
    If ticks <> 0 Then
     
  5. Erel

    Erel Administrator Staff Member Licensed User

  6. LucaMs

    LucaMs Expert Licensed User

    I have not watched the update yet but...

    I think it is not enough, because:

    Code:
    Private Sub GetCurrentDateFromTextField (DateString As StringAs Long
        
    Try
            
    Dim ticks As Long = DateTime.DateParse(DateString)
            
    If DateTime.GetYear(ticks) >= minYear And DateTime.GetYear(ticks) <= maxYear Then
                
    Return ticks
            
    End If
        
    Catch
            
    'invalid date
        End Try 'ignore
        Return 0
    End Sub
    And zero is a valid number of ticks for a date (1/1/1970).

    Maybe GetCurrentDateFromTextField should return an Object and so you can return a different value (Null) for an invalid date.
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    You should check it.
     
    LucaMs likes this.
  8. LucaMs

    LucaMs Expert Licensed User

    Doing...
     
  9. LucaMs

    LucaMs Expert Licensed User

    Private const INVALID_DATE As Long = -9999999999999999

    ;)
     
  10. LucaMs

    LucaMs Expert Licensed User

    It also does not work well. I tried:

    Log(DateTime.Date(INVALID_DATE))

    and the log is a valid date!

    2981 B.C.

    :p
     
    Erel likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice