[Gambas-user] bug in function cstr()?
rwe-sse at osnanet.de
Mon Sep 14 11:23:53 CEST 2020
Am 13.09.20 um 16:42 schrieb Tobias Boege:
> 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
>> 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
As far as I remember, especially this "time zero" thing wasn't there in
older Gambas. When it was new, it did confuse me a lot and I had to
rewrite a lot of code. Strange enough, in my calendar program, when I
let it run on my laptop at home (old Suse Linux on it), it steps back a
day. Don't know why, but in the office (Ubuntu 18) it runs well. Maybe
it's because the Gambas version on it is older, too?
And for communication with folks in other time zones, on other planets
and in different spacetime continuums we still have star time... But I
wouldn't dare trying to recalculate into that :)
More information about the User