xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
10.14k stars 782 forks source link

Add os.timestamp api #5472

Closed xq114 closed 3 months ago

xq114 commented 3 months ago

你在什么场景下需要该功能?

希望将构建时的Unix时间戳编码到程序中,为此需要获取当前系统时间,但xmake中只提供了文件修改时间os.mtime,没有直接获取时间的api;目前要编码时间只能分平台写script获取,非常麻烦(windows Get-Date -UFormat %s,unix date +%s

描述可能的解决方案

增加os.timestamp或者os.systime api获取系统时间

描述你认为的候选方案

No response

其他信息

No response

Issues-translate-bot commented 3 months ago

Bot detected the issue body's language is not English, translate it automatically.


In what scenario do you need this feature?

I hope to encode the Unix timestamp during construction into the program. To do this, I need to obtain the current system time. However, xmake only provides the file modification time os.mtime, and there is no API to directly obtain the time. Currently, the encoding time can only be written according to the platform. Script acquisition is very troublesome (windows Get-Date -UFormat %s, unix date +%s)

Describe possible solutions

Add os.timestamp or os.systime api to obtain system time

Describe your alternatives

No response

Other information

No response

waruqi commented 3 months ago

不是有 os.date 和 os.time 么

https://github.com/xmake-io/xmake/blob/c8e8e04d832288a0a7f4d5a90a89061f7951b0e0/xmake/actions/build/cleaner.lua#L68

Issues-translate-bot commented 3 months ago

Bot detected the issue body's language is not English, translate it automatically.


Isn’t there os.date and os.time?

https://github.com/xmake-io/xmake/blob/c8e8e04d832288a0a7f4d5a90a89061f7951b0e0/xmake/actions/build/cleaner.lua#L68

xq114 commented 3 months ago

文档里没搜到,看来是文档问题

Issues-translate-bot commented 3 months ago

Bot detected the issue body's language is not English, translate it automatically.


I couldn't find it in the documentation. It seems to be a documentation problem.

waruqi commented 3 months ago

这两是 lua 原生接口,文档暂时没写,可以来 pr 补下

Issues-translate-bot commented 3 months ago

Bot detected the issue body's language is not English, translate it automatically.


These two are Lua's native interfaces. The documentation has not been written yet. You can come to PR to make up for it.