mirror of
https://github.com/wez/wezterm.git
synced 2024-11-23 15:04:36 +03:00
Add wezterm.strftime_utc
This commit is contained in:
parent
a70ddd9212
commit
478b0df58b
@ -160,6 +160,7 @@ pub fn make_lua_context(config_file: &Path) -> anyhow::Result<Lua> {
|
||||
wezterm_mod.set("emit", lua.create_async_function(emit_event)?)?;
|
||||
wezterm_mod.set("sleep_ms", lua.create_async_function(sleep_ms)?)?;
|
||||
wezterm_mod.set("strftime", lua.create_function(strftime)?)?;
|
||||
wezterm_mod.set("strftime_utc", lua.create_function(strftime_utc)?)?;
|
||||
wezterm_mod.set("gradient_colors", lua.create_function(gradient_colors)?)?;
|
||||
|
||||
package.set("path", path_array.join(";"))?;
|
||||
@ -172,6 +173,12 @@ pub fn make_lua_context(config_file: &Path) -> anyhow::Result<Lua> {
|
||||
Ok(lua)
|
||||
}
|
||||
|
||||
fn strftime_utc<'lua>(_: &'lua Lua, format: String) -> mlua::Result<String> {
|
||||
use chrono::prelude::*;
|
||||
let local: DateTime<Utc> = Utc::now();
|
||||
Ok(local.format(&format).to_string())
|
||||
}
|
||||
|
||||
fn strftime<'lua>(_: &'lua Lua, format: String) -> mlua::Result<String> {
|
||||
use chrono::prelude::*;
|
||||
let local: DateTime<Local> = Local::now();
|
||||
|
@ -37,6 +37,7 @@ As features stabilize some brief notes about them will accumulate here.
|
||||
* [RotatePanes](config/lua/keyassignment/RotatePanes.md) key assignment for re-arranging the panes in a tab
|
||||
* [SplitPane](config/lua/keyassignment/SplitPane.md) key assignment that allows specifying the size and location of the split, as well as top-level (full width/height) splits. `wezterm cli split-pane --help` shows equivalent options you can use from the cli. [#578](https://github.com/wez/wezterm/issues/578)
|
||||
* [ime_preedit_rendering](config/lua/config/ime_preedit_rendering.md) option to choose whether to use the builtin or the system IME preedit rendering mode. Thanks to [@kumattau](https://github.com/kumattau)! [#2006](https://github.com/wez/wezterm/pull/2006)
|
||||
* [wezterm.strftime_utc](config/lua/wezterm/strftime_utc.md) for manipulating times in UTC rather than the local timezone
|
||||
|
||||
|
||||
#### Updated
|
||||
|
@ -12,3 +12,4 @@ local date_and_time = wezterm.strftime("%Y-%m-%d %H:%M:%S");
|
||||
wezterm.log_info(date_and_time);
|
||||
```
|
||||
|
||||
See also [strftime_utc](strftime_utc.md).
|
||||
|
15
docs/config/lua/wezterm/strftime_utc.md
Normal file
15
docs/config/lua/wezterm/strftime_utc.md
Normal file
@ -0,0 +1,15 @@
|
||||
# `wezterm.strftime_utc(format)`
|
||||
|
||||
*Since: nightly builds only*
|
||||
|
||||
Formats the current UTC date/time into a string using [the Rust chrono
|
||||
strftime syntax](https://docs.rs/chrono/0.4.19/chrono/format/strftime/index.html).
|
||||
|
||||
```lua
|
||||
local wezterm = require 'wezterm';
|
||||
|
||||
local date_and_time = wezterm.strftime_utc("%Y-%m-%d %H:%M:%S");
|
||||
wezterm.log_info(date_and_time);
|
||||
```
|
||||
|
||||
See also [strftime](strftime.md).
|
Loading…
Reference in New Issue
Block a user