[Gambas-user] Possible CDATE issue Latest version

Tobias Boege tobs at taboege.de
Sat Nov 19 19:47:51 CET 2022


On Sat, 19 Nov 2022, Brian G wrote:
> ----- On Nov 19, 2022, at 9:43 AM, Benoit Minisini benoit.minisini at gambas-basic.org wrote:
> 
> > Le 19/11/2022 à 17:26, Brian G a écrit :
> >> 
> >> ----- On Nov 19, 2022, at 2:43 AM, Benoit Minisini
> >> benoit.minisini at gambas-basic.org wrote:
> >> 
> >>> Le 18/11/2022 à 20:36, Brian G a écrit :
> >>>> With the latest version of gambas, I am getting the strangest issue, I
> >>>> dont understand, not sure if its a bug
> >>>> cdate returns different values if called with a class public variable.
> >>>> Locks like possibly like in the last case
> >>>> its return the gmt time.
> >>>>
> >>>> Hello world                     11/18/2022 11:30:56
> >>>> CDATE(now)                      11/18/2022 11:30:56
> >>>> Eval("cdate(now)")              11/18/2022 11:30:56
> >>>> dim thedate as string = "CDate(now)"
> >>>> Try ddate = Eval(thedate)       11/18/2022 19:30:56.895
> >>>>
> >>>
> >>> The printed strings are normal. What did you expect?
> >>>
> >>> --
> >>> Benoît Minisini.
> >>>
> >>>
> >>> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
> >> 
> >> I expect the times to all be the same, the last time printed is a different time
> >> zone
> >> although the same expression is being evaluated.
> >> 
> > 
> > It can't be the same as in your script, 'ddate' is a string that
> > receives the result of evaluating an expression that returns a date.
> > 
> > Hence this date is converted to a string automatically with CDate() to
> > be put inside the 'ddate' variable, and so you get the UTC
> > representation of the date as returned by CDate().
> > 
> > Regards,
> > 
> > --
> > Benoît Minisini.
> > 
> > 
> > ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
> Maybe I am just a bit thick but I had expected
> 
> print   cdate(now)
> 
> and 
> 
> dim a as string = cdate(now)
> print a
> 
> To produce the same output value! 
> 
> This is what is produced
> 
> 11/19/2022 10:19:18
> 11/19/2022 18:19:18.16
> 

No! The Print instruction converts dates to strings for humans, i.e.,
using the current locale, including timezone. By contrast, assigning
to a string variable uses the low-level conversion function CStr()
which does not use the current locale.

You should expect

  Dim a As String = CDate(Now)
  Print a

and

  Print CStr(Now)

to produce the same output, as well as

  Dim a As String = Str$(Now)
  Print a

and

  Print Now

And indeed, they do. The Print documentation tells you that.

Best,
Tobias

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk


More information about the User mailing list