Getting system.time() to work

In order to learn Flux I installed the latest build of the Flux REPL app (0.104.0). According to the Flux docs, now() should return UTC and system.time() should be the local time. I am running Ubuntu 20.10 and should have the time setup properly but both now() and system.time() report UTC time.

Here is peek of the Ubuntu time details and the Flux output, anyone with an idea of what I am doing wrong?

sillygoose@u-desktop:~/projects/flux$ timedatectl
               Local time: Wed 2021-02-03 16:21:32 EST  
           Universal time: Wed 2021-02-03 21:21:32 UTC  
                 RTC time: Wed 2021-02-03 21:21:33      
                Time zone: America/New_York (EST, -0500)
System clock synchronized: yes                          
              NTP service: active                       
          RTC in local TZ: no                           
sillygoose@u-desktop:~/projects/flux$ ./flux repl
> import "system"
> system.time()
2021-02-03T21:21:59.589535036Z
> now()
2021-02-03T21:22:03.637864430Z
> 
sillygoose@u-desktop:~/projects/flux$ ```

Moved on to InfluxDB2 and I see the same thing as in version 1.8.4 (both are running as Docker containers on the same hardware).

root@7591593af691:~# date
Mon Feb 15 16:18:51 EST 2021
root@7591593af691:~# flux repl
> import "system"
> now()
2021-02-15T21:19:32.248271524Z
> system.time()
2021-02-15T21:19:39.592824858Z

If anyone can enlighten me I would very much appreciate it, even if only to tell me that now() and system.time() are different on their machine.

@sillygoose, I’ll have to test, but the docs may be incorrect when they say system.time() typically accounts for the local time zone. They may only return UTC.

The key difference between system.time() and now() is that now() should return the time the Flux script is executed (or in the cast of Flux tasks, when the task was supposed to be executed). Using now() multiple times in a script/query should return the same time value. system.time() returns the time the function itself is executed. So if using system.time() multiple times in a script/query, each execution of the system.time() function returns a different time value.

It appears a bug was introduced that makes now() and system.time() behave the same. I’ve created an issue on the Flux repo: 'now()' doesn't return the same time throughout a script execution · Issue #3496 · influxdata/flux · GitHub

Thanks for confirming what I observed but I see there are actually two potential problems based on the problem report you reference:

  1. now() does not have identical times in a script as documented (not cached)
  2. system.time() does not return the machine local time

What is not clear in the problem report is that the documentation is right and system.time() should be a local time. I’ll add a comment there to see if this behavior can be clarified (I ran info this when trying to calculate my local time difference from UTC and the result was zero).

From the 2.0 docs (bold is mine):

now() returns the current UTC time. now() is cached at runtime, so all instances of now() in a Flux script return the same value.

system.time() returns the current system time of the host machine, which typically accounts for the local time zone. This time represents the time at which system.time() it is executed, so each instance of system.time() in a Flux script returns a unique value.