[Gambas-user] Where is the mistake?

Tobias Boege taboege at gmail.com
Mon Apr 8 18:20:04 CEST 2019

```On Mon, 08 Apr 2019, Hans Lehmann wrote:
> Hello!
>
> Where is the mistake?
>
> Print "Time-Part:  "; Round(Frac(Now()), -8); " ▸ "; Format\$(Time(Frac(Now())), "hh:nn:ss"); Format\$(Time(Frac(Now())), "(t)")
> Print "Time-Part:  "; Round(Frac(Now()), -8); " ▸ "; Format\$(Time(Now()),       "hh:nn:ss"); Format\$(Time(Now()),       "(t)")
>

BTW, this could be written in a single Format\$() call:

Print "Time-Part:  "; Round(Frac(Now()), -8); " ▸ "; Format\$(Time(Frac(Now())), "hh:nn:ss (t)")

> Output:
>
> Time-Part:  0,59328568 ▸ *14*:14:19 (CEST) ' UTC!
> Time-Part:  0,59328568 ▸ *16*:14:19 (CEST)
>

Dates in Gambas are not what you seem to think they are, or what people
usually write on paper and call a "date". In Gambas a Date is a floating
point value which points to a specific point in time (in UTC). There is
no timezone attached to it -- as opposed to people, who have a timezone
in mind when they talk about dates and times. Benoît likes to say that
"Dates are absolute in Gambas".

The timezone is only applied when rendering this floating point value as
a string, which is when the timezone makes a difference at all. Consequently,
when you use "t" to get the timezone in Format\$(), you are not reading off
a property from the Date. The timezone is a property of your system and
hence does not change depending on the Date you pass to Format\$(). If you
want to work with (Date, Timezone) pairs, have a look at how I did it in
gb.web.feed.

As for the following oddity:

\$ gbx3 -e 'CDate(1 + Frac(Now))'
01/01/-4801 18:14:44
\$ gbx3 -e 'CDate(Frac(Now))'
16:14:49

It seems that a time-only date (which is what you get from calling Frac()
on a date) are *not* subject to timezone calculations. As soon as the Date
has a date part (a positive integral part in the Float representation),
the system timezone is taken into account. If you think about it, it makes
sense (at least a little): if you have no date, how are you going to handle
the timezone calculation causing your time to overflow and the change the
(non-existent) date? [ Or it might be a bug... ]

Regards,
Tobi

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