[Gambas-user] bug in function cstr()?

Tobias Boege taboege at gmail.com
Sun Sep 13 16:42:07 CEST 2020

On Sun, 13 Sep 2020, Angel wrote:
> El 13/9/20 a las 13:21, Tobias Boege escribió:
> > It's not a bug. When you Print a value, it is internally converted to
> > a string using Str() semantics, so `Print x` and `Print Str(x)` should
> > always give you the same result.
> > 
> > The (documented!) difference between Str and CStr is that Str uses
> > localization information, like your timezone, and CStr doesn't.
> > Gambas stores dates internally in UTC, so when you
> > 
> >    Print CStr(Now)
> > 
> > you get the `Now` in UTC, which reads the same as two hours in the past
> > for you in Madrid. But when you `Print Str(Now)`, the Date is treated
> > as if it were relative to your current timezone instead of UTC, so you
> > get the same information printed that your wallclock shows you.
> > 
> > Also notice that the date format changes -- this is due to another part
> > of your localization. Str picks it up, CStr doesn't.
> >
> I don't think I can explain it well, I imagine the time is UTC, but 1 day
> remains.
> And that's what strikes me as a bug.
> Sorry for my English
> Print cstr(date)  09/12/2020 22:00:00

Well, a Date without a time component (such as the one returned by the
Date() function) is secretly a Date with the time component set to zero.

So when you call Date on your spanish computer, what you get is the
timestamp pointing at 2020-09-13 00:00:00 Madrid time, which is the
same timestamp as 2020-09-12 22:00:00 in UTC.

It is not a bug. It is by design and documented. It certainly can be
considered a trap because over the years many people expressed confusion
about this. But that is partly because we aren't confronted with time-
zone arithmetic usually. Most often when we say "today", we don't say
it to someone in another timezone and not with the intention of relaying
a universal point in time that is precise to the millisecond, but Gambas
still has to have a clear idea about this stuff somewhere right in its


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

More information about the User mailing list