What's new

Chaotic UTC and local time in merlin

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Jiang

Occasional Visitor
Router: RT-AC88U
Firmware: 386.5_2

I found this little issue when checking spdMerlin's log.
Code:
AutoBW report - Fri Jun 10 10:12:48 2022

Calculated Download speed (31562 Kbps) does not exceed 10% threshold of existing value (31659 Kbps)

Calculated Upload speed (17379 Kbps) does not exceed 10% threshold of existing value (17695 Kbps)

No changes made to QoS by AutoBW
The UTC time is printed instead of the local time. So, I went to the system log and found the following snippet
Code:
Jun 10 10:27:00 transmission-daemon[5909]: Fantastic.Beasts.The.Secrets.of.Dumbledore.2022.2160p.MA.WEB-DL.DDP5.1.Atmos.HDR.HEVC-CMRG.mkv Tracker error: "Tracker gave HTTP response code 502 (Bad Gateway)" (torrent.c:623)
Jun 10 19:45:10 syslog: wlceventd_proc_event(527): eth2: Auth 48:01:C5:66:15:B3, status: Successful (0), rssi:0
Jun 10 19:45:10 syslog: wlceventd_proc_event(556): eth2: Assoc 48:01:C5:66:15:B3, status: Successful (0), rssi:0
Jun 10 19:45:11 dnsmasq-dhcp[429]: DHCPREQUEST(br0) 192.168.50.125 48:01:c5:66:15:b3
Jun 10 19:45:11 dnsmasq-dhcp[429]: DHCPACK(br0) 192.168.50.125 48:01:c5:66:15:b3 OnePlus7T
Jun 10 11:11:05 transmission-daemon[5909]: Unable to create session lock file (22): Invalid argument (session-id.c:96)
Jun 10 20:12:02 spdMerlin: Starting speedtest using auto-selected server for WAN interface
Jun 10 11:12:30 spdMerlin: Speedtest results - Download: 32.20 Mbps (data used: 40.1 MB) - Upload: 17.71 Mbps (data used: 20.9 MB)
Jun 10 11:12:30 spdMerlin: Connection quality - Latency: 5.63 ms (0.23 ms jitter) - Packet Loss: 0.0%
Jun 10 11:12:31 spdMerlin: Retrieving data for WebUI charts
Jun 10 11:12:44 spdMerlin: Calculated Download speed (31392 Kbps) does not exceed 10% threshold of existing value (31659 Kbps)
Jun 10 11:12:44 spdMerlin: Calculated Upload speed (17383 Kbps) does not exceed 10% threshold of existing value (17695 Kbps)
Using either UTC or local time could be a choice for developers of any software, e.g. `transmission` uses UTC all the time.
But it is not reasonable to use both UTC and local time for one software. For instance, `spdMerlin` prints its log with both local and UTC time. Till now, I used to think that there might be something wrong with the implementation of `spdMerlin`. Then I searched the source code of `spdMerlin`, trying to found how it prints time:
Code:
    TZ=$(cat /etc/TZ)
    export TZ
    
    printf "AutoBW report - %s\\n\\n" "$(date +"%c")" > "$autobwoutfile"
The developer uses
Code:
TZ=<timezone> date
to print local time. Reference: how to get local date/time in linux terminal while server configured in UTC/different timezone?

So, why does `spdMerlin` still prints UTC time?
Further, I tested this issue in the console.
Code:
$ date
Fri Jun 10 11:47:37 UTC 2022

$ date -u
Fri Jun 10 11:47:52 UTC 2022

$ TZ=$(cat /etc/TZ)
$ echo $TZ
JST
$ date
Fri Jun 10 11:48:11 UTC 2022
Interesting, the `date` command can only print UTC time. Is there any difference between the Merlin's and other unix-like systems' `date` command?
Code:
$ date --help
BusyBox v1.25.1 (2022-03-25 10:23:25 EDT) multi-call binary.

Usage: date [OPTIONS] [+FMT] [TIME]

Display time (using +FMT), or set time

        [-s,--set] TIME Set time to TIME
        -u,--utc        Work in UTC (don't convert to local time)
        -R,--rfc-2822   Output RFC-2822 compliant date string
        -I[SPEC]        Output ISO-8601 compliant date string
                        SPEC='date' (default) for date only,
                        'hours', 'minutes', or 'seconds' for date and
                        time to the indicated precision
        -r,--reference FILE     Display last modification time of FILE
        -d,--date TIME  Display TIME, not 'now'
        -D FMT          Use FMT for -d TIME conversion

Recognized TIME formats:
        hh:mm[:ss]
        [YYYY.]MM.DD-hh:mm[:ss]
        YYYY-MM-DD hh:mm[:ss]
        [[[[[YY]YY]MM]DD]hh]mm[.ss]
        'date TIME' form accepts MMDDhhmm[[YY]YY][.ss] instead
The answer is `NO` refer to the help info of Merlin's `date`. It says the `-u,--utc` option is used for UTC time. Local time should be printed when using default `date` command.

This simple test shows that the function of Merlin's `date` command is improper. Should this be improved/fixed?
 
Works for me on my RT-AX86U.
Code:
# cat /etc/TZ
GMT0DST,M3.5.0/1,M10.5.0/2
# /bin/date
Fri Jun 10 13:08:28 DST 2022

# TZ="JST"
# /bin/date
Fri Jun 10 12:08:37 JST 2022
 
@Jiang Your command line test problem might be caused by TZ not being exported. Try this:
Code:
# export TZ
# date
Fri Jun 10 15:13:30 JST 2022
 
Looking more closely at this the JST timezone seems to be broken.

Even though it says "JST" in my 'date' output it is actually showing the UTC time. If you change the timezone to Seoul (UTC-9_1) or Yakutsk (UTC-9_3) it should be correct.
Rich (BB code):
# TZ="UTC" date
Fri Jun 10 23:47:23 UTC 2022

# TZ="JST" date
Fri Jun 10 23:47:37 JST 2022

# TZ="UTC-9_1" date
Sat Jun 11 08:47:57 UTC 2022

# TZ="UTC-9_3" date
Sat Jun 11 08:48:01 UTC 2022
 
Looking more closely at this the JST timezone seems to be broken.

Even though it says "JST" in my 'date' output it is actually showing the UTC time. If you change the timezone to Seoul (UTC-9_1) or Yakutsk (UTC-9_3) it should be correct.
Rich (BB code):
# TZ="UTC" date
Fri Jun 10 23:47:23 UTC 2022

# TZ="JST" date
Fri Jun 10 23:47:37 JST 2022

# TZ="UTC-9_1" date
Sat Jun 11 08:47:57 UTC 2022

# TZ="UTC-9_3" date
Sat Jun 11 08:48:01 UTC 2022
It turns out that none of the listed commands works for me.
 
How about a timezone near the beginning of its internal list:
Code:
# TZ="UTC10" date
Fri Jun 10 14:01:47 UTC 2022
That works! And "UTC-9" gives the JST time.
Code:
# TZ="UTC10" date
Fri Jun 10 14:07:42 UTC 2022
# TZ="UTC9" date
Fri Jun 10 15:07:51 UTC 2022
# TZ="UTC-9" date
Sat Jun 11 09:08:28 UTC 2022
 
It's good that you've found a solution but it's very strange. I wonder what the reason for the problem is.
I found that everything is fine when I set time zone to other than `GMT+09:00` in the web interface.
For example, when set it to `Singapore` which is `GMT+08:00`
Code:
# date
Sat Jun 11 08:27:13 GMT 2022
to `Sydney` which is `GMT+10:00`
Code:
# date
Sat Jun 11 10:28:33 UTC 2022
 
Curiously it looks like there a special piece of code that's already meant to set the nvram variable to "UTC-9" for JST, but this isn't reflected in the /etc/TZ file. It's hard to know whether that's intentional or not. But it does imply that Asus knows there's something odd about JST.

https://github.com/RMerl/asuswrt-me...40600411/release/src/router/rc/common.c#L1391
Rich (BB code):
    /* special mapping */
    if (nvram_match("time_zone", "JST"))
        nvram_set("time_zone_x", "UCT-9");
#if 0
    else if (nvram_match("time_zone", "TST-10TDT"))
        nvram_set("time_zone_x", "UCT-10");
    else if (nvram_match("time_zone", "CST-9:30CDT"))
        nvram_set("time_zone_x", "UCT-9:30");
#endif

    if ((fp = fopen("/etc/TZ", "w")) != NULL) {
        fprintf(fp, "%s\n", tmpstr);
        fclose(fp);
    }
 
Curiously it looks like there a special piece of code that's already meant to set the nvram variable to "UTC-9" for JST, but this isn't reflected in the /etc/TZ file. It's hard to know whether that's intentional or not. But it does imply that Asus knows there's something odd about JST.

https://github.com/RMerl/asuswrt-me...40600411/release/src/router/rc/common.c#L1391
Rich (BB code):
    /* special mapping */
    if (nvram_match("time_zone", "JST"))
        nvram_set("time_zone_x", "UCT-9");
#if 0
    else if (nvram_match("time_zone", "TST-10TDT"))
        nvram_set("time_zone_x", "UCT-10");
    else if (nvram_match("time_zone", "CST-9:30CDT"))
        nvram_set("time_zone_x", "UCT-9:30");
#endif

    if ((fp = fopen("/etc/TZ", "w")) != NULL) {
        fprintf(fp, "%s\n", tmpstr);
        fclose(fp);
    }
I think you have already found the key. Please see the following code with my annotation.
Code:
    snprintf(tmpstr, sizeof(tmpstr), "%s", nvram_safe_get("time_zone")); // line 1371
    // Suppose that the value of tmpstr is now `JST`
    nvram_set("time_zone_x", tmpstr); #set value of variable `time_zone_x` to `tmpstr`
    // Now, "time_zone_x" is 'JST'
    /* special mapping */
    if (nvram_match("time_zone", "JST"))
        nvram_set("time_zone_x", "UCT-9"); // Replace 'JST' to 'UCT-9'. First problem found in this line, should it be 'UTC' instead of 'UCT'? Might be a typo.
        // Now, "time_zone_x" is 'UCT-9'
/*
other codes
*/
    if ((fp = fopen("/etc/TZ", "w")) != NULL) {
        fprintf(fp, "%s\n", tmpstr); // Write tmpstr, which is now 'JST', to /etc/TZ.
        fclose(fp);
    }

This explains why my `cat /etc/TZ` gives 'JST' but not work for `date` command.
 
Last edited:
Yeah, I spotted the tmpstr issue but missed the typo for UTC. Like I said, I don't understand their thinking for this. Maybe they simply forgot to assign UTC-9 to tmpstr.

EDIT: It looks like technically UCT is a valid synonym for UTC.
 
Last edited:

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top