Skip to content

ubus: expose unix timestamp in ubus system call#17

Open
fjamarquez wants to merge 1 commit intoopenwrt:masterfrom
fjamarquez:add_unixtime
Open

ubus: expose unix timestamp in ubus system call#17
fjamarquez wants to merge 1 commit intoopenwrt:masterfrom
fjamarquez:add_unixtime

Conversation

@fjamarquez
Copy link

Expose the unix timestamp in the ubus system call. In case the local time is different from UTC, the ubus call gets the local time and the unix timestamp.

root@c82c2b100000:~# ubus call system info
{
	"localtime": 1741345176,
	"unixtime": 1741341576,
	"uptime": 528,
	"load": [
		64,
		21984,
		20096
	],
	"memory": {
		"total": 124801024,
		"free": 46555136,
		"shared": 159744,
		"buffered": 53248,
		"available": 39346176,
		"cached": 33030144
	},
	"root": {
		"total": 1280,
		"free": 200,
		"used": 1080,
		"avail": 200
	},
	"tmp": {
		"total": 60936,
		"free": 60780,
		"used": 156,
		"avail": 60780
	},
	"swap": {
		"total": 0,
		"free": 0
	}
}

@Rondom
Copy link
Contributor

Rondom commented Mar 27, 2025

Out of interest: What is the use case behind this?

@fjamarquez
Copy link
Author

The main use case is to always get a unix timestamp from the AP, even if the AP is configured in another time zone. In that case, you will get the timestamp relative to the timezone configured and relative to unix time without the need of any manual conversion. For example, if the AP must always send the timestamp to any application in unix, it is easier if the AP gets the time directly in unixtime, than needing to know the local time zone configured in the AP in order to obtain unix timestamp. In case you have many APs configured with different time zones, you need to know the time zone of each one to get the unix of all of them. In addition, the configured timezone is not obtained from this ubus output. I think that it can be useful, but if you think it is out of interest, it is good.

@Neustradamus
Copy link

@fjamarquez: What is the status of your PR?

@fjamarquez
Copy link
Author

@fjamarquez: What is the status of your PR?

Is still open, pending of review after my last comment

@AndyChiang888
Copy link

@fjamarquez
Copy link
Author

luci provides unixtime: https://github.com/openwrt/luci/blob/6f454d00eca4bc206550efd9eab96c50a2fae2b0/modules/luci-base/root/usr/share/rpcd/ucode/luci#L97

Yes, but what if you need to obtain the Unix time of the system without luci interaction? Anyway, if you think this is out of interest, the pr can be closed

@AndyChiang888
Copy link

Just use ubus call luci getUnixtime, unless your router doesn't installed luci.

@AndyChiang888
Copy link

However, I prefer unixtime provided by the system rather than luci.

@dangowrt
Copy link
Member

dangowrt commented Feb 9, 2026

Please include a full description of the change (like you did in the PR description) also in the commit message, adhering to
https://openwrt.org/submitting-patches#submission_guidelines

In case the local time is different from UTC, the ubus
call gets the local and the unix timestamp.

root@c82c2b100000:~# ubus call system info
{
	"localtime": 1741345176,
	"unixtime": 1741341576,
	"uptime": 528,
	"load": [
.
.
.
}

Signed-off-by: Francisco Jose Alvarez <fjamarquez@gmail.com>
@fjamarquez
Copy link
Author

@dangowrt Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants