DateTime Error

Post your Gambas programming questions here.
User avatar
gambix
Posts: 5
Joined: Sunday 25th September 2016 5:51pm
Location: France
Contact:

Re: DateTime Error

Post by gambix » Wednesday 13th March 2019 1:17pm

Again it work fine for me :-/

So the problem can coming from your system too.
:-P

User avatar
Cedron
Posts: 125
Joined: Thursday 21st February 2019 5:02pm
Location: The Mitten State
Contact:

Re: DateTime Error

Post by Cedron » Wednesday 13th March 2019 2:42pm

cogier wrote:
Wednesday 13th March 2019 11:45am
@Cedron .Move() does what you four lines did in one
I did not need either the following worked fine: -
Public Sub Form_Open()
Dim d As DateBox

d = New DateBox(Me)
d.Value = CDate("01/01/2019")
Print d.Value

End
Thanks, I should have remembered that. Honestly, it's not all that often that I move controls around the form.

Code:
        Dim d As DateBox
        Dim s As String

        d = New DateBox(Me)
        
        d.Move(100, 100, 100, 20)
        d.Show()

        d.Value = CDate("01/01/2019")
        s = CDate("01/01/2019")
        d.Value = CDate(s)
        
        Print s
        Print d.Value
        
        Print CFloat(CDate(s))
        Print CFloat(d.Value)
        Print CFloat(CDate(d.Value))
Output:

Code: Select all

01/01/2019
12/31/2018 00:00:00
2490589
2490588.16666667
2490588.16666667
Somebody is definitely having trouble getting a date.

(Side note: Could you guys put one of those handy "SELECT ALL" options in the "gb" tag output?

Ced

[System]
Gambas=3.12.2
OperatingSystem=Linux
Kernel=3.13.0-24-generic
Architecture=x86_64
Distribution=Linux Mint 17 Qiana
Desktop=MATE
Theme=Gtk
Language=en_US.UTF-8
.... and carry a big stick!

User avatar
cogier
Site Admin
Posts: 646
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: DateTime Error

Post by cogier » Wednesday 13th March 2019 3:50pm

It works OK for me.

Image

You can change line 10 to: -
d.Value = "01/01/2019"
Same result.

User avatar
Cedron
Posts: 125
Joined: Thursday 21st February 2019 5:02pm
Location: The Mitten State
Contact:

Re: DateTime Error

Post by Cedron » Wednesday 13th March 2019 3:52pm

Somewhat tracing what happens in the code (shown below)
        Dim t As String
        Dim v As Date
        Dim f As Float
        Dim w As Date
        
        v = CDate("01/01/2019")
        t = Format(v, "mm/dd/yyyy")
        f = Val(t)
        w = f  ' Implied CDate
        
        Print v
        Print CFloat(v)
        Print CStr(v)
        Print Str(v)
        Print t
        Print f
        Print CDate(f)
        Print w

Produces:

Code: Select all

12/31/2018 20:00:00
2490589
01/01/2019
12/31/2018 20:00:00
12/31/2018
2490588.16666667
12/31/2018 00:00:00
12/31/2018 00:00:00
So I am a bit puzzled. I've always understood internal date representation to be Integer Date + Fraction Of Day Time.

Looks like Str and Val might be problematic.

Ced

From: gambas-master/comp/src/gb.form/.src/Date/DateBox.class
Private Function Value_Read() As Date

  Dim vVal As Variant
  
  If Not $bShowDate Then
    vVal = Time(Val(Format(Date(1, 1, 1), "dd/mm/yyyy") & " " & $hButtonBox.Text))
  Else
    vVal = Val($hButtonBox.Text)
  Endif
  
  If vVal And If TypeOf(vVal) = gb.Date Then Return vVal
  
End

Private Sub Value_Write(Value As Date)

  If IsNull(Value) Then 
    $hButtonBox.Text = GetNullDate()
  Else
    $hButtonBox.Text = Format(Value, GetDateFormat())
  Endif
End
Private Sub GetDateFormat() As String
  
  Dim sFormat As String
  
  If $bShowDate Then
    sFormat = Format(Date(3333, 11, 22), gb.ShortDate)
    sFormat = Replace(sFormat, "3333", "yyyy")
    sFormat = Replace(sFormat, "22", "dd")
    sFormat = Replace(sFormat, "11", "mm")
  Endif

  If $bShowTime Then 
    sFormat &= " " & Format(Time(11, 22, 33), gb.ShortTime)
    sFormat = Replace(sFormat, "11", "hh")
    sFormat = Replace(sFormat, "22", "nn")
    sFormat = Replace(sFormat, "33", "ss")
  Endif
  
  Return LTrim(sFormat)
  
End
.... and carry a big stick!

User avatar
Cedron
Posts: 125
Joined: Thursday 21st February 2019 5:02pm
Location: The Mitten State
Contact:

Re: DateTime Error

Post by Cedron » Wednesday 13th March 2019 6:23pm

It helps to RTFM. The Str$ vs CStr is a localization issue.

http://gambaswiki.org/wiki/lang/cstr

vs

http://gambaswiki.org/wiki/lang/str

Same with val vs CDate.

So, val and str use localization, CDate and CStr do not.

Hence the observed behavior.

I have not been able to reproduce the OP's original bug.

Ced
.... and carry a big stick!

User avatar
Quincunxian
Posts: 112
Joined: Sunday 25th June 2017 12:14am
Location: Western Australia

Re: DateTime Error

Post by Quincunxian » Wednesday 13th March 2019 10:36pm

Ok that makes sense now. :roll:
Thanks to all.

I've been keeping a list of things that are either bugs(?) that need to be confirmed or a bit of a wish list.
I'll post in a new thread with a more appropriate title a bit later on.
Cheers - Quin.
I code therefore I am

chescobar
Posts: 1
Joined: Monday 15th February 2021 4:39pm

Re: DateTime Error

Post by chescobar » Monday 15th February 2021 4:43pm

This work for me:
DateBox1.Value=CDate(CDate("01/01/2019")+1)

User avatar
BruceSteers
Posts: 390
Joined: Thursday 23rd July 2020 5:20pm

Re: DateTime Error

Post by BruceSteers » Tuesday 16th February 2021 1:31am

chescobar wrote:
Monday 15th February 2021 4:43pm
This work for me:
DateBox1.Value=CDate(CDate("01/01/2019")+1)
It might not have 2 years ago when the post was made ;)
Wishing well
Bruce

If at first you don't succeed , try it differently.

Post Reply