Skip to content

Commit

Permalink
Merge commit 'fd8ee5407836b056d6432924d1408529388d7828'
Browse files Browse the repository at this point in the history
  • Loading branch information
h1romas4 committed Jun 23, 2023
2 parents e43d607 + fd8ee54 commit df4f969
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zellij-datetime"
version = "0.12.0"
version = "0.13.0"
authors = ["h1romas4 <[email protected]>"]
edition = "2021"

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ Since it is a WebAssembly/WASI build, it will probably work in all environments,

## WIP

- [x] Support for changing timezone by click or scroll on a pane
- [x] Support for changing timezone by click or scroll on a pane.
- [x] Support for timezone definition files.
- [x] Binary size reduction
- [x] Binary size reduction.
- [ ] Improved parsing of configuration files.
- [ ] Support for background color specification.
- [ ] When a Zellij session is detached and reattached, the plugin stops without getting drawing and timer events.
- [ ] Unnecessary borderlines appear when this plugin is placed at the bottom of the workspace with borderless=true.
Expand Down
16 changes: 10 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static INTERVAL_TIME: f64 = 1.0;

#[derive(Default)]
struct State {
now: Option<DateTime<FixedOffset>>,
now: Option<DateTime<Utc>>,
timezone: String,
timezone_offset: i32,
before_minute: u32,
Expand Down Expand Up @@ -59,7 +59,7 @@ impl ZellijPlugin for State {
}
Event::Timer(_t) => {
// get current time with timezone
let now = now(self.timezone_offset);
let now = now();
// render at 1 minute intervals
let now_minute = now.minute();
if self.before_minute != now_minute {
Expand Down Expand Up @@ -99,7 +99,7 @@ impl ZellijPlugin for State {
}

fn render(&mut self, _rows: usize, cols: usize) {
if let Some(now) = self.now {
if let Some(now) = self.now() {
let date = format!(
"{year}-{month:02}-{day:02} {weekday}",
year = now.year(),
Expand All @@ -121,7 +121,6 @@ impl State {
fn change_timezone(&mut self, timezone: String) {
self.timezone = timezone;
self.timezone_offset = self.config.get_timezone_offset(&self.timezone);
self.now = Some(now(self.timezone_offset));
}

fn change_timezone_next(&mut self) {
Expand All @@ -131,10 +130,15 @@ impl State {
fn change_timezone_prev(&mut self) {
self.change_timezone(self.config.get_prev_timezone(&self.timezone));
}

fn now(&self) -> Option<DateTime<FixedOffset>> {
self.now
.map(|now| now.with_timezone(&FixedOffset::east(&self.timezone_offset * 3600)))
}
}

fn now(timezone_offset: i32) -> DateTime<FixedOffset> {
fn now() -> DateTime<Utc> {
// Timezone may not be obtained by WASI.
// let now = Local::now();
Utc::now().with_timezone(&FixedOffset::east(timezone_offset * 3600))
Utc::now()
}

0 comments on commit df4f969

Please sign in to comment.